Skip to content

Commit cccb006

Browse files
authored
CI: check the presence of the changelog line in every pull request (rust-lang#13976)
Checking it only in the merge queue leads to deferred failures once the decision to merge has been taken already. - [X] Testing first without changelog line - [x] Now that that has failed, adding the changelog line and force-pushing changelog: none
2 parents 7611dbb + 7639e82 commit cccb006

File tree

2 files changed

+58
-33
lines changed

2 files changed

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

.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

0 commit comments

Comments
 (0)