-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into MIJN-9794-afis-live
- Loading branch information
Showing
4 changed files
with
134 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: 'Release notification' | ||
on: | ||
push: | ||
tags: | ||
- release-* | ||
run-name: Generating release notes for ${{ github.base_ref }} | ||
permissions: | ||
contents: write | ||
jobs: | ||
create-publish-release-notes: | ||
runs-on: ubuntu-latest | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
fetch-tags: true | ||
|
||
- name: Generate and update the release notes | ||
run: | | ||
all_tags=$(git tag -l --sort=-creatordate) | ||
latest_tag=$(echo "$all_tags" | sed -n '1p') | ||
previous_tag=$(echo "$all_tags" | sed -n '2p') | ||
release_notes=$(git log "$previous_tag..$latest_tag" --oneline) | ||
release_notes=$(echo "$release_notes" | python3\ | ||
./scripts/create-release-notes.py\ | ||
"$previous_tag"\ | ||
"$latest_tag"\ | ||
) | ||
if gh release view "$latest_tag" &>/dev/null; then | ||
echo "Release exists. Updating..." | ||
gh release edit "$latest_tag" --notes "$release_notes" | ||
else | ||
echo "Creating new release..." | ||
gh release create "$latest_tag" --notes "$release_notes" | ||
fi | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import sys | ||
import re | ||
from functools import reduce | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Create release notes for a github workflow." | ||
) | ||
|
||
parser.add_argument("previous_release_tag") | ||
parser.add_argument("latest_release_tag") | ||
|
||
args = parser.parse_args() | ||
|
||
release_notes = sys.stdin.read() | ||
if not release_notes: | ||
raise Exception("Release notes read from the stdin are empty") | ||
|
||
categories = { | ||
"features": { | ||
"pattern": re.compile(r'MIJN-[0-9]+-FEATURE', flags=re.IGNORECASE), | ||
"commits": [] | ||
}, | ||
"chores": { | ||
"pattern": re.compile(r'MIJN-[0-9]+-CHORE', flags=re.IGNORECASE), | ||
"commits": [] | ||
}, | ||
"bugs": { | ||
"pattern": re.compile(r'MIJN-[0-9]+-BUG', flags=re.IGNORECASE), | ||
"commits": [] | ||
}, | ||
} | ||
|
||
other = { | ||
# Must start with a commit hash | ||
"pattern": re.compile(r'^[a-z\d]+\b'), | ||
"commits": [] | ||
} | ||
|
||
# Sort release notes | ||
# ================== | ||
for line in release_notes.split('\n'): | ||
def identify(acc, category): | ||
if categories[category]["pattern"].search(line): | ||
return category | ||
return acc | ||
|
||
category = reduce(identify, categories, None) | ||
|
||
try: | ||
categories[category]["commits"].append(line) | ||
except KeyError: | ||
if other["pattern"].match(line): | ||
other["commits"].append(line) | ||
|
||
# Format | ||
# ================================ | ||
categories["other"] = other | ||
|
||
RELEASE_SUFFIX = 'release-' | ||
previous_version = args.previous_release_tag.removeprefix(RELEASE_SUFFIX) | ||
latest_version = args.latest_release_tag.removeprefix(RELEASE_SUFFIX) | ||
|
||
# Lines entered here are at the top of the release notes. | ||
release_notes = [ | ||
f"Here are the updates between the {previous_version} and {latest_version} releases.\n", | ||
] | ||
|
||
release_notes_size = len(release_notes) | ||
|
||
def format_category(acc, category): | ||
commits = categories[category]["commits"] | ||
if not commits: | ||
return acc | ||
|
||
# Add title in markdown. | ||
acc.append(f"## {category.title()}\n") | ||
|
||
for commit in commits: | ||
acc.append(commit) | ||
|
||
# Make sure a newline is added after the block of commits. | ||
acc.append("") | ||
|
||
return acc | ||
|
||
release_notes = reduce(format_category, categories, release_notes) | ||
if release_notes_size == len(release_notes): | ||
raise Exception("Not a single line added to the release notes.") | ||
|
||
print('\n'.join(release_notes)) | ||
|