Stabilize and handle releases

This commit is contained in:
Lars Gohr
2019-02-27 13:57:10 +01:00
parent add4f56a20
commit 215d3ea744
4 changed files with 62 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
FROM docker
FROM docker as runtime
LABEL "com.github.actions.name"="Publish Docker"
LABEL "com.github.actions.description"="Uses the git branch as the docker tag and pushes the container"
LABEL "com.github.actions.icon"="anchor"
@@ -13,3 +13,12 @@ RUN apk update \
ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
FROM runtime as test
ADD test.sh /test.sh
ADD mock.sh /fake_bin/docker
# Use mock instead of real docker
ENV PATH="/bin:/fake_bin"
RUN /test.sh
FROM runtime

View File

@@ -1,10 +1,15 @@
#!/bin/sh -l
#!/bin/sh
DOCKER_REPOSITORY=$*
BRANCH=$(echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g")
if [ "${BRANCH}" = "master" ]; then
BRANCH="latest"
BRANCH="latest"
fi;
# if contains /refs/tags/
if [ $(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g") != ${GITHUB_REF} ]; then
BRANCH="latest"
fi;
DOCKERNAME="${DOCKER_REPOSITORY}:${BRANCH}"

3
mock.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
echo "Called mock with: $@"
exit 0

41
test.sh Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/sh -e
function itPushesMasterBranchToLatest() {
export GITHUB_REF='refs/heads/master'
result=$(exec /entrypoint.sh 'my/repository')
expected="Called mock with: build -t my/repository:latest .
Called mock with: push my/repository:latest"
if [ "$result" != "$expected" ]; then
echo "Expected: $expected
Got: $result"
exit 1
fi
}
function itPushesBranchAsNameOfTheBranch() {
export GITHUB_REF='refs/heads/myBranch'
result=$(exec /entrypoint.sh 'my/repository')
expected="Called mock with: build -t my/repository:myBranch .
Called mock with: push my/repository:myBranch"
if [ "$result" != "$expected" ]; then
echo "Expected: $expected
Got: $result"
exit 1
fi
}
function itPushesReleasesToLatest() {
export GITHUB_REF='refs/tags/myRelease'
result=$(exec /entrypoint.sh 'my/repository')
expected="Called mock with: build -t my/repository:latest .
Called mock with: push my/repository:latest"
if [ "$result" != "$expected" ]; then
echo "Expected: $expected
Got: $result"
exit 1
fi
}
itPushesMasterBranchToLatest
itPushesBranchAsNameOfTheBranch
itPushesReleasesToLatest