From 90321f499896c7b215442fb3503abdbb7ba47bce Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Mon, 11 Jan 2021 21:52:07 +0100 Subject: [PATCH 01/12] Add workflow to check Changelog entry. --- .github/workflows/check_changelog.yml | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/check_changelog.yml diff --git a/.github/workflows/check_changelog.yml b/.github/workflows/check_changelog.yml new file mode 100644 index 0000000000000..f590348fe03f3 --- /dev/null +++ b/.github/workflows/check_changelog.yml @@ -0,0 +1,29 @@ +name: Check Changelog + +on: + pull_request: + +jobs: + check: + runs-on: ubuntu-latest + if: ${{ contains(github.event.pull_request.labels.*.name, 'no-changelog') == 0 }} + steps: + - name: Get PR number and author + run: | + echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV + echo "PR_AUTHOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV + - uses: actions/checkout@v2 + with: + fetch-depth: '0' + - name: Check the changelog + run: | + set -xe + result=`grep "$PR_NUMBER" ./doc/whats_new/v*.rst | grep "$PR_AUTHOR"` + if [ "$result" != "" ] + then + echo $result + else + then + echo "Changelog entry is missing." + exit 1 + fi From 09fb7d95ded7ae37c57bf49d1f22d3440656aa44 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Tue, 12 Jan 2021 16:17:57 +0100 Subject: [PATCH 02/12] Check changelog only if tests have been modified. Remove grep command. --- .github/workflows/check_changelog.yml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/check_changelog.yml b/.github/workflows/check_changelog.yml index f590348fe03f3..de4c194bbcd82 100644 --- a/.github/workflows/check_changelog.yml +++ b/.github/workflows/check_changelog.yml @@ -8,22 +8,24 @@ jobs: runs-on: ubuntu-latest if: ${{ contains(github.event.pull_request.labels.*.name, 'no-changelog') == 0 }} steps: - - name: Get PR number and author + - name: Get PR number run: | echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV - echo "PR_AUTHOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV - uses: actions/checkout@v2 with: fetch-depth: '0' - - name: Check the changelog + - name: Check the changelog only if tests have been modified run: | set -xe - result=`grep "$PR_NUMBER" ./doc/whats_new/v*.rst | grep "$PR_AUTHOR"` - if [ "$result" != "" ] + tests=$(git diff --name-only origin/master) + if [[ "$tests" =~ tests ]] then - echo $result - else - then - echo "Changelog entry is missing." - exit 1 + result=$(cat ./doc/whats_new/v*.rst) + if [[ "$result" =~ :pr:\`$PR_NUMBER\` ]] + then + echo "Changelog has been updated." + else + echo "Changelog entry is missing." + exit 1 + fi fi From 62a506861e9c16348764e5187da6749ac3402312 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Tue, 12 Jan 2021 17:13:06 +0100 Subject: [PATCH 03/12] More explicit comment and message Co-authored-by: Nicolas Hug --- .github/workflows/check_changelog.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check_changelog.yml b/.github/workflows/check_changelog.yml index de4c194bbcd82..99524298ccad7 100644 --- a/.github/workflows/check_changelog.yml +++ b/.github/workflows/check_changelog.yml @@ -1,5 +1,7 @@ name: Check Changelog - +# This check makes sure that the changelog is properly updated +# when a PR introduces a change in a test file. +# To bypass this check, label the PR with no-changelog. on: pull_request: @@ -25,7 +27,7 @@ jobs: then echo "Changelog has been updated." else - echo "Changelog entry is missing." + echo "Changelog entry is missing. If no changelog entry is required for this PR, label the PR with no-changelog to bypass this check." exit 1 fi fi From 0ff8125a03799ea34309257c68f9b39477f5f847 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Thu, 14 Jan 2021 13:46:16 +0100 Subject: [PATCH 04/12] Define variables. --- .github/workflows/check_changelog.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check_changelog.yml b/.github/workflows/check_changelog.yml index 99524298ccad7..f9c83d5bab269 100644 --- a/.github/workflows/check_changelog.yml +++ b/.github/workflows/check_changelog.yml @@ -1,18 +1,19 @@ name: Check Changelog # This check makes sure that the changelog is properly updated # when a PR introduces a change in a test file. -# To bypass this check, label the PR with no-changelog. +# To bypass this check, label the PR with no-changelog. on: pull_request: jobs: check: runs-on: ubuntu-latest - if: ${{ contains(github.event.pull_request.labels.*.name, 'no-changelog') == 0 }} + env: + LABEL_LIST: ${{ github.event.pull_request.labels.*.name }} + PR_NUMBER: ${{ github.event.pull_request.number }} + + if: ${{ contains($LABEL_LIST, 'no-changelog') == 0 }} || steps: - - name: Get PR number - run: | - echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV - uses: actions/checkout@v2 with: fetch-depth: '0' From 5a7c871e521704eb05fca192a33c04397be58122 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Fri, 15 Jan 2021 15:04:56 +0100 Subject: [PATCH 05/12] Add check for the milestone. Change file name. Group variable definition. --- .../{check_changelog.yml => check-changelog.yml} | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) rename .github/workflows/{check_changelog.yml => check-changelog.yml} (56%) diff --git a/.github/workflows/check_changelog.yml b/.github/workflows/check-changelog.yml similarity index 56% rename from .github/workflows/check_changelog.yml rename to .github/workflows/check-changelog.yml index f9c83d5bab269..5fa511e6280fe 100644 --- a/.github/workflows/check_changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -1,7 +1,7 @@ name: Check Changelog # This check makes sure that the changelog is properly updated # when a PR introduces a change in a test file. -# To bypass this check, label the PR with no-changelog. +# To bypass this check, label the PR with "No Changelog Needed". on: pull_request: @@ -11,8 +11,9 @@ jobs: env: LABEL_LIST: ${{ github.event.pull_request.labels.*.name }} PR_NUMBER: ${{ github.event.pull_request.number }} + MILESTONE_TITLE: ${{ github.event.pull_request.milestone.title }} - if: ${{ contains($LABEL_LIST, 'no-changelog') == 0 }} || + if: ${{ contains($LABEL_LIST, 'No Changelog Needed') == 0 }} steps: - uses: actions/checkout@v2 with: @@ -27,8 +28,16 @@ jobs: if [[ "$result" =~ :pr:\`$PR_NUMBER\` ]] then echo "Changelog has been updated." + check_mlstn=$(cat ./doc/whats_new/v${MILESTONE_TITLE:0:4}.rst) + if [[ "$check_mlstn" =~ :pr:\`$PR_NUMBER\` ]] + then + echo "Changelog and milestone correspond." + else + echo "Changelog and milestone do not correspond. Please move the changelog description or change the milestone." + exit 1 + fi else - echo "Changelog entry is missing. If no changelog entry is required for this PR, label the PR with no-changelog to bypass this check." + echo "Changelog entry is missing. If no changelog entry is required for this PR, label the PR with 'No Changelog Needed' to bypass this check." exit 1 fi fi From be40e43c8b9529178e620d49e82e7b7e4f42e0c0 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Fri, 15 Jan 2021 15:11:24 +0100 Subject: [PATCH 06/12] Revert variable definition. --- .github/workflows/check-changelog.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml index 5fa511e6280fe..94f6965191ef3 100644 --- a/.github/workflows/check-changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -8,13 +8,12 @@ on: jobs: check: runs-on: ubuntu-latest - env: - LABEL_LIST: ${{ github.event.pull_request.labels.*.name }} - PR_NUMBER: ${{ github.event.pull_request.number }} - MILESTONE_TITLE: ${{ github.event.pull_request.milestone.title }} - - if: ${{ contains($LABEL_LIST, 'No Changelog Needed') == 0 }} + if: ${{ contains(contains(github.event.pull_request.labels.*.name, 'No Changelog Needed') == 0 }} steps: + - name: Get PR number and milestone + run: | + echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV + echo "MILESTONE_TITLE=${{ github.event.pull_request.milestone.title }} >> $GITHUB_ENV - uses: actions/checkout@v2 with: fetch-depth: '0' From 4ae42a8e5db14121bde7c270398d69eab0a7fce4 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Fri, 15 Jan 2021 15:17:52 +0100 Subject: [PATCH 07/12] Fix syntax error. --- .github/workflows/check-changelog.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml index 94f6965191ef3..b3d6c32955523 100644 --- a/.github/workflows/check-changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -8,7 +8,7 @@ on: jobs: check: runs-on: ubuntu-latest - if: ${{ contains(contains(github.event.pull_request.labels.*.name, 'No Changelog Needed') == 0 }} + if: ${{ contains(github.event.pull_request.labels.*.name, 'No Changelog Needed') == 0 }} steps: - name: Get PR number and milestone run: | From dd4c1aac1a0b0adabb279949523fa471694e8e5b Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Fri, 15 Jan 2021 15:29:26 +0100 Subject: [PATCH 08/12] Check the existence of the milestone. Add comments. --- .github/workflows/check-changelog.yml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml index b3d6c32955523..d43348af408e4 100644 --- a/.github/workflows/check-changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -17,26 +17,33 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: '0' - - name: Check the changelog only if tests have been modified + - name: Check the changelog run: | set -xe tests=$(git diff --name-only origin/master) + # Changelog should be updated only if tests have been modified if [[ "$tests" =~ tests ]] then result=$(cat ./doc/whats_new/v*.rst) if [[ "$result" =~ :pr:\`$PR_NUMBER\` ]] then echo "Changelog has been updated." - check_mlstn=$(cat ./doc/whats_new/v${MILESTONE_TITLE:0:4}.rst) - if [[ "$check_mlstn" =~ :pr:\`$PR_NUMBER\` ]] + # If the pull request is milestoned check the correspondent changelog + if exist -f ./doc/whats_new/v${MILESTONE_TITLE:0:4}.rst then - echo "Changelog and milestone correspond." - else - echo "Changelog and milestone do not correspond. Please move the changelog description or change the milestone." - exit 1 + check_mlstn=$(cat ./doc/whats_new/v${MILESTONE_TITLE:0:4}.rst) + if [[ "$check_mlstn" =~ :pr:\`$PR_NUMBER\` ]] + then + echo "Changelog and milestone correspond." + else + echo "Changelog and milestone do not correspond. + echo "Move the changelog description or change the milestone." + exit 1 + fi fi else - echo "Changelog entry is missing. If no changelog entry is required for this PR, label the PR with 'No Changelog Needed' to bypass this check." + echo "Changelog entry is missing. If no changelog entry is required for this PR, + echo "label the PR with 'No Changelog Needed' to bypass this check." exit 1 fi fi From 4dcd9df8107f5c744cb836aa672bad72ff776612 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Fri, 15 Jan 2021 15:42:42 +0100 Subject: [PATCH 09/12] Rename variables. --- .github/workflows/check-changelog.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml index d43348af408e4..14aa640543272 100644 --- a/.github/workflows/check-changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -20,19 +20,19 @@ jobs: - name: Check the changelog run: | set -xe - tests=$(git diff --name-only origin/master) + changed_files=$(git diff --name-only origin/master) # Changelog should be updated only if tests have been modified - if [[ "$tests" =~ tests ]] + if [[ "$changed_files" =~ tests ]] then - result=$(cat ./doc/whats_new/v*.rst) - if [[ "$result" =~ :pr:\`$PR_NUMBER\` ]] + all_changelogs=$(cat ./doc/whats_new/v*.rst) + if [[ "$all_changelogs" =~ :pr:\`$PR_NUMBER\` ]] then echo "Changelog has been updated." # If the pull request is milestoned check the correspondent changelog if exist -f ./doc/whats_new/v${MILESTONE_TITLE:0:4}.rst then - check_mlstn=$(cat ./doc/whats_new/v${MILESTONE_TITLE:0:4}.rst) - if [[ "$check_mlstn" =~ :pr:\`$PR_NUMBER\` ]] + expected_changelog=$(cat ./doc/whats_new/v${MILESTONE_TITLE:0:4}.rst) + if [[ "$expected_changelog" =~ :pr:\`$PR_NUMBER\` ]] then echo "Changelog and milestone correspond." else From 145ed05540c2e9baf1a85e6d26527cc1835b96b6 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Fri, 15 Jan 2021 16:51:13 +0100 Subject: [PATCH 10/12] Make the error message more informative. --- .github/workflows/check-changelog.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml index 14aa640543272..60f5f088816be 100644 --- a/.github/workflows/check-changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -36,13 +36,16 @@ jobs: then echo "Changelog and milestone correspond." else - echo "Changelog and milestone do not correspond. - echo "Move the changelog description or change the milestone." + echo "Changelog and milestone do not correspond." + echo "If you see this error and there is already a changelog entry then make sure that" + echo "the tagged milestone for the PR (if any) and the changelog name properly match." exit 1 fi fi else - echo "Changelog entry is missing. If no changelog entry is required for this PR, + echo "Changelog entry is missing." + echo "If you see this error and there is already a changelog entry then make sure that" + echo "the PR number is correct. If no changelog entry is required for this PR," echo "label the PR with 'No Changelog Needed' to bypass this check." exit 1 fi From 7d013bb7b0e49eb96fd60562519210b2e8913e45 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Fri, 15 Jan 2021 17:50:39 +0100 Subject: [PATCH 11/12] Clarify the error message. --- .github/workflows/check-changelog.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml index 60f5f088816be..9c8e1e999e3ae 100644 --- a/.github/workflows/check-changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -13,7 +13,7 @@ jobs: - name: Get PR number and milestone run: | echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV - echo "MILESTONE_TITLE=${{ github.event.pull_request.milestone.title }} >> $GITHUB_ENV + echo "TAGGED_MILESTONE=${{ github.event.pull_request.milestone.title }} >> $GITHUB_ENV - uses: actions/checkout@v2 with: fetch-depth: '0' @@ -29,16 +29,16 @@ jobs: then echo "Changelog has been updated." # If the pull request is milestoned check the correspondent changelog - if exist -f ./doc/whats_new/v${MILESTONE_TITLE:0:4}.rst + if exist -f ./doc/whats_new/v${TAGGED_MILESTONE:0:4}.rst then - expected_changelog=$(cat ./doc/whats_new/v${MILESTONE_TITLE:0:4}.rst) + expected_changelog=$(cat ./doc/whats_new/v${TAGGED_MILESTONE:0:4}.rst) if [[ "$expected_changelog" =~ :pr:\`$PR_NUMBER\` ]] then echo "Changelog and milestone correspond." else echo "Changelog and milestone do not correspond." - echo "If you see this error and there is already a changelog entry then make sure that" - echo "the tagged milestone for the PR (if any) and the changelog name properly match." + echo "If you see this error make sure that the tagged milestone for the PR" + echo "and the changelog name properly match." exit 1 fi fi From 6526b88c3a0a8dda0a4b52a275f837b55c704f28 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Fri, 15 Jan 2021 18:14:35 +0100 Subject: [PATCH 12/12] Exit early if tests are not modified. --- .github/workflows/check-changelog.yml | 46 ++++++++++++++------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml index 9c8e1e999e3ae..7d954c530cff8 100644 --- a/.github/workflows/check-changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -22,31 +22,33 @@ jobs: set -xe changed_files=$(git diff --name-only origin/master) # Changelog should be updated only if tests have been modified - if [[ "$changed_files" =~ tests ]] + if [[ ! "$changed_files" =~ tests ]] then - all_changelogs=$(cat ./doc/whats_new/v*.rst) - if [[ "$all_changelogs" =~ :pr:\`$PR_NUMBER\` ]] + exit 0 + fi + all_changelogs=$(cat ./doc/whats_new/v*.rst) + if [[ "$all_changelogs" =~ :pr:\`$PR_NUMBER\` ]] + then + echo "Changelog has been updated." + # If the pull request is milestoned check the correspondent changelog + if exist -f ./doc/whats_new/v${TAGGED_MILESTONE:0:4}.rst then - echo "Changelog has been updated." - # If the pull request is milestoned check the correspondent changelog - if exist -f ./doc/whats_new/v${TAGGED_MILESTONE:0:4}.rst + expected_changelog=$(cat ./doc/whats_new/v${TAGGED_MILESTONE:0:4}.rst) + if [[ "$expected_changelog" =~ :pr:\`$PR_NUMBER\` ]] then - expected_changelog=$(cat ./doc/whats_new/v${TAGGED_MILESTONE:0:4}.rst) - if [[ "$expected_changelog" =~ :pr:\`$PR_NUMBER\` ]] - then - echo "Changelog and milestone correspond." - else - echo "Changelog and milestone do not correspond." - echo "If you see this error make sure that the tagged milestone for the PR" - echo "and the changelog name properly match." - exit 1 - fi + echo "Changelog and milestone correspond." + else + echo "Changelog and milestone do not correspond." + echo "If you see this error make sure that the tagged milestone for the PR" + echo "and the changelog name properly match." + exit 1 fi - else - echo "Changelog entry is missing." - echo "If you see this error and there is already a changelog entry then make sure that" - echo "the PR number is correct. If no changelog entry is required for this PR," - echo "label the PR with 'No Changelog Needed' to bypass this check." - exit 1 fi + else + echo "Changelog entry is missing." + echo "If you see this error and there is already a changelog entry then make sure that" + echo "the PR number is correct. If no changelog entry is required for this PR," + echo "label the PR with 'No Changelog Needed' to bypass this check." + exit 1 fi +