mirror of
https://github.com/elgohr/Publish-Docker-Github-Action.git
synced 2026-03-12 18:07:12 -04:00
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:
@@ -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
|
||||
|
||||
6
stub.sh
6
stub.sh
@@ -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
|
||||
|
||||
20
test.bats
20
test.bats
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user