Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Changelog

# pull_request rather than pull_request_target: this needs the PR's changed-file list and no
# secrets, so the read-only token a fork PR receives is enough, and no PR content is checked
# out or executed. `labeled`/`unlabeled` are here so applying the skip label re-runs the check
# rather than leaving a stale failure behind.
on:
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
branches:
- master
- main

permissions:
contents: read
pull-requests: read

jobs:
changelog-entry:
name: Changelog entry
runs-on: ubuntu-latest
steps:
# The job runs unconditionally and decides inside the step, rather than skipping on an
# `if`: a skipped job reports as neither passing nor failing, and the reason a PR is
# exempt belongs in the log where the next reader will look for it.
- name: Require a changelog entry beside an engine change
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
# contains() matches an array element exactly, so a label carrying a comma or a
# name this one is a prefix of cannot be mistaken for it
SKIP_LABELLED: ${{ contains(github.event.pull_request.labels.*.name, 'no-changelog') }}
run: |
set -euo pipefail

if [ "${SKIP_LABELLED}" = "true" ]; then
echo "Labelled no-changelog; entry not required."
exit 0
fi

changed="$(gh api --paginate "repos/${REPOSITORY}/pulls/${PR_NUMBER}/files" --jq '.[].filename')"

if ! printf '%s\n' "${changed}" | grep -q '^src/smda/'; then
echo "No files under src/smda/ changed; entry not required."
exit 0
fi

if printf '%s\n' "${changed}" | grep -qx 'CHANGELOG.md'; then
echo "CHANGELOG.md touched beside the engine change."
exit 0
fi

echo "::error file=CHANGELOG.md::This PR changes src/smda/ but does not touch CHANGELOG.md. Add an entry under ## Unreleased describing what moved and what it cost, or apply the no-changelog label if the change genuinely needs no entry."
exit 1