Skip to content

Commit 0e135af

Browse files
committed
Automate release workflow: update manifest, merge PR to dev then
fast-forward dev into master
1 parent 876cabf commit 0e135af

File tree

5 files changed

+100
-10
lines changed

5 files changed

+100
-10
lines changed

.github/tweak_changelogs.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
RELEASE_VERSION="$1"
44

5-
# Delete until and including the first line containing "<!-- Release notes generated"
6-
sed -i '1,/^<!-- Release notes generated/d' temp_change.md
5+
if grep -q "<!-- Release notes generated" temp_change.md; then
6+
# Delete up to and including the first line containing "<!-- Release notes generated"
7+
sed -i '1,/^<!-- Release notes generated/d' temp_change.md
8+
else
9+
# Otherwise, delete up to and including the first line containing "--" (The release metadata)
10+
sed -i '1,/--/d' temp_change.md
11+
fi
712

813
# Check if there is more than one non-empty line (the full changelog line) before we continue
914
if [ $(grep -c '^[[:space:]]*[^[:space:]]' temp_change.md) -le 1 ]; then
@@ -19,12 +24,12 @@ sed -i 's/\r//g' temp_change.md CHANGELOG.md changelog.txt
1924
sed -i '1h;1d;$!H;$!d;G' temp_change.md
2025
# Convert "**Full Changelog**: URL" format to markdown link format "[Full Changelog](URL)"
2126
sed -i -re 's/\*\*Full Changelog\*\*: (.*)/\[Full Changelog\]\(\1\)\n/' temp_change.md
22-
# Delete everything from "## New Contributors" line to the end of file
27+
# Delete everything from "## New Contributors" line to the end of the file
2328
sed -i '/## New Contributors/,$d' temp_change.md
2429
# Convert GitHub changelog entries to markdown format
2530
# "* description by (@username1, @username2) in #1310, #1311" → "- description #1310, #1311 (@username1, @username2)"
2631
sed -i -re 's/^\*\s(.*)\sby\s\(?(@[^)]*[^) ])\)?\s+in\s+(.*)/- \1 \3 (\2)/' temp_change.md
27-
# Convert @usernames to github links
32+
# Convert @usernames to GitHub links
2833
# "(@username1, @username2)" → "([username1](https://github.com/username1), [username2](https://github.com/username2))"
2934
sed -i -re 's/@([a-zA-Z0-9_-]+)/[\1](https:\/\/github.com\/\1)/g' temp_change.md
3035
# Convert full PR URLs to linked format
@@ -43,13 +48,17 @@ cp temp_change.md changelog_temp.txt
4348
cat CHANGELOG.md | sed '1d' >> temp_change.md
4449
# Create new CHANGELOG.md with header containing version and date, followed by processed changes
4550
printf "# Changelog\n\n## [$RELEASE_VERSION](https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2/tree/$RELEASE_VERSION) ($(date +'%Y/%m/%d'))\n\n" | cat - temp_change.md > CHANGELOG.md
51+
52+
# Delete up to and including the line containing "## What's Changed"
53+
sed -i "1,/## What's Changed/d" changelog_temp.txt
54+
4655
# Convert changelog entries from markdown link format to simplified "* description (username)" format
4756
# First remove all PR links
4857
sed -i -re 's/( \()?\[\\#[0-9]+\]\([^)]*\),? ?\)?//g' changelog_temp.txt
4958
# Remove markdown link formatting from usernames in parentheses
5059
sed -i -re 's/\[([^]]*)\]\(https:\/\/github\.com\/[^)]*\)/\1/g' changelog_temp.txt
51-
# Create new changelog format: add version header, remove lines 2-3, format section headers, remove ## headers with following line, prepend to existing changelog
52-
echo "VERSION[${RELEASE_VERSION#v}][$(date +'%Y/%m/%d')]" | cat - changelog_temp.txt | sed '2,3d' | sed -re 's/^### (.*)/\n--- \1 ---/' | sed -e '/^##.*/,+1 d' | cat - changelog.txt > changelog_new.txt
60+
# Create new changelog format: add version header, format section headers, prepend to existing changelog
61+
echo "VERSION[${RELEASE_VERSION#v}][$(date +'%Y/%m/%d')]" | cat - changelog_temp.txt | sed -re 's/^### (.*)/\n--- \1 ---/' | cat - changelog.txt > changelog_new.txt
5362
mv changelog_new.txt changelog.txt
5463

