Add GitHub Action to automatically create a release when creating a tag

pull/184/head
Michele Locati 2020-11-06 15:21:50 +01:00
parent bb3d2914eb
commit 75d14bf330
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
1 changed files with 59 additions and 0 deletions

59
.github/workflows/create-release.yml vendored Normal file
View File

@ -0,0 +1,59 @@
name: Create release
on:
create:
tags:
jobs:
create-release:
if: github.event_name == 'create' && github.event.ref_type == 'tag'
runs-on: ubuntu-latest
steps:
- name: Check tag format
run: |
THIS_TAG="${GITHUB_REF#refs/tags/}"
if printf '%s' "$THIS_TAG" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
printf 'Tag %s is version-like\n' "$THIS_TAG"
else
printf 'Tag %s is not version-like\n' "$THIS_TAG"
THIS_TAG=
fi
printf 'THIS_TAG=%s\n' "$THIS_TAG" >> "$GITHUB_ENV"
- name: Checkout
if: env.THIS_TAG != ''
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Extract release notes
if: env.THIS_TAG != ''
run: |
printf 'Generating release notes for tag %s\n' "$THIS_TAG"
TAGS="$(git tag --list --sort=-version:refname)"
PREVIOUS_TAG=
for TAG in $(git tag --list --sort=-version:refname); do
if test "$THIS_TAG" != "$TAG" && printf '%s' "$TAG" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
PREVIOUS_TAG="$TAG"
break
fi
done
if test -z "$PREVIOUS_TAG"; then
echo 'No previous tag found'
RELEASE_NOTES='First version'
else
printf 'Generating release notes for commits between %s and %s\n' "$PREVIOUS_TAG" "$THIS_TAG"
RELEASE_NOTES="$(git log --format='- %s' --no-merges --reverse "$PREVIOUS_TAG...$THIS_TAG" -- ./install-php-extensions)"
fi
printf 'Release notes:\n%s\n' "$RELEASE_NOTES"
printf 'RELEASE_NAME=v%s\n' "$THIS_TAG" >> "$GITHUB_ENV"
printf 'RELEASE_NOTES<<EOF\n%s\nEOF\n' "$RELEASE_NOTES" >> "$GITHUB_ENV"
- name: Create release
if: env.THIS_TAG != ''
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.THIS_TAG }}
release_name: ${{ env.RELEASE_NAME }}
body: ${{ env.RELEASE_NOTES }}
draft: false
prerelease: false