Skip to content

Commit 3d6b645

Browse files
committed
Split CI into readme-check and render jobs, each post a PR comment on failure
1 parent 19f5a31 commit 3d6b645

File tree

1 file changed

+69
-9
lines changed

1 file changed

+69
-9
lines changed

.github/workflows/ci.yml

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,80 @@ on:
55
branches: [master]
66

77
jobs:
8-
build:
8+
readme-check:
99
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: write
12+
contents: read
1013
steps:
1114
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
1217

13-
- name: Install Rust toolchain
14-
uses: dtolnay/rust-toolchain@stable
18+
- name: Check README.md was not edited directly
19+
id: readme
20+
run: |
21+
TRUSTED="mre jakubsacha"
22+
AUTHOR="${{ github.event.pull_request.user.login }}"
23+
for u in $TRUSTED; do
24+
if [ "$AUTHOR" = "$u" ]; then
25+
echo "trusted=true" >> "$GITHUB_OUTPUT"
26+
exit 0
27+
fi
28+
done
29+
if git diff --name-only origin/master...HEAD | grep -q "^README.md$"; then
30+
echo "modified=true" >> "$GITHUB_OUTPUT"
31+
fi
1532
16-
- name: Prevent file change
17-
uses: xalvarez/prevent-file-change-action@v1
33+
- name: Comment and fail on direct README edit
34+
if: steps.readme.outputs.modified == 'true'
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
PR: ${{ github.event.pull_request.number }}
38+
REPO: ${{ github.repository }}
39+
run: |
40+
gh api "repos/$REPO/issues/$PR/comments" \
41+
-f body="README.md was edited directly. The README is generated from the YAML files in \`data/tools/\`. Please add or edit the corresponding file in \`data/tools/\` instead and do not touch README.md." \
42+
--silent
43+
echo "README.md must not be edited directly." >&2
44+
exit 1
45+
46+
render:
47+
runs-on: ubuntu-latest
48+
permissions:
49+
pull-requests: write
50+
contents: read
51+
steps:
52+
- uses: actions/checkout@v4
1853
with:
19-
githubToken: ${{ secrets.GITHUB_TOKEN }}
20-
pattern: README.md
21-
trustedAuthors: mre, jakubsacha
54+
fetch-depth: 0
55+
56+
- name: Install Rust toolchain
57+
uses: dtolnay/rust-toolchain@stable
2258

2359
- name: Render list
24-
run: make render-skip-deprecated
60+
id: render
61+
run: |
62+
make render-skip-deprecated 2>&1 | tee /tmp/render-output.txt
63+
exit ${PIPESTATUS[0]}
64+
65+
- name: Comment render error on failure
66+
if: failure() && steps.render.outcome == 'failure'
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
PR: ${{ github.event.pull_request.number }}
70+
REPO: ${{ github.repository }}
71+
run: |
72+
OUTPUT=$(grep -E "^Error" /tmp/render-output.txt | head -20)
73+
{
74+
echo "The render step failed with the following error:"
75+
echo ""
76+
echo '```'
77+
echo "$OUTPUT"
78+
echo '```'
79+
echo ""
80+
echo "Please check your YAML file in \`data/tools/\` against the format used by other tools in that directory."
81+
} > /tmp/render-comment.txt
82+
gh api "repos/$REPO/issues/$PR/comments" \
83+
-f body=@/tmp/render-comment.txt \
84+
--silent

0 commit comments

Comments
 (0)