Skip to content

Commit 1a4376b

Browse files
committed
CI: check the presence of the changelog line in every pull request
Checking it only in the merge queue leads to deferred failures once the decision to merge has been taken already.
1 parent 197d58d commit 1a4376b

File tree

2 files changed

+57
-33
lines changed

2 files changed

+57
-33
lines changed

.github/workflows/clippy_mq.yml

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,7 @@ defaults:
1515
shell: bash
1616

1717
jobs:
18-
changelog:
19-
runs-on: ubuntu-latest
20-
21-
steps:
22-
- name: Checkout
23-
uses: actions/checkout@v4
24-
with:
25-
ref: ${{ github.ref }}
26-
# Unsetting this would make so that any malicious package could get our Github Token
27-
persist-credentials: false
28-
29-
# Run
30-
- name: Check Changelog
31-
run: |
32-
MESSAGE=$(git log --format=%B -n 1)
33-
PR=$(echo "$MESSAGE" | grep -o "#[0-9]*" | head -1 | sed -e 's/^#//')
34-
body=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR" | \
35-
python -c "import sys, json; print(json.load(sys.stdin)['body'])")
36-
output=$(grep "^changelog:\s*\S" <<< "$body" | sed "s/changelog:\s*//g") || {
37-
echo "ERROR: PR body must contain 'changelog: ...'"
38-
exit 1
39-
}
40-
if [[ "$output" = "none" ]]; then
41-
echo "WARNING: changelog is 'none'"
42-
else
43-
echo "changelog: $output"
44-
fi
45-
env:
46-
PYTHONIOENCODING: 'utf-8'
4718
base:
48-
needs: changelog
4919
strategy:
5020
matrix:
5121
include:
@@ -119,7 +89,6 @@ jobs:
11989
OS: ${{ runner.os }}
12090

12191
metadata_collection:
122-
needs: changelog
12392
runs-on: ubuntu-latest
12493

12594
steps:
@@ -138,7 +107,6 @@ jobs:
138107
run: cargo collect-metadata
139108

140109
integration_build:
141-
needs: changelog
142110
runs-on: ubuntu-latest
143111

144112
steps:
@@ -228,7 +196,7 @@ jobs:
228196
INTEGRATION: ${{ matrix.integration }}
229197

230198
conclusion:
231-
needs: [ changelog, base, metadata_collection, integration_build, integration ]
199+
needs: [ base, metadata_collection, integration_build, integration ]
232200
# We need to ensure this job does *not* get skipped if its dependencies fail,
233201
# because a skipped job is considered a success by GitHub. So we have to
234202
# overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Clippy changelog check
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, edited]
6+
7+
concurrency:
8+
# For a given workflow, if we push to the same PR, cancel all previous builds on that PR.
9+
# If the push is not attached to a PR, we will cancel all builds on the same branch.
10+
group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}"
11+
cancel-in-progress: true
12+
13+
jobs:
14+
changelog:
15+
runs-on: ubuntu-latest
16+
17+
defaults:
18+
run:
19+
shell: bash
20+
21+
steps:
22+
# Run
23+
- name: Check Changelog
24+
run: |
25+
body=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR_NUMBER" | \
26+
python -c "import sys, json; print(json.load(sys.stdin)['body'])")
27+
output=$(grep "^changelog:\s*\S" <<< "$body" | sed "s/changelog:\s*//g") || {
28+
echo "ERROR: pull request message must contain 'changelog: ...'. Add it " \
29+
"and push (or force-push) the pull request to trigger a new check."
30+
exit 1
31+
}
32+
echo "changelog: $output"
33+
env:
34+
PYTHONIOENCODING: 'utf-8'
35+
PR_NUMBER: '${{ github.event.number }}'
36+
37+
# We need to have the "conclusion" job also on PR CI, to make it possible
38+
# to add PRs to a merge queue.
39+
conclusion_changelog:
40+
needs: [ changelog ]
41+
# We need to ensure this job does *not* get skipped if its dependencies fail,
42+
# because a skipped job is considered a success by GitHub. So we have to
43+
# overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
44+
# when the workflow is canceled manually.
45+
#
46+
# ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
47+
if: ${{ !cancelled() }}
48+
runs-on: ubuntu-latest
49+
steps:
50+
# Manually check the status of all dependencies. `if: failure()` does not work.
51+
- name: Conclusion
52+
run: |
53+
# Print the dependent jobs to see them in the CI log
54+
jq -C <<< '${{ toJson(needs) }}'
55+
# Check if all jobs that we depend on (in the needs array) were successful.
56+
jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'

0 commit comments

Comments
 (0)