Skip to content

Commit

Permalink
Add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr committed Mar 27, 2024
1 parent d9534dd commit c17bbda
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 ""
23 changes: 23 additions & 0 deletions get-changelog.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c17bbda

Please sign in to comment.