Skip to content

Commit 1b9b6ae

Browse files
authored
Merge pull request github#14542 from github/esbena/proper-check-change-note
Improve change note checking
2 parents a4ef183 + 2c99e2f commit 1b9b6ae

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

.github/workflows/check-change-note.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,34 @@ on:
1515

1616
jobs:
1717
check-change-note:
18+
env:
19+
REPO: ${{ github.repository }}
20+
PULL_REQUEST_NUMBER: ${{ github.event.number }}
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1822
runs-on: ubuntu-latest
1923
steps:
24+
2025
- name: Fail if no change note found. To fix, either add one, or add the `no-change-note-required` label.
2126
if: |
2227
github.event.pull_request.draft == false &&
2328
!contains(github.event.pull_request.labels.*.name, 'no-change-note-required')
24-
env:
25-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2629
run: |
27-
gh api 'repos/${{github.repository}}/pulls/${{github.event.number}}/files' --paginate --jq 'any(.[].filename ; test("/change-notes/.*[.]md$"))' |
28-
grep true -c
30+
change_note_files=$(gh api "repos/$REPO/pulls/$PULL_REQUEST_NUMBER/files" --paginate --jq '.[].filename | select(test("/change-notes/.*[.]md$"))')
31+
32+
if [ -z "$change_note_files" ]; then
33+
echo "No change note found. Either add one, or add the 'no-change-note-required' label."
34+
exit 1
35+
fi
36+
37+
echo "Change notes found:"
38+
echo "$change_note_files"
39+
2940
- name: Fail if the change note filename doesn't match the expected format. The file name must be of the form 'YYYY-MM-DD.md', 'YYYY-MM-DD-{title}.md', where '{title}' is arbitrary text, or released/x.y.z.md for released change-notes
30-
env:
31-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3241
run: |
33-
gh api 'repos/${{github.repository}}/pulls/${{github.event.number}}/files' --paginate --jq '[.[].filename | select(test("/change-notes/.*[.]md$"))] | all(test("/change-notes/[0-9]{4}-[0-9]{2}-[0-9]{2}.*[.]md$") or test("/change-notes/released/[0-9]*[.][0-9]*[.][0-9]*[.]md$"))' |
34-
grep true -c
42+
bad_change_note_file_names=$(gh api "repos/$REPO/pulls/$PULL_REQUEST_NUMBER/files" --paginate --jq '[.[].filename | select(test("/change-notes/.*[.]md$"))][] | select((test("/change-notes/[0-9]{4}-[0-9]{2}-[0-9]{2}.*[.]md$") or test("/change-notes/released/[0-9]*[.][0-9]*[.][0-9]*[.]md$")) | not)')
43+
44+
if [ -n "$bad_change_note_file_names" ]; then
45+
echo "The following change note file names are invalid:"
46+
echo "$bad_change_note_file_names"
47+
exit 1
48+
fi

0 commit comments

Comments
 (0)