Publish snapshot tag as an output for later use

This commit is contained in:
Lars Gohr
2019-09-27 08:08:20 +02:00
parent 1b9fb052a2
commit a5b5841bae
3 changed files with 15 additions and 4 deletions

View File

@@ -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

View File

@@ -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}

View File

@@ -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" ]