Skip to content

Commit

Permalink
CI: check the presence of the changelog line in each pull request
Browse files Browse the repository at this point in the history
Checking it only in the merge queue leads to deferred failures once the
decision to merge has been taken already.
  • Loading branch information
samueltardieu committed Jan 10, 2025
1 parent 197d58d commit 1cdf60c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/clippy_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1cdf60c

Please sign in to comment.