-
Notifications
You must be signed in to change notification settings - Fork 5
51 lines (48 loc) · 2.17 KB
/
changelog-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# This workflow checks that there is either a 'pr/no-changelog' label
# applied to a PR or there is a .changelog/<pr number>.txt file associated
# with a PR for a changelog entry.
---
name: Changelog Check
on:
pull_request:
types:
- opened
- synchronize
- labeled
- unlabeled
branches:
- main
jobs:
changelog-check:
name: Changelog Check
# Ignore this check if there is a `pr/no-changelog` label
if: |
!contains(github.event.pull_request.labels.*.name, 'pr/no-changelog')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
- name: Check for changelog entry in diff
run: |
# check if there is a diff in the changelog directory
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")" -- .changelog/${{ github.event.pull_request.number }}.txt)
# If we do not find a file matching the PR # in .changelog/, we fail the check
if [ -z "$changelog_files" ]; then
echo "::error::Did not find a changelog entry named ${{ github.event.pull_request.number }}.txt in .changelog/"
echo "::debug::For reference, refer to the README."
exit 1
elif grep -q ':enhancement$' $changelog_files; then
# "Enhancement is not a valid type of changelog entry, but it's a common mistake.
echo "::error::Found invalid type (enhancement) in changelog - did you mean improvement?"
exit 1
elif grep -q ':bugs$' $changelog_files; then
echo "::error::Found invalid type (bugs) in changelog - did you mean bug?"
exit 1
elif ! grep -q '```release-note:' $changelog_files; then
# People often make changelog files like ```changelog:, which is incorrect.
echo "::error::Changelog file did not contain 'release-note' heading - check formatting."
exit 1
else
echo "::debug::Found changelog entry in PR!"
fi