Create a new release after a v*.*.* commit instead of the tag (#9470)

* Create a new release after a v*.*.* commit instead of the tag

* Fix bugs

* Avoid matching things like "v2"
This commit is contained in:
Nicolò Ribaudo 2019-02-15 21:42:51 +01:00 committed by GitHub
parent 83cbc11d46
commit b25fea49fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 8 deletions

View File

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

View File

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

View File

@ -5,11 +5,20 @@ set -e
echo "INFO: Installing action dependencies..." echo "INFO: Installing action dependencies..."
(cd /action; npm ci) (cd /action; npm ci)
echo "INFO: Checking out current tag..." echo "INFO: Checking out current commit..."
git -c advice.detachedHead=false checkout $GITHUB_REF 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^) last_tag=$(git describe --abbrev=0 --tags HEAD^)
echo "INFO: New version is $current_tag; last version is $last_tag." echo "INFO: New version is $current_tag; last version is $last_tag."

10
.github/main.workflow vendored
View File

@ -10,14 +10,16 @@ action "Trigger GitHub release" {
# When GitHub Actions will support the "release" event for public # When GitHub Actions will support the "release" event for public
# repositories, we won't need these checks anymore. # repositories, we won't need these checks anymore.
needs = [ needs = [
"Is version tag", "Is version commit",
"On master branch", "On master branch",
] ]
} }
action "Is version tag" { action "Is version commit" {
uses = "actions/bin/filter@master" uses = "./.github/actions/filter-commit-message"
args = "tag v*" # 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" { action "On master branch" {