Skip to content

Commit

Permalink
Don't update major, minor and patch version on pre-release
Browse files Browse the repository at this point in the history
Fixes #108
  • Loading branch information
elgohr committed Nov 15, 2020
1 parent e6b13fe commit 5e568dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 9 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down

0 comments on commit 5e568dd

Please sign in to comment.