From f7aca2fea76a5218f3c76cd5933c3ba1d8008774 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 15 Dec 2020 07:44:30 +0000 Subject: [PATCH] no_push can be used without login (#111) - fixes #110 --- entrypoint.sh | 20 +++++++++++++------- test.bats | 12 ++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index cc0e7049..8b8aa9c4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,10 +9,12 @@ main() { echo "::add-mask::${INPUT_PASSWORD}" set -x fi - + sanitize "${INPUT_NAME}" "name" - sanitize "${INPUT_USERNAME}" "username" - sanitize "${INPUT_PASSWORD}" "password" + if ! usesBoolean "${INPUT_NO_PUSH}"; then + sanitize "${INPUT_USERNAME}" "username" + sanitize "${INPUT_PASSWORD}" "password" + fi registryToLower nameToLower @@ -24,7 +26,7 @@ main() { if uses "${INPUT_TAGS}"; then TAGS=$(echo "${INPUT_TAGS}" | sed "s/,/ /g") - else + else translateDockerTag fi @@ -32,7 +34,9 @@ main() { changeWorkingDirectory fi - echo "${INPUT_PASSWORD}" | docker login -u ${INPUT_USERNAME} --password-stdin ${INPUT_REGISTRY} + if uses "${INPUT_USERNAME}" && uses "${INPUT_PASSWORD}"; then + echo "${INPUT_PASSWORD}" | docker login -u ${INPUT_USERNAME} --password-stdin ${INPUT_REGISTRY} + fi FIRST_TAG=$(echo "${TAGS}" | cut -d ' ' -f1) DOCKERNAME="${INPUT_NAME}:${FIRST_TAG}" @@ -56,9 +60,11 @@ main() { fi build - + if usesBoolean "${INPUT_NO_PUSH}"; then - docker logout + if uses "${INPUT_USERNAME}" && uses "${INPUT_PASSWORD}"; then + docker logout + fi exit 0 fi diff --git a/test.bats b/test.bats index 3856546a..e95172f4 100755 --- a/test.bats +++ b/test.bats @@ -627,6 +627,18 @@ teardown() { /usr/local/bin/docker logout" } +@test "it can be used for building without login" { + export GITHUB_REF='refs/heads/master' + export INPUT_NO_PUSH='true' + export INPUT_USERNAME='' + + run /entrypoint.sh + + expectStdOutIs "" + + expectMockCalledIs "/usr/local/bin/docker build -t my/repository:latest ." +} + @test "it can change the default branch" { export GITHUB_REF='refs/heads/trunk' export INPUT_DEFAULT_BRANCH='trunk'