Skip to content

Commit

Permalink
Support semver pre-releases (https://semver.org/#spec-item-11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Gohr committed Mar 24, 2020
1 parent 2da252b commit b2f6325
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function translateDockerTag() {
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]+)/\1.\2.\3 \1.\2 \1/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")
elif isGitTag; then
Expand Down Expand Up @@ -132,7 +132,7 @@ function usesBoolean() {
}

function isSemver() {
echo "${1}" | grep -Eq '^refs/tags/v?([0-9]+)\.([0-9+])\.([0-9]+)$'
echo "${1}" | grep -Eq '^refs/tags/v?([0-9]+)\.([0-9+])\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?$'
}

function useSnapshot() {
Expand Down
23 changes: 23 additions & 0 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ teardown() {
/usr/local/bin/docker logout"
}

@test "with tag semver it pushes tags using the pre-releases" {
# https://semver.org/#spec-item-11

SUFFIXES=('alpha.1' 'alpha' 'ALPHA' 'ALPHA.11' 'beta' 'rc.11')
for SUFFIX in "${SUFFIXES[@]}"
do
export GITHUB_REF="refs/tags/v1.1.1-${SUFFIX}"
export INPUT_TAG_SEMVER="true"

run /entrypoint.sh

expectStdOutContains "::set-output name=tag::1.1.1-${SUFFIX}"

expectMockCalled "/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 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
}

@test "with tag semver it pushes tags without 'v' prefix" {
export GITHUB_REF='refs/tags/1.2.34'
export INPUT_TAG_SEMVER="true"
Expand Down

0 comments on commit b2f6325

Please sign in to comment.