Skip to content

Commit

Permalink
Publish snapshot tag as an output for later use
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Gohr committed Sep 27, 2019
1 parent 1b9fb05 commit a5b5841
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
7 changes: 6 additions & 1 deletion test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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" ]
Expand All @@ -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" ]
Expand All @@ -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" ]
Expand All @@ -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" ]
Expand All @@ -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" ]
Expand Down

0 comments on commit a5b5841

Please sign in to comment.