From 7f8a8d4a00692303bbceb34faf4abe8e4c258b1a Mon Sep 17 00:00:00 2001 From: Lars Gohr Date: Fri, 23 Aug 2019 00:49:32 +0200 Subject: [PATCH] Add checks for mandatory fields --- entrypoint.sh | 15 +++++++++++++++ test.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index d4930fc7..ae3b4f4a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,20 @@ #!/bin/sh +if [ -z "${INPUT_NAME}" ]; then + echo "Unable to find the repository name. Did you set with.name?" + exit 1 +fi + +if [ -z "${INPUT_USERNAME}" ]; then + echo "Unable to find the username. Did you set with.username?" + exit 1 +fi + +if [ -z "${INPUT_PASSWORD}" ]; then + echo "Unable to find the password. Did you set with.password?" + exit 1 +fi + BRANCH=$(echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g") if [ "${BRANCH}" == "master" ]; then diff --git a/test.sh b/test.sh index 07d59d3c..19c655f4 100755 --- a/test.sh +++ b/test.sh @@ -138,6 +138,42 @@ Called mock with: logout" cleanEnvironment } +function itErrorsWhenNameWasNotSet() { + unset INPUT_NAME + local result=$(exec /entrypoint.sh) + local expected="Unable to find the repository name. Did you set with.name?" + if [ "$result" != "$expected" ]; then + echo "Expected: $expected + Got: $result" + exit 1 + fi +} + +function itErrorsWhenUsernameWasNotSet() { + export INPUT_NAME='my/repository' + unset INPUT_USERNAME + local result=$(exec /entrypoint.sh) + local expected="Unable to find the username. Did you set with.username?" + if [ "$result" != "$expected" ]; then + echo "Expected: $expected + Got: $result" + exit 1 + fi +} + +function itErrorsWhenPasswordWasNotSet() { + export INPUT_NAME='my/repository' + export INPUT_USERNAME='USERNAME' + unset INPUT_PASSWORD + local result=$(exec /entrypoint.sh) + local expected="Unable to find the password. Did you set with.password?" + if [ "$result" != "$expected" ]; then + echo "Expected: $expected + Got: $result" + exit 1 + fi +} + itPushesMasterBranchToLatest itPushesBranchAsNameOfTheBranch itPushesReleasesToLatest @@ -145,3 +181,6 @@ itPushesSpecificDockerfileReleasesToLatest itPushesBranchByShaInAddition itPushesBranchByShaInAdditionWithSpecificDockerfile itLogsIntoAnotherRegistryIfConfigured +itErrorsWhenNameWasNotSet +itErrorsWhenUsernameWasNotSet +itErrorsWhenPasswordWasNotSet