mirror of
https://github.com/elgohr/Publish-Docker-Github-Action.git
synced 2026-03-12 18:07:12 -04:00
Check booleans for falseness
This commit is contained in:
@@ -30,11 +30,11 @@ function main() {
|
||||
if uses "${INPUT_BUILDARGS}"; then
|
||||
addBuildArgs
|
||||
fi
|
||||
if uses "${INPUT_CACHE}"; then
|
||||
if usesBoolean "${INPUT_CACHE}"; then
|
||||
useBuildCache
|
||||
fi
|
||||
|
||||
if uses "${INPUT_SNAPSHOT}"; then
|
||||
if usesBoolean "${INPUT_SNAPSHOT}"; then
|
||||
pushWithSnapshot
|
||||
else
|
||||
pushWithoutSnapshot
|
||||
@@ -62,7 +62,7 @@ function translateDockerTag() {
|
||||
INPUT_NAME=$(echo ${INPUT_NAME} | cut -d':' -f1)
|
||||
elif isOnMaster; then
|
||||
TAG="latest"
|
||||
elif isGitTag && uses "${INPUT_TAG_NAMES}"; then
|
||||
elif isGitTag && usesBoolean "${INPUT_TAG_NAMES}"; then
|
||||
TAG=$(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g")
|
||||
elif isGitTag; then
|
||||
TAG="latest"
|
||||
@@ -114,6 +114,10 @@ function uses() {
|
||||
[ ! -z "${1}" ]
|
||||
}
|
||||
|
||||
function usesBoolean() {
|
||||
[ ! -z "${1}" ] && [ "${1}" = "true" ]
|
||||
}
|
||||
|
||||
function pushWithSnapshot() {
|
||||
local TIMESTAMP=`date +%Y%m%d%H%M%S`
|
||||
local SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-6)
|
||||
|
||||
48
test.bats
48
test.bats
@@ -82,7 +82,7 @@ teardown() {
|
||||
|
||||
@test "with tag names it pushes tags using the name" {
|
||||
export GITHUB_REF='refs/tags/myRelease'
|
||||
export INPUT_TAG_NAMES=true
|
||||
export INPUT_TAG_NAMES="true"
|
||||
|
||||
run /entrypoint.sh
|
||||
|
||||
@@ -95,6 +95,21 @@ teardown() {
|
||||
/usr/local/bin/docker logout"
|
||||
}
|
||||
|
||||
@test "with tag names set to false it doesn't push tags using the name" {
|
||||
export GITHUB_REF='refs/tags/myRelease'
|
||||
export INPUT_TAG_NAMES="false"
|
||||
|
||||
run /entrypoint.sh
|
||||
|
||||
expectStdOut "
|
||||
::set-output name=tag::latest"
|
||||
|
||||
expectMockCalled "/usr/local/bin/docker login -u USERNAME --password-stdin
|
||||
/usr/local/bin/docker build -t my/repository:latest .
|
||||
/usr/local/bin/docker push my/repository:latest
|
||||
/usr/local/bin/docker logout"
|
||||
}
|
||||
|
||||
@test "it pushes specific Dockerfile to latest" {
|
||||
export INPUT_DOCKERFILE='MyDockerFileName'
|
||||
|
||||
@@ -132,6 +147,26 @@ teardown() {
|
||||
/usr/local/bin/docker logout"
|
||||
}
|
||||
|
||||
@test "it does not push a snapshot by sha and date in addition when turned off" {
|
||||
export INPUT_SNAPSHOT='false'
|
||||
export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7'
|
||||
|
||||
declare -A -p MOCK_RETURNS=(
|
||||
['/usr/local/bin/docker']=""
|
||||
['/usr/bin/date']="197001010101"
|
||||
) > mockReturns
|
||||
|
||||
run /entrypoint.sh
|
||||
|
||||
expectStdOut "
|
||||
::set-output name=tag::latest"
|
||||
|
||||
expectMockCalled "/usr/local/bin/docker login -u USERNAME --password-stdin
|
||||
/usr/local/bin/docker build -t my/repository:latest .
|
||||
/usr/local/bin/docker push my/repository:latest
|
||||
/usr/local/bin/docker logout"
|
||||
}
|
||||
|
||||
@test "it caches image from former build and uses it for snapshot" {
|
||||
export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7'
|
||||
export INPUT_SNAPSHOT='true'
|
||||
@@ -264,6 +299,17 @@ teardown() {
|
||||
/usr/local/bin/docker logout"
|
||||
}
|
||||
|
||||
@test "it does not cache the image from a former build if set to false" {
|
||||
export INPUT_CACHE='false'
|
||||
|
||||
run /entrypoint.sh
|
||||
|
||||
expectMockCalled "/usr/local/bin/docker login -u USERNAME --password-stdin
|
||||
/usr/local/bin/docker build -t my/repository:latest .
|
||||
/usr/local/bin/docker push my/repository:latest
|
||||
/usr/local/bin/docker logout"
|
||||
}
|
||||
|
||||
@test "it pushes pull requests when configured" {
|
||||
export GITHUB_REF='refs/pull/24/merge'
|
||||
export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7'
|
||||
|
||||
Reference in New Issue
Block a user