[gh action] Release on tag push

This commit is contained in:
Nicolò Ribaudo 2019-07-20 16:39:10 +02:00
parent 3b4a86aea4
commit fb910e063c
No known key found for this signature in database
GPG Key ID: 6F2E38DF3E4A6D0C
6 changed files with 30 additions and 56 deletions

View File

@ -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"

View File

@ -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

View File

@ -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"]

View File

@ -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"

View File

@ -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

20
.github/main.workflow vendored
View File

@ -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",
]
}