diff --git a/README.md b/README.md index 1c30814..5acac67 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,10 @@ jobs: > If you would like to publish the image to AWS ECR, please have a look at https://github.com/elgohr/ecr-login-action +## Outputs + +`snapshot-tag` is the tag that is generated by the `snapshot`-option + ## Optional Arguments ### registry diff --git a/entrypoint.sh b/entrypoint.sh index 2b95e42..ea4e628 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -55,12 +55,14 @@ if [ ! -z "${INPUT_CACHE}" ]; then fi if [ "${INPUT_SNAPSHOT}" = "true" ]; then - timestamp=`date +%Y%m%d%H%M%S` - shortSha=$(echo "${GITHUB_SHA}" | cut -c1-6) - SHA_DOCKER_NAME="${INPUT_NAME}:${timestamp}${shortSha}" + TIMESTAMP=`date +%Y%m%d%H%M%S` + SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-6) + SNAPSHOT_TAG="${TIMESTAMP}${SHORT_SHA}" + SHA_DOCKER_NAME="${INPUT_NAME}:${SNAPSHOT_TAG}" docker build $BUILDPARAMS -t ${DOCKERNAME} -t ${SHA_DOCKER_NAME} . docker push ${DOCKERNAME} docker push ${SHA_DOCKER_NAME} + echo ::set-output name=snapshot-tag::"${SNAPSHOT_TAG}" else docker build $BUILDPARAMS -t ${DOCKERNAME} . docker push ${DOCKERNAME} diff --git a/test.bats b/test.bats index eabbabd..67ed269 100755 --- a/test.bats +++ b/test.bats @@ -82,7 +82,7 @@ Called /usr/local/bin/docker logout" [ "$output" = "$expected" ] } -@test "it pushes branch by sha and date in addition" { +@test "it pushes a snapshot by sha and date in addition" { export INPUT_SNAPSHOT='true' export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7' export MOCK_DATE='197001010101' @@ -93,6 +93,7 @@ Called /usr/local/bin/docker logout" Called /usr/local/bin/docker build -t my/repository:latest -t my/repository:19700101010112169e . Called /usr/local/bin/docker push my/repository:latest Called /usr/local/bin/docker push my/repository:19700101010112169e +::set-output name=snapshot-tag::19700101010112169e Called /usr/local/bin/docker logout" echo $output [ "$output" = "$expected" ] @@ -111,6 +112,7 @@ Called /usr/local/bin/docker pull my/repository:latest Called /usr/local/bin/docker build --cache-from my/repository:latest -t my/repository:latest -t my/repository:19700101010112169e . Called /usr/local/bin/docker push my/repository:latest Called /usr/local/bin/docker push my/repository:19700101010112169e +::set-output name=snapshot-tag::19700101010112169e Called /usr/local/bin/docker logout" echo $output [ "$output" = "$expected" ] @@ -130,6 +132,7 @@ Called /usr/local/bin/docker pull my/repository:latest Called /usr/local/bin/docker build -t my/repository:latest -t my/repository:19700101010112169e . Called /usr/local/bin/docker push my/repository:latest Called /usr/local/bin/docker push my/repository:19700101010112169e +::set-output name=snapshot-tag::19700101010112169e Called /usr/local/bin/docker logout" echo $output [ "$output" = "$expected" ] @@ -147,6 +150,7 @@ Called /usr/local/bin/docker logout" Called /usr/local/bin/docker build -f MyDockerFileName -t my/repository:latest -t my/repository:19700101010112169e . Called /usr/local/bin/docker push my/repository:latest Called /usr/local/bin/docker push my/repository:19700101010112169e +::set-output name=snapshot-tag::19700101010112169e Called /usr/local/bin/docker logout" echo $output [ "$output" = "$expected" ] @@ -166,6 +170,7 @@ Called /usr/local/bin/docker pull my/repository:latest Called /usr/local/bin/docker build -f MyDockerFileName --cache-from my/repository:latest -t my/repository:latest -t my/repository:19700101010112169e . Called /usr/local/bin/docker push my/repository:latest Called /usr/local/bin/docker push my/repository:19700101010112169e +::set-output name=snapshot-tag::19700101010112169e Called /usr/local/bin/docker logout" echo $output [ "$output" = "$expected" ]