Skip to content

Commit 2c99e2f

Browse files
committed
improve change note file name checks
1 parent 836bb60 commit 2c99e2f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,22 @@ jobs:
2727
github.event.pull_request.draft == false &&
2828
!contains(github.event.pull_request.labels.*.name, 'no-change-note-required')
2929
run: |
30-
gh api "repos/$REPO/pulls/$PULL_REQUEST_NUMBER/files" --paginate --jq 'any(.[].filename ; test("/change-notes/.*[.]md$"))' |
31-
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"
3239
3340
- 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
3441
run: |
35-
gh api "repos/$REPO/pulls/$PULL_REQUEST_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$"))' |
36-
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)