From f631eb1a2a74850076cdbedf193d3a30de12bcba Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 10 Jan 2025 11:31:16 +0100 Subject: [PATCH] CI: check the presence of the changelog line in each pull request Checking it only in the merge queue leads to deferred failures once the decision to merge has been taken already. --- .github/workflows/clippy_pr.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/.github/workflows/clippy_pr.yml b/.github/workflows/clippy_pr.yml index 80523d91f4fc..270a3b68a634 100644 --- a/.github/workflows/clippy_pr.yml +++ b/.github/workflows/clippy_pr.yml @@ -17,8 +17,41 @@ concurrency: cancel-in-progress: true jobs: + changelog: + runs-on: ubuntu-latest + + defaults: + run: + shell: bash + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + # Unsetting this would make so that any malicious package could get our Github Token + persist-credentials: false + + # Run + - name: Check Changelog + run: | + body=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR_NUMBER" | \ + python -c "import sys, json; print(json.load(sys.stdin)['body'])") + output=$(grep "^changelog:\s*\S" <<< "$body" | sed "s/changelog:\s*//g") || { + echo "ERROR: pull request message must contain 'changelog: ...'. Add it " \ + "and push (or force-push) the pull request to trigger a new check." + exit 1 + } + if [[ "$output" = "none" ]]; then + echo "WARNING: changelog is 'none'" + else + echo "changelog: $output" + fi + env: + PYTHONIOENCODING: 'utf-8' + PR_NUMBER: '${{ github.event.number }}' base: # NOTE: If you modify this job, make sure you copy the changes to clippy_mq.yml + needs: changelog runs-on: ubuntu-latest steps: