From 1cdf60c9b0ab1a59c73833c19d462a92b0220d83 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 10 Jan 2025 11:04:08 +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 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/clippy_pr.yml b/.github/workflows/clippy_pr.yml index 80523d91f4fc..c24de1e57c79 100644 --- a/.github/workflows/clippy_pr.yml +++ b/.github/workflows/clippy_pr.yml @@ -17,8 +17,39 @@ concurrency: cancel-in-progress: true jobs: + changelog: + runs-on: ubuntu-latest + + 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: | + set -x + 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'])") + cl_line=$(grep "^changelog:\s*\S" <<< "$body") || { + echo "ERROR: PR body must contain 'changelog: ...'. Please modify the PR " \ + "message and push (or force-push) the PR commits to trigger a new check." + exit 1 + } + output=$(sed "s/^changelog:\s*//" <<< "$cl_line") + 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: