Skip to content

A local-first personal finance app

fix release automation with branch protection (#8842)

Matt Fiddaman62a18ba77081
diff --git a/.github/workflows/cut-release-branch.yml b/.github/workflows/cut-release-branch.yml
index c1ea73ba86..0f03114310 100644
--- a/.github/workflows/cut-release-branch.yml
+++ b/.github/workflows/cut-release-branch.yml
@@ -115,7 +115,7 @@ jobs:
branch: 'release-notes/${{ steps.version.outputs.version }}'
base: master
- - name: Update release branch
+ - name: Open release branch update PR
env:
VERSION: ${{ steps.version.outputs.version }}
TYPE: ${{ steps.version.outputs.type }}
@@ -124,17 +124,55 @@ jobs:
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
- if gh api "repos/${GITHUB_REPOSITORY}/branches/release" --silent >/dev/null 2>&1; then
- git fetch origin release
- git checkout release
+ git fetch origin "release-notes/$VERSION"
+ bump_commit=$(git rev-parse FETCH_HEAD)
+
+ if ! gh api "repos/${GITHUB_REPOSITORY}/branches/release" --silent >/dev/null 2>&1; then
+ # No release branch yet: create it directly from the bump commit.
+ git push origin "$bump_commit:refs/heads/release"
+ exit 0
+ fi
+
+ git fetch origin master release
+ branch="release-update/$VERSION"
- if [[ "$TYPE" == "monthly" ]]; then
- git fetch origin master
- git merge --no-edit -X theirs origin/master
- git diff --exit-code origin/master
+ if [[ "$TYPE" == "monthly" ]]; then
+ # Take master + version bump wholesale. `-s ours` records release
+ # as merged without attempting any content merge, so divergent
+ # histories (including modify/delete) can never conflict.
+ git checkout -B "$branch" "$bump_commit"
+ git merge -s ours --no-edit origin/release
+ git diff --exit-code "$bump_commit"
+ else
+ git checkout -B "$branch" origin/release
+
+ # Drop release notes already shipped by a previous release: the
+ # release-notes PR deletes them from master but not from release,
+ # and a hotfix must not compile them into its changelog again.
+ stale=$(comm -23 \
+ <(git ls-tree -r --name-only origin/release upcoming-release-notes/ | sort) \
+ <(git ls-tree -r --name-only origin/master upcoming-release-notes/ | sort))
+ if [[ -n "$stale" ]]; then
+ echo "$stale" | xargs git rm -q --
+ git commit -m 'πŸ”– remove release notes shipped in previous releases'
fi
+
+ git cherry-pick "$bump_commit"
fi
- git fetch origin "release-notes/$VERSION"
- git cherry-pick FETCH_HEAD
- git push origin HEAD:refs/heads/release
+ git push --force origin "HEAD:refs/heads/$branch"
+
+ open_prs=$(gh pr list --head "$branch" --base release --state open --json number --jq 'length')
+ if [[ "$open_prs" == "0" ]]; then
+ {
+ echo "Generated by [cut-release-branch.yml](../tree/master/.github/workflows/cut-release-branch.yml)"
+ echo
+ echo "Merging this PR updates the \`release\` branch for ${VERSION}. Release-note generation runs automatically once it is merged."
+ } > "$RUNNER_TEMP/release-pr-body.md"
+
+ gh pr create \
+ --base release \
+ --head "$branch" \
+ --title "πŸ”– update release branch (${VERSION})" \
+ --body-file "$RUNNER_TEMP/release-pr-body.md"
+ fi
diff --git a/.github/workflows/release-notes.yml b/.github/workflows/release-notes.yml
index 057dab0a56..da67d872b5 100644
--- a/.github/workflows/release-notes.yml
+++ b/.github/workflows/release-notes.yml
@@ -5,11 +5,6 @@ on:
push:
branches:
- release
- workflow_run: # zizmor: ignore[dangerous-triggers]
- workflows: ['Cut release branch']
- types:
- - completed
- branches: [master]
permissions: {}
@@ -73,10 +68,7 @@ jobs:
uses: ./.github/actions/release-notes/check
generate-release-notes:
- if: >-
- github.event_name == 'push'
- || (github.event_name == 'workflow_run'
- && github.event.workflow_run.conclusion == 'success')
+ if: github.event_name == 'push'
runs-on: depot-ubuntu-latest
environment: release
permissions:
@@ -92,7 +84,22 @@ jobs:
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "notes_branch=release-notes/$version" >> "$GITHUB_OUTPUT"
+ # Pushes to release can happen outside a cut (e.g. hotfix commits
+ # landing before the version bump). Only generate notes when the cut
+ # has opened the notes branch and the version has not shipped yet.
+ repo_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
+ if git ls-remote --exit-code "$repo_url" "refs/tags/v$version" >/dev/null 2>&1; then
+ echo "Tag v$version already published; skipping generation"
+ echo "skip=true" >> "$GITHUB_OUTPUT"
+ elif ! git ls-remote --exit-code "$repo_url" "refs/heads/release-notes/$version" >/dev/null 2>&1; then
+ echo "Notes branch release-notes/$version does not exist yet; skipping generation"
+ echo "skip=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "skip=false" >> "$GITHUB_OUTPUT"
+ fi
+
- name: Checkout release-notes branch
+ if: steps.version.outputs.skip != 'true'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ steps.version.outputs.notes_branch }}
@@ -100,6 +107,7 @@ jobs:
persist-credentials: true
- name: Generate release notes
+ if: steps.version.outputs.skip != 'true'
uses: ./.github/actions/release-notes/generate
with:
release-branch: release
diff --git a/packages/ci-actions/bin/release-notes-generate.mjs b/packages/ci-actions/bin/release-notes-generate.mjs
index c3d89fdb4d..97bb8bb1b3 100644
--- a/packages/ci-actions/bin/release-notes-generate.mjs
+++ b/packages/ci-actions/bin/release-notes-generate.mjs
@@ -130,11 +130,25 @@ await group('Prepare branch', async () => {
});
});
+// Only notes present on the release branch belong in this release. The notes
+// branch is created from master, so on a hotfix the directory also holds
+// master's pending notes for changes that are not part of the release; those
+// must be neither compiled nor deleted (deleting them here would propagate to
+// master when this PR merges, silently dropping them from the next release).
+const { stdout: releaseNotesList } = await exec(
+ `git ls-tree -r --name-only origin/${releaseBranch} -- upcoming-release-notes`,
+);
+const releaseNoteFiles = releaseNotesList
+ .split('\n')
+ .filter(Boolean)
+ .map(path => path.replace(/^upcoming-release-notes\//, ''));
+
const { notesByCategory, files } = await parseReleaseNotes(
'upcoming-release-notes',
owner,
repo,
`origin/${baseBranch}`,
+ releaseNoteFiles,
);
const categorizedNotes = formatNotes(notesByCategory);
diff --git a/packages/ci-actions/src/release-notes/util.mjs b/packages/ci-actions/src/release-notes/util.mjs
index e03135c3e8..e4e29789a1 100644
--- a/packages/ci-actions/src/release-notes/util.mjs
+++ b/packages/ci-actions/src/release-notes/util.mjs
@@ -21,9 +21,13 @@ export const categoryOrder = [
'Maintenance',
];
-export async function parseReleaseNotes(dir, owner, repo, historyRef) {
+export async function parseReleaseNotes(dir, owner, repo, historyRef, only) {
+ const allowed = only == null ? null : new Set(only);
const files = (await fs.readdir(dir)).filter(
- f => f.endsWith('.md') && f !== 'README.md',
+ f =>
+ f.endsWith('.md') &&
+ f !== 'README.md' &&
+ (allowed == null || allowed.has(f)),
);
const notes = files.map(async name => {
const content = await fs.readFile(join(dir, name), 'utf-8');
diff --git a/upcoming-release-notes/release-cut-prs.md b/upcoming-release-notes/release-cut-prs.md
new file mode 100644
index 0000000000..60773ba294
--- /dev/null
+++ b/upcoming-release-notes/release-cut-prs.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [matt-fidd]
+---
+
+Rework the release cut automation to open PRs into the release branch instead of pushing directly, avoid monthly sync merge conflicts, and stop hotfix changelogs re-listing already-shipped notes