Remove 'function' as this is not bourne shell. Escaping.

This commit is contained in:
Lars Gohr
2020-05-19 21:17:09 +02:00
parent 554d1b7c0e
commit 2d6b8f33b6

View File

@@ -1,7 +1,7 @@
#!/bin/sh
set -e
function main() {
main() {
echo "" # see https://github.com/actions/toolkit/issues/168
if usesBoolean "${ACTIONS_STEP_DEBUG}"; then
@@ -27,9 +27,9 @@ function main() {
changeWorkingDirectory
fi
echo ${INPUT_PASSWORD} | docker login -u ${INPUT_USERNAME} --password-stdin ${INPUT_REGISTRY}
echo "${INPUT_PASSWORD}" | docker login -u ${INPUT_USERNAME} --password-stdin ${INPUT_REGISTRY}
FIRST_TAG=$(echo $TAGS | cut -d ' ' -f1)
FIRST_TAG=$(echo "${TAGS}" | cut -d ' ' -f1)
DOCKERNAME="${INPUT_NAME}:${FIRST_TAG}"
BUILDPARAMS=""
CONTEXT="."
@@ -59,28 +59,28 @@ function main() {
docker logout
}
function sanitize() {
sanitize() {
if [ -z "${1}" ]; then
>&2 echo "Unable to find the ${2}. Did you set with.${2}?"
exit 1
fi
}
function isPartOfTheName() {
isPartOfTheName() {
[ $(echo "${INPUT_NAME}" | sed -e "s/${1}//g") != "${INPUT_NAME}" ]
}
function translateDockerTag() {
local BRANCH=$(echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g" | sed -e "s/\//-/g")
translateDockerTag() {
local BRANCH=$(echo "${GITHUB_REF}" | sed -e "s/refs\/heads\///g" | sed -e "s/\//-/g")
if hasCustomTag; then
TAGS=$(echo ${INPUT_NAME} | cut -d':' -f2)
INPUT_NAME=$(echo ${INPUT_NAME} | cut -d':' -f1)
TAGS=$(echo "${INPUT_NAME}" | cut -d':' -f2)
INPUT_NAME=$(echo "${INPUT_NAME}" | cut -d':' -f1)
elif isOnMaster; then
TAGS="latest"
elif isGitTag && usesBoolean "${INPUT_TAG_SEMVER}" && isSemver "${GITHUB_REF}"; then
TAGS=$(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g" | sed -E "s/v?([0-9]+)\.([0-9+])\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?/\1.\2.\3\4 \1.\2\4 \1\4/g")
TAGS=$(echo "${GITHUB_REF}" | sed -e "s/refs\/tags\///g" | sed -E "s/v?([0-9]+)\.([0-9+])\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?/\1.\2.\3\4 \1.\2\4 \1\4/g")
elif isGitTag && usesBoolean "${INPUT_TAG_NAMES}"; then
TAGS=$(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g")
TAGS=$(echo "${GITHUB_REF}" | sed -e "s/refs\/tags\///g")
elif isGitTag; then
TAGS="latest"
elif isPullRequest; then
@@ -90,73 +90,71 @@ function translateDockerTag() {
fi;
}
function hasCustomTag() {
hasCustomTag() {
[ $(echo "${INPUT_NAME}" | sed -e "s/://g") != "${INPUT_NAME}" ]
}
function isOnMaster() {
isOnMaster() {
[ "${BRANCH}" = "master" ]
}
function isGitTag() {
isGitTag() {
[ $(echo "${GITHUB_REF}" | sed -e "s/refs\/tags\///g") != "${GITHUB_REF}" ]
}
function isPullRequest() {
isPullRequest() {
[ $(echo "${GITHUB_REF}" | sed -e "s/refs\/pull\///g") != "${GITHUB_REF}" ]
}
function changeWorkingDirectory() {
changeWorkingDirectory() {
cd "${INPUT_WORKDIR}"
}
function useCustomDockerfile() {
useCustomDockerfile() {
BUILDPARAMS="${BUILDPARAMS} -f ${INPUT_DOCKERFILE}"
}
function addBuildArgs() {
addBuildArgs() {
for ARG in $(echo "${INPUT_BUILDARGS}" | tr ',' '\n'); do
BUILDPARAMS="${BUILDPARAMS} --build-arg ${ARG}"
echo "::add-mask::${ARG}"
done
}
function useBuildCache() {
if docker pull ${DOCKERNAME} 2>/dev/null; then
BUILDPARAMS="$BUILDPARAMS --cache-from ${DOCKERNAME}"
useBuildCache() {
if docker pull "${DOCKERNAME}" 2>/dev/null; then
BUILDPARAMS="${BUILDPARAMS} --cache-from ${DOCKERNAME}"
fi
}
function uses() {
uses() {
[ ! -z "${1}" ]
}
function usesBoolean() {
usesBoolean() {
[ ! -z "${1}" ] && [ "${1}" = "true" ]
}
function isSemver() {
isSemver() {
echo "${1}" | grep -Eq '^refs/tags/v?([0-9]+)\.([0-9+])\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?$'
}
function useSnapshot() {
useSnapshot() {
local TIMESTAMP=`date +%Y%m%d%H%M%S`
local SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-6)
local SNAPSHOT_TAG="${TIMESTAMP}${SHORT_SHA}"
TAGS="${TAGS} ${SNAPSHOT_TAG}"
echo ::set-output name=snapshot-tag::"${SNAPSHOT_TAG}"
echo "::set-output name=snapshot-tag::${SNAPSHOT_TAG}"
}
function push() {
push() {
local BUILD_TAGS=""
for TAG in ${TAGS}
do
for TAG in ${TAGS}; do
BUILD_TAGS="${BUILD_TAGS}-t ${INPUT_NAME}:${TAG} "
done
docker build ${INPUT_BUILDOPTIONS} ${BUILDPARAMS} ${BUILD_TAGS} ${CONTEXT}
for TAG in ${TAGS}
do
for TAG in ${TAGS}; do
docker push "${INPUT_NAME}:${TAG}"
done
}