From 5e568ddac4916066726841dda8fd537ea841f827 Mon Sep 17 00:00:00 2001 From: Lars Gohr Date: Sun, 15 Nov 2020 20:16:27 +0100 Subject: [PATCH] Don't update major, minor and patch version on pre-release Fixes https://github.com/elgohr/Publish-Docker-Github-Action/issues/108 --- entrypoint.sh | 10 +++++++++- test.bats | 7 +++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 981b8451..cc0e7049 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -98,7 +98,11 @@ translateDockerTag() { elif isOnDefaultBranch; 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") + if isPreRelease "${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/g") + else + TAGS=$(echo "${GITHUB_REF}" | sed -e "s/refs\/tags\///g" | sed -E "s/v?([0-9]+)\.([0-9]+)\.([0-9]+)/\1.\2.\3\4 \1.\2\4 \1\4/g") + fi elif isGitTag && usesBoolean "${INPUT_TAG_NAMES}"; then TAGS=$(echo "${GITHUB_REF}" | sed -e "s/refs\/tags\///g") elif isGitTag; then @@ -163,6 +167,10 @@ isSemver() { echo "${1}" | grep -Eq '^refs/tags/v?([0-9]+)\.([0-9]+)\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?$' } +isPreRelease() { + echo "${1}" | grep -Eq '-' +} + useSnapshot() { local TIMESTAMP=`date +%Y%m%d%H%M%S` local SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-6) diff --git a/test.bats b/test.bats index 1ae79ec9..3856546a 100755 --- a/test.bats +++ b/test.bats @@ -147,7 +147,8 @@ teardown() { /usr/local/bin/docker logout" } -@test "with tag semver it pushes tags using the pre-releases" { +@test "with tag semver it pushes tags using the pre-release, but does not update the major, minor or patch version" { + # as pre-release versions tend to be unstable # https://semver.org/#spec-item-11 SUFFIXES=('alpha.1' 'alpha' 'ALPHA' 'ALPHA.11' 'beta' 'rc.11') @@ -161,10 +162,8 @@ teardown() { expectStdOutContains "::set-output name=tag::1.1.1-${SUFFIX}" expectMockCalledContains "/usr/local/bin/docker login -u USERNAME --password-stdin -/usr/local/bin/docker build -t my/repository:1.1.1-${SUFFIX} -t my/repository:1.1-${SUFFIX} -t my/repository:1-${SUFFIX} . +/usr/local/bin/docker build -t my/repository:1.1.1-${SUFFIX} . /usr/local/bin/docker push my/repository:1.1.1-${SUFFIX} -/usr/local/bin/docker push my/repository:1.1-${SUFFIX} -/usr/local/bin/docker push my/repository:1-${SUFFIX} /usr/local/bin/docker inspect --format={{index .RepoDigests 0}} my/repository:1.1.1-${SUFFIX} /usr/local/bin/docker logout" done