From 836bb6006cee98d43ef46f779855678882a8e01c Mon Sep 17 00:00:00 2001 From: Esben Sparre Andreasen Date: Thu, 19 Oct 2023 12:05:29 +0200 Subject: [PATCH 1/2] improve env var usage in check-change-note.yml --- .github/workflows/check-change-note.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check-change-note.yml b/.github/workflows/check-change-note.yml index 3967c0ec9215..b886704555a2 100644 --- a/.github/workflows/check-change-note.yml +++ b/.github/workflows/check-change-note.yml @@ -15,20 +15,22 @@ on: jobs: check-change-note: + env: + REPO: ${{ github.repository }} + PULL_REQUEST_NUMBER: ${{ github.event.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} runs-on: ubuntu-latest steps: + - name: Fail if no change note found. To fix, either add one, or add the `no-change-note-required` label. if: | github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'no-change-note-required') - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh api 'repos/${{github.repository}}/pulls/${{github.event.number}}/files' --paginate --jq 'any(.[].filename ; test("/change-notes/.*[.]md$"))' | + gh api "repos/$REPO/pulls/$PULL_REQUEST_NUMBER/files" --paginate --jq 'any(.[].filename ; test("/change-notes/.*[.]md$"))' | grep true -c + - 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 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - 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$"))' | + 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$"))' | grep true -c From 2c99e2f3d53924aeb717bb578f151398a4dcd8c9 Mon Sep 17 00:00:00 2001 From: Esben Sparre Andreasen Date: Thu, 19 Oct 2023 12:16:27 +0200 Subject: [PATCH 2/2] improve change note file name checks --- .github/workflows/check-change-note.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-change-note.yml b/.github/workflows/check-change-note.yml index b886704555a2..f80864ed0199 100644 --- a/.github/workflows/check-change-note.yml +++ b/.github/workflows/check-change-note.yml @@ -27,10 +27,22 @@ jobs: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'no-change-note-required') run: | - gh api "repos/$REPO/pulls/$PULL_REQUEST_NUMBER/files" --paginate --jq 'any(.[].filename ; test("/change-notes/.*[.]md$"))' | - grep true -c + change_note_files=$(gh api "repos/$REPO/pulls/$PULL_REQUEST_NUMBER/files" --paginate --jq '.[].filename | select(test("/change-notes/.*[.]md$"))') + + if [ -z "$change_note_files" ]; then + echo "No change note found. Either add one, or add the 'no-change-note-required' label." + exit 1 + fi + + echo "Change notes found:" + echo "$change_note_files" - 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 run: | - 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$"))' | - grep true -c + 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)') + + if [ -n "$bad_change_note_file_names" ]; then + echo "The following change note file names are invalid:" + echo "$bad_change_note_file_names" + exit 1 + fi