5564
# Normalize line endings to CRLF for all output files to ensure consistent checksums with Windows
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# These checks are run for PRs preparing a release
2+
name: Release Check
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
# ready_for_review is needed for the workaround described at https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#workarounds-to-trigger-further-workflow-runs
9+
- ready_for_review
10+
branches:
11+
- 'dev'
12+
paths:
13+
- 'manifest.xml'
14+
- 'changelog.txt' # To detect if this is a release PR
15+
workflow_dispatch:
16+
jobs:
17+
check_manifest:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Set line endings
21+
run: git config --global core.autocrlf true
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
- name: Update manifest
25+
run: python3 update_manifest.py --quiet --in-place
26+
- name: Check if the generated manifest is different
27+
run: git diff --exit-code manifest.xml
28+
- name: Check if the manifest version is correct
29+
if: startsWith(github.head_ref, 'release-')
30+
run: |
31+
MANIFEST_VERSION=$(grep -o '<Version number="[^"]*' manifest.xml | sed 's/<Version number="//')
32+
BRANCH_VERSION=$(echo ${{ github.head_ref }} | sed 's/release-//')
33+
if [ "$MANIFEST_VERSION" != "$BRANCH_VERSION" ]; then
34+
echo "Manifest version ($MANIFEST_VERSION) does not match branch version ($BRANCH_VERSION)"
35+
exit 1
36+
fi

.github/workflows/release.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,42 @@ jobs:
1414
release:
1515
runs-on: ubuntu-latest
1616
steps:
17+
- name: Set line endings
18+
run: git config --global core.autocrlf true
1719
- name: Checkout
18-
uses: actions/checkout@v3
20+
uses: actions/checkout@v5
1921
with:
2022
ref: 'dev'
2123
- name: Generate Release notes
2224
if: ${{ github.event.inputs.releaseNoteUrl == '' }}
2325
run: >
2426
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token;
25-
gh release view $(basename $(gh release create v${{ github.event.inputs.releaseVersion }} --title "Release ${{ github.event.inputs.releaseVersion }}" --draft --generate-notes)) > temp_change.md
27+
gh release view $(basename $(gh release create --target dev v${{ github.event.inputs.releaseVersion }} --title "Release ${{ github.event.inputs.releaseVersion }}" --draft --generate-notes)) > temp_change.md
2628
- name: Use existing Release notes
2729
if: ${{ github.event.inputs.releaseNoteUrl != '' }}
2830
run: >
2931
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token;
3032
gh release view $(basename ${{ github.event.inputs.releaseNoteUrl }}) > temp_change.md
33+
# The initial draft release must target dev for the changelog generation, but the final release should use the last commit on master to avoid tagging a wrong commit
34+
- name: Change release target to master
35+
run: |
36+
gh release edit v${{ github.event.inputs.releaseVersion }} --target master
3137
- name: Tweak changelogs
3238
run: |
3339
# Remove carriage returns to be able to run the script
3440
sed -i 's/\r$//' .github/tweak_changelogs.sh
3541
chmod +x .github/tweak_changelogs.sh
3642
.github/tweak_changelogs.sh "v${{ github.event.inputs.releaseVersion }}"
43+
- name: Update manifest version
44+
run: |
45+
sed -ri "s/<Version number=\"([^\"]*)\"/<Version number=\"${{ github.event.inputs.releaseVersion }}\"/g" manifest.xml
46+
- name: Update manifest.xml
47+
run: python3 update_manifest.py --quiet --in-place
3748
- name: Create Pull Request
38-
uses: peter-evans/create-pull-request@v5
49+
uses: peter-evans/create-pull-request@v7
3950
with:
40-
draft: true
51+
# draft: always-true is needed for the workaround described at https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#workarounds-to-trigger-further-workflow-runs
52+
draft: always-true
4153
title: Release ${{ github.event.inputs.releaseVersion }}
4254
branch: release-${{ github.event.inputs.releaseVersion }}
4355
body: |
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Sync Release to Master
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- dev
8+
9+
jobs:
10+
sync-release-to-master:
11+
# Checks that the push to dev was from a pull request whose head branch started with 'release-'.
12+
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release-')
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
with:
18+
ref: master
19+
fetch-depth: 0
20+
21+
- name: Configure bot user
22+
run: |
23+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
24+
git config --global user.name "github-actions[bot]"
25+
26+
- name: Merge fast-forward dev into master
27+
run: |
28+
git merge ${{ github.sha }} --ff-only
29+
git push

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
branches: [ dev ]
55
pull_request:
66
branches: [ dev ]
7+
types:
8+
- opened
9+
- synchronize
10+
- ready_for_review
711
workflow_dispatch:
812
jobs:
913
run_tests:

0 commit comments

Comments
 (0)