Skip to content

Commit

Permalink
no_push can be used without login (#111)
Browse files Browse the repository at this point in the history
- fixes #110
  • Loading branch information
casperdcl authored Dec 15, 2020
1 parent 5e568dd commit f7aca2f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
20 changes: 13 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,15 +26,17 @@ main() {

if uses "${INPUT_TAGS}"; then
TAGS=$(echo "${INPUT_TAGS}" | sed "s/,/ /g")
else
else
translateDockerTag
fi

if uses "${INPUT_WORKDIR}"; then
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}"
Expand All @@ -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

Expand Down
12 changes: 12 additions & 0 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit f7aca2f

Please sign in to comment.