From fb910e063cfa2977508624e6911e8beb3be49a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sat, 20 Jul 2019 16:39:10 +0200 Subject: [PATCH] [gh action] Release on tag push --- .../Dockerfile | 8 ++++---- .../commit-matches-branch/entrypoint.sh | 13 ++++++++++++ .github/actions/create-release-tag/Dockerfile | 16 --------------- .../actions/create-release-tag/entrypoint.sh | 14 ------------- .../filter-commit-message/entrypoint.sh | 15 -------------- .github/main.workflow | 20 ++++++++++++------- 6 files changed, 30 insertions(+), 56 deletions(-) rename .github/actions/{filter-commit-message => commit-matches-branch}/Dockerfile (54%) create mode 100644 .github/actions/commit-matches-branch/entrypoint.sh delete mode 100644 .github/actions/create-release-tag/Dockerfile delete mode 100644 .github/actions/create-release-tag/entrypoint.sh delete mode 100644 .github/actions/filter-commit-message/entrypoint.sh diff --git a/.github/actions/filter-commit-message/Dockerfile b/.github/actions/commit-matches-branch/Dockerfile similarity index 54% rename from .github/actions/filter-commit-message/Dockerfile rename to .github/actions/commit-matches-branch/Dockerfile index 4779062c2a..88cd83ade9 100644 --- a/.github/actions/filter-commit-message/Dockerfile +++ b/.github/actions/commit-matches-branch/Dockerfile @@ -1,10 +1,10 @@ FROM debian:stable-slim -LABEL "name"="filter" -LABEL "version"="1.1.0" +LABEL "name"="commit-matches-branch" +LABEL "version"="1.0.0" -LABEL "com.github.actions.name"="Filter commit message" -LABEL "com.github.actions.description"="Stop a workflow if the message of the current commit doesn't match the pattern" +LABEL "com.github.actions.name"="Commit matches branch" +LABEL "com.github.actions.description"="Only continue the workflow if the current commit is the last commit of the given branch" LABEL "com.github.actions.icon"="filter" LABEL "com.github.actions.color"="gray-dark" diff --git a/.github/actions/commit-matches-branch/entrypoint.sh b/.github/actions/commit-matches-branch/entrypoint.sh new file mode 100644 index 0000000000..5b2f2e066d --- /dev/null +++ b/.github/actions/commit-matches-branch/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e + +current=$(git rev-parse HEAD) +git checkout $1 +branch=$(git rev-parse HEAD) + +if [ "$current" = "$branch" ]; then + exit 0 +else + exit 78 +fi diff --git a/.github/actions/create-release-tag/Dockerfile b/.github/actions/create-release-tag/Dockerfile deleted file mode 100644 index 58c743a3d5..0000000000 --- a/.github/actions/create-release-tag/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM debian:stable-slim - -LABEL "name"="create-release-tag" -LABEL "version"="0.0.1" - -LABEL "com.github.actions.name"="Create release tag" -LABEL "com.github.actions.description"="Creates a release tag equal to the last commit message" -LABEL "com.github.actions.icon"="tag" -LABEL "com.github.actions.color"="gray-dark" - -ADD entrypoint.sh /action/entrypoint.sh - -RUN chmod +x /action/entrypoint.sh -RUN apt-get update && apt-get install -y --no-install-recommends git - -ENTRYPOINT ["/action/entrypoint.sh"] diff --git a/.github/actions/create-release-tag/entrypoint.sh b/.github/actions/create-release-tag/entrypoint.sh deleted file mode 100644 index 225797f397..0000000000 --- a/.github/actions/create-release-tag/entrypoint.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -set -e - -# GitHub doesn't support running actions on new tags yet: we need to run it on the commit. -# For this reason, we can't be sure that the tag already exists. We can use the commit -# message to create the tag. If the tag already exists locally, they won't conflict because -# they have the same name and are on the same commit. - -echo "INFO: Getting release version..." -tag_name=$(git log --oneline --format=%B -1 $GITHUB_SHA) - -echo "INFO: Creating new tag..." -(git tag $tag_name $GITHUB_SHA) || echo "INFO: Tag already exists" diff --git a/.github/actions/filter-commit-message/entrypoint.sh b/.github/actions/filter-commit-message/entrypoint.sh deleted file mode 100644 index ba8873b64b..0000000000 --- a/.github/actions/filter-commit-message/entrypoint.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -set -e - -pattern=$1 -message=$(git log --oneline --format=%B -1 $GITHUB_SHA) - -if echo "$message" | grep -Pq "$pattern"; then - echo "INFO: $message matches $pattern" - exit 0 -else - echo "INFO: $message does not match $pattern" - # 78 is the "neutral" exit status - exit 78 -fi diff --git a/.github/main.workflow b/.github/main.workflow index 3c6315efff..eab86380dc 100644 --- a/.github/main.workflow +++ b/.github/main.workflow @@ -1,18 +1,23 @@ workflow "Release" { - resolves = [ - "Trigger GitHub release", - "Is version tag", - ] - on = "release" + on = "push" + resolves = ["Trigger GitHub release"] } action "Is version tag" { - uses = "actions/bin/filter@master" + uses = "actions/bin/filter@0dbb077f64d0ec1068a644d25c71b1db66148a24" args = "tag v*" } +action "Is tag from master" { + uses = "./commit-matches-branch/" + needs = [ + "Is version tag", + ] + args = "master" +} + action "Trigger GitHub release" { - uses = "./.github/actions/trigger-github-release/" + uses = "./trigger-github-release/" secrets = ["GITHUB_TOKEN"] env = { COMMIT_AUTHOR_NAME = "Babel Bot" @@ -20,6 +25,7 @@ action "Trigger GitHub release" { } needs = [ "Is version tag", + "Is tag from master", ] }