Fix breaking builds when the cached image was not there with tests (https://github.com/elgohr/Publish-Docker-Github-Action/pull/20)

This commit is contained in:
Lars Gohr
2019-09-15 13:50:26 +02:00
parent 073c9a9c0e
commit 2684231638
3 changed files with 28 additions and 3 deletions

View File

@@ -45,8 +45,9 @@ if [ ! -z "${INPUT_DOCKERFILE}" ]; then
fi
if [ ! -z "${INPUT_CACHE}" ]; then
docker pull ${DOCKERNAME}
BUILDPARAMS="$BUILDPARAMS --cache-from ${DOCKERNAME}"
if docker pull ${DOCKERNAME} 2>/dev/null; then
BUILDPARAMS="$BUILDPARAMS --cache-from ${DOCKERNAME}"
fi
fi
if [ "${INPUT_SNAPSHOT}" = "true" ]; then

View File

@@ -1,3 +1,7 @@
#!/bin/sh
echo "Called mock with: $@"
parameters="$@"
echo "Called mock with: ${parameters}"
if [ "${MOCK_ERROR_CONDITION}" = "${parameters}" ]; then
exit 1
fi
exit 0

View File

@@ -14,6 +14,7 @@ teardown() {
unset INPUT_CACHE
unset GITHUB_SHA
unset INPUT_PULL_REQUESTS
unset MOCK_ERROR_CONDITION
}
@test "it pushes master branch to latest" {
@@ -115,6 +116,25 @@ Called mock with: logout"
[ "$output" = "$expected" ]
}
@test "it does not use the cache for building when pulling the former image failed" {
export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7'
export MOCK_DATE='197001010101'
export INPUT_SNAPSHOT='true'
export INPUT_CACHE='true'
export MOCK_ERROR_CONDITION='pull my/repository:latest'
run /entrypoint.sh
local expected="Called mock with: login -u USERNAME --password-stdin
Called mock with: pull my/repository:latest
Called mock with: build -t my/repository:latest -t my/repository:19700101010112169e .
Called mock with: push my/repository:latest
Called mock with: push my/repository:19700101010112169e
Called mock with: logout"
echo $output
[ "$output" = "$expected" ]
}
@test "it pushes branch by sha and date with specific Dockerfile" {
export GITHUB_SHA='12169ed809255604e557a82617264e9c373faca7'
export MOCK_DATE='197001010101'