mirror of
https://github.com/elgohr/Publish-Docker-Github-Action.git
synced 2026-03-12 18:07:12 -04:00
Stabilize and handle releases
This commit is contained in:
11
Dockerfile
11
Dockerfile
@@ -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
|
||||
|
||||
@@ -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}"
|
||||
|
||||
41
test.sh
Executable file
41
test.sh
Executable 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
|
||||
Reference in New Issue
Block a user