From b1253b2edfcd8636685eb08955d28698c6db53d2 Mon Sep 17 00:00:00 2001 From: Lars Gohr Date: Sun, 20 Sep 2020 19:40:12 +0200 Subject: [PATCH] :sparkles: Support new default branch See https://github.com/github/renaming#on-october-1-2020-newly-created-repositories-will-default-to-main --- entrypoint.sh | 6 +++--- test.bats | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 02b783ae..981b8451 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -115,11 +115,11 @@ hasCustomTag() { } isOnDefaultBranch() { - local DEFAULT_BRANCH="master" if uses "${INPUT_DEFAULT_BRANCH}"; then - DEFAULT_BRANCH="${INPUT_DEFAULT_BRANCH}" + [ "${BRANCH}" = "${INPUT_DEFAULT_BRANCH}" ] + else + [ "${BRANCH}" = "master" ] || [ "${BRANCH}" = "main" ] fi - [ "${BRANCH}" = "${DEFAULT_BRANCH}" ] } isGitTag() { diff --git a/test.bats b/test.bats index c312d725..1ae79ec9 100755 --- a/test.bats +++ b/test.bats @@ -25,6 +25,20 @@ teardown() { unset MOCK_ERROR_CONDITION } +@test "it pushes main branch to latest" { + export GITHUB_REF='refs/heads/main' + + run /entrypoint.sh + + expectStdOutContains "::set-output name=tag::latest" + + expectMockCalledContains "/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 inspect --format={{index .RepoDigests 0}} my/repository:latest +/usr/local/bin/docker logout" +} + @test "it pushes master branch to latest" { export GITHUB_REF='refs/heads/master'