|
| 1 | +name: Changelog Entry |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened, labeled, unlabeled] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + check: |
| 13 | + name: Check changelog entry |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 17 | + - name: Verify changelog entry or "no changelog" label |
| 18 | + env: |
| 19 | + GH_TOKEN: ${{ github.token }} |
| 20 | + REPO: ${{ github.repository }} |
| 21 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 22 | + LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }} |
| 23 | + run: | |
| 24 | + set -euo pipefail |
| 25 | + if echo "$LABELS" | jq -e 'index("no changelog")' > /dev/null; then |
| 26 | + echo "PR is labeled 'no changelog' - skipping check." |
| 27 | + exit 0 |
| 28 | + fi |
| 29 | + expected="^changelog\\.d/${PR_NUMBER}\\.[^/]+\\.md$" |
| 30 | + matching=$(gh api "repos/$REPO/pulls/$PR_NUMBER/files" --paginate \ |
| 31 | + | jq -r '.[] | select(.status == "added") | .filename' \ |
| 32 | + | grep -E "$expected" \ |
| 33 | + || true) |
| 34 | + if [ -z "$matching" ]; then |
| 35 | + echo "::error::PR must add a file named 'changelog.d/${PR_NUMBER}.<type>.md' or carry the 'no changelog' label." |
| 36 | + echo "See changelog.d/README.md for how to create an entry." |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + echo "Found new changelog entry/entries:" |
| 40 | + echo "$matching" |
| 41 | + echo "Checking changelog entries contain '<ISSUES_LIST>' placeholder on the first line..." |
| 42 | + missing=() |
| 43 | + while IFS= read -r file; do |
| 44 | + if ! head -n 1 "$file" | grep -qF '<ISSUES_LIST>'; then |
| 45 | + missing+=("$file") |
| 46 | + fi |
| 47 | + done <<< "$matching" |
| 48 | + if [ ${#missing[@]} -gt 0 ]; then |
| 49 | + echo "::error::The following changelog entries must contain '<ISSUES_LIST>' on the first line:" |
| 50 | + for f in "${missing[@]}"; do |
| 51 | + echo " - $f" |
| 52 | + done |
| 53 | + echo "See changelog.d/README.md for the expected format." |
| 54 | + exit 1 |
| 55 | + fi |
0 commit comments