Skip to content

Commit ec48ed2

Browse files
authored
fix(ci): changelog workflow must open a PR, not push to protected master (#68)
* fix(ci): deliver generated CHANGELOG.md via PR, not a direct push The direct `git push origin HEAD:master` was rejected by the repository ruleset ("Changes must be made through a pull request") — master is protected, so the CI bot cannot push to it. Replace the manual commit/push step with peter-evans/create-pull-request (SHA-pinned, v8.1.1): generation + `test -s` verification stay; the action pushes a fixed `automation/update-changelog` branch and opens or updates a PR, and no-ops when nothing changed. Add `pull-requests: write`. This makes the generated changelog comply with the same PR-only governance the rest of the repo uses, with no privileged bypass on the protected branch. * docs(ci): document why GITHUB_TOKEN is intentional for the changelog PR Copilot flagged that GITHUB_TOKEN-created PRs don't trigger CI/Sonar and "may be unmergeable if branch protection requires them". Verified the master ruleset: it requires only 1 approving review, NOT status checks. So the changelog PR is mergeable after a human review; running CI on a generated CHANGELOG.md is low value. Add an inline rationale so a PAT/App token isn't swapped in later (a managed elevated secret for no benefit). Comment-only.
1 parent 2867eb0 commit ec48ed2

1 file changed

Lines changed: 35 additions & 19 deletions

File tree

.github/workflows/changelog.yml

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ on:
1212
workflow_dispatch:
1313

1414
permissions:
15-
contents: write
15+
contents: write # push the automation branch
16+
pull-requests: write # open/update the changelog PR
1617

1718
concurrency:
1819
# Fixed group (not keyed by ref): release-tag and manual-dispatch runs
19-
# both push the default branch. Queue them (cancel-in-progress: false) so
20-
# each run finishes and persists its CHANGELOG.md instead of a later run
21-
# cancelling an in-flight one mid-push.
20+
# both target the same automation branch / PR. Queue them
21+
# (cancel-in-progress: false) so each run finishes and updates the PR
22+
# instead of a later run cancelling an in-flight one mid-update.
2223
group: changelog
2324
cancel-in-progress: false
2425

@@ -54,18 +55,33 @@ jobs:
5455
- name: Verify changelog was generated at the repo root
5556
run: test -s CHANGELOG.md
5657

57-
- name: Commit CHANGELOG.md if changed
58-
run: |
59-
# Stage first, then compare the index to HEAD. Plain
60-
# `git diff --quiet` ignores untracked files, so on the first
61-
# run (CHANGELOG.md brand-new) it falsely reported "no change"
62-
# and the file was never committed. --cached sees new files too.
63-
git add CHANGELOG.md
64-
if git diff --cached --quiet -- CHANGELOG.md; then
65-
echo "CHANGELOG.md unchanged — nothing to commit."
66-
exit 0
67-
fi
68-
git config user.name "xoops-ci"
69-
git config user.email "ci@xoops.org"
70-
git commit -m "docs(changelog): regenerate CHANGELOG.md [skip ci]"
71-
git push origin HEAD:${{ github.event.repository.default_branch }}
58+
- name: Open/update changelog pull request
59+
# master is protected (changes must go through a PR), so the bot
60+
# cannot push directly. Push a fixed automation branch and let this
61+
# action open or update the PR; it no-ops when nothing changed.
62+
# Pinned to a commit SHA (supply-chain hardening); comment tracks the tag.
63+
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
64+
with:
65+
# Intentional: GITHUB_TOKEN-created PRs do not trigger CI/Sonar
66+
# (GitHub recursion-prevention). That is fine here — master's
67+
# ruleset requires only 1 approving review, not status checks, and
68+
# CI on a generated CHANGELOG.md is low value. A maintainer reviews
69+
# and merges the changelog PR. Do not swap in a PAT/App token just
70+
# to run checks — it adds a managed elevated secret for no benefit.
71+
token: ${{ secrets.GITHUB_TOKEN }}
72+
base: ${{ github.event.repository.default_branch }}
73+
branch: automation/update-changelog
74+
delete-branch: true
75+
add-paths: CHANGELOG.md
76+
commit-message: "docs(changelog): regenerate CHANGELOG.md"
77+
committer: "xoops-ci <ci@xoops.org>"
78+
author: "xoops-ci <ci@xoops.org>"
79+
title: "docs(changelog): regenerate CHANGELOG.md"
80+
body: |
81+
Regenerated `CHANGELOG.md` from the commit history via
82+
`git-cliff` (config: `cliff.toml`).
83+
84+
Opened by the **Changelog** workflow — `master` is protected
85+
(changes must go through a PR), so the generated file is
86+
delivered this way instead of a direct push. Safe to merge
87+
once green; it only touches `CHANGELOG.md`.

0 commit comments

Comments
 (0)