From e541342d5d78a817f89104582908294149cc4878 Mon Sep 17 00:00:00 2001 From: Lars Gohr Date: Thu, 22 Aug 2019 07:23:55 +0200 Subject: [PATCH] From buildlog it looks like the commit sha is also accessible from GITHUB_SHA. Lets try this, for making it more easy. --- entrypoint.sh | 3 +-- test.sh | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index b943b29..710d4ea 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -21,8 +21,7 @@ fi if [ "${INPUT_SNAPSHOT}" == "true" ]; then - SHA=$(env | grep ^github\\.sha= | cut -d= -f2-) # Thank you Github for using dots in variables - SHA_DOCKER_NAME="${DOCKER_REPOSITORY}:${SHA}" + SHA_DOCKER_NAME="${DOCKER_REPOSITORY}:${GITHUB_SHA}" docker build $CUSTOMDOCKERFILE -t ${DOCKERNAME} -t ${SHA_DOCKER_NAME} . docker push ${DOCKERNAME} docker push ${SHA_DOCKER_NAME} diff --git a/test.sh b/test.sh index 81e13d2..d1fd90f 100755 --- a/test.sh +++ b/test.sh @@ -3,6 +3,7 @@ function cleanEnvironment() { unset INPUT_SNAPSHOT unset INPUT_DOCKERFILE + unset GITHUB_SHA } function itPushesMasterBranchToLatest() { @@ -58,7 +59,8 @@ Called mock with: push my/repository:latest" function itPushesBranchByShaInAddition() { export GITHUB_REF='refs/tags/myRelease' export INPUT_SNAPSHOT='true' - local result=$(exec env 'github.sha'=COMMIT_SHA /entrypoint.sh 'my/repository') + export GITHUB_SHA='COMMIT_SHA' + local result=$(exec /entrypoint.sh 'my/repository') local expected="Called mock with: build -t my/repository:latest -t my/repository:COMMIT_SHA . Called mock with: push my/repository:latest Called mock with: push my/repository:COMMIT_SHA" @@ -74,7 +76,8 @@ function itPushesBranchByShaInAdditionWithSpecificDockerfile() { export GITHUB_REF='refs/tags/myRelease' export INPUT_SNAPSHOT='true' export INPUT_DOCKERFILE='MyDockerFileName' - local result=$(exec env 'github.sha'=COMMIT_SHA /entrypoint.sh 'my/repository') + export GITHUB_SHA='COMMIT_SHA' + local result=$(exec /entrypoint.sh 'my/repository') local expected="Called mock with: build -f MyDockerFileName -t my/repository:latest -t my/repository:COMMIT_SHA . Called mock with: push my/repository:latest Called mock with: push my/repository:COMMIT_SHA"