Skip to content

Commit

Permalink
Create a new release after a v*.*.* commit instead of the tag (#9470)
Browse files Browse the repository at this point in the history
* Create a new release after a v*.*.* commit instead of the tag

* Fix bugs

* Avoid matching things like "v2"
  • Loading branch information
nicolo-ribaudo committed Feb 15, 2019
1 parent 83cbc11 commit b25fea4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .github/actions/filter-commit-message/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM debian:stable-slim

LABEL "name"="filter"
LABEL "version"="1.1.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.icon"="filter"
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"]
15 changes: 15 additions & 0 deletions .github/actions/filter-commit-message/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/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
17 changes: 13 additions & 4 deletions .github/actions/trigger-github-release/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ set -e
echo "INFO: Installing action dependencies..."
(cd /action; npm ci)

echo "INFO: Checking out current tag..."
git -c advice.detachedHead=false checkout $GITHUB_REF
echo "INFO: Checking out current commit..."
git -c advice.detachedHead=false checkout $GITHUB_SHA

# 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..."
# current_tag=$(git describe --abbrev=0 --tags HEAD)
current_tag=$(git log --oneline --format=%B -1 HEAD)

echo "INFO: Creating new tag..."
(git tag $current_tag $GITHUB_SHA) || echo "INFO: Tag already exists"

echo "INFO: Getting tag info..."
current_tag=$(git describe --abbrev=0 --tags)
last_tag=$(git describe --abbrev=0 --tags HEAD^)
echo "INFO: New version is $current_tag; last version is $last_tag."

Expand Down
10 changes: 6 additions & 4 deletions .github/main.workflow
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ action "Trigger GitHub release" {
# When GitHub Actions will support the "release" event for public
# repositories, we won't need these checks anymore.
needs = [
"Is version tag",
"Is version commit",
"On master branch",
]
}

action "Is version tag" {
uses = "actions/bin/filter@master"
args = "tag v*"
action "Is version commit" {
uses = "./.github/actions/filter-commit-message"
# This regex is run using "grep -P".
# The (-\\S+) part is for 7.0.0-beta.1 releases.
args = "^v(\\d+\\.){2}\\d+(-\\S+)?$"
}

action "On master branch" {
Expand Down

0 comments on commit b25fea4

Please sign in to comment.