diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..780f962 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,51 @@ +name: Release + +on: + release: + types: [released] + workflow_dispatch: + inputs: + TAG_NAME: + description: "Tag name" + required: true + +env: + REGISTRY: ghcr.io + TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + patch-changelog: + runs-on: ubuntu-latest + name: Patch CHANGELOG.md and update GitHub release notes + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set environment variables + run: | + echo GIT_BRANCH_NAME=mark-version-${TAG_NAME#v}-as-released >> $GITHUB_ENV + echo GIT_COMMIT_MESSAGE=Mark version ${TAG_NAME#v} as released >> $GITHUB_ENV + echo RELEASE_ID=$(gh api -H "Accept: application/vnd.github+json" /repos/${GITHUB_REPOSITORY}/releases/tags/${TAG_NAME} | jq '.id') >> $GITHUB_ENV + + - name: Get changelog for this specific release and update release notes + run: | + gh api \ + --method PATCH \ + --header "Accept: application/vnd.github+json" \ + /repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID} \ + -f body="$(./get-changelog.sh)" + + - name: Checkout new branch and patch changelog + run: | + git checkout -b $GIT_BRANCH_NAME + sed -i "/^\#\# \[Unreleased\]$/a \\\n\#\# $TAG_NAME - $(date '+%Y-%m-%d')" CHANGELOG.md + + - name: Commit, push and create pull request + run: | + git config --global user.email "office@geowerkstatt.ch" + git config --global user.name "GeoWerkstatt-Build" + git commit -am "$GIT_COMMIT_MESSAGE" + git push --set-upstream origin $GIT_BRANCH_NAME + gh pr create --title "$GIT_COMMIT_MESSAGE" --body "" diff --git a/get-changelog.sh b/get-changelog.sh new file mode 100644 index 0000000..82a3498 --- /dev/null +++ b/get-changelog.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# This script gets all changelog entries from CHANGELOG.md since last release. + +set -e + +tempDir="$(mktemp -d)" +tempFile=$tempDir/gh_release_notes.md + +# Get changelog entries since last release +cat CHANGELOG.md | \ + grep -Pazo '(?s)(?<=\#{2} \[Unreleased\]\n{2}).*?(?=\n\#{2} v|$)' \ + > $tempFile + +# Improve readability and add some icons +sed -i -E 's/(###) (Added)/\1 🚀 \2/' $tempFile +sed -i -E 's/(###) (Changed)/\1 🔨 \2/' $tempFile +sed -i -E 's/(###) (Fixed)/\1 🐛 \2/' $tempFile +sed -i 's/\x0//g' $tempFile + +cat $tempFile + +# Cleanup temporary files +trap 'rm -rf -- "$tempDir"' EXIT \ No newline at end of file