From 75d14bf3308823668cf37a0ac3b0a4a33eeb5c85 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Fri, 6 Nov 2020 15:21:50 +0100 Subject: [PATCH] Add GitHub Action to automatically create a release when creating a tag --- .github/workflows/create-release.yml | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/create-release.yml diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 0000000..34f77a4 --- /dev/null +++ b/.github/workflows/create-release.yml @@ -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<> "$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