Skip to content

Commit c33759e

Browse files
authored
ci: comment on PRs for helpful fixes (#7451)
A new action to comment on PRs that come from forks help contributors fix their errors
1 parent f8b4df0 commit c33759e

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: "PR Comment on Failure"
2+
description: "Comments on PRs from forks when checks fail"
3+
inputs:
4+
check-name:
5+
description: "The name of the check that failed"
6+
required: true
7+
command:
8+
description: "The command that contributors should run"
9+
required: true
10+
github-token:
11+
description: "GitHub token for commenting"
12+
required: true
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Comment on PR
18+
if: github.event.pull_request.head.repo.fork == true
19+
uses: actions/github-script@v7
20+
with:
21+
github-token: ${{ inputs.github-token }}
22+
script: |
23+
const checkName = '${{ inputs.check-name }}';
24+
const command = '${{ inputs.command }}';
25+
26+
const body = `👋 It looks like the **${checkName}** check failed.
27+
28+
To fix this locally, please run:
29+
30+
\`\`\`bash
31+
${command}
32+
\`\`\`
33+
`;
34+
35+
// Check if we already commented
36+
const { data: comments } = await github.rest.issues.listComments({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
issue_number: context.issue.number,
40+
});
41+
42+
const botComment = comments.find(comment =>
43+
comment.user.type === 'Bot' &&
44+
comment.body.includes(checkName)
45+
);
46+
47+
if (botComment) {
48+
// Update existing comment
49+
await github.rest.issues.updateComment({
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
comment_id: botComment.id,
53+
body: body
54+
});
55+
} else {
56+
// Create new comment
57+
await github.rest.issues.createComment({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
issue_number: context.issue.number,
61+
body: body
62+
});
63+
}

.github/workflows/test_be.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
permissions:
99
contents: read
10+
pull-requests: write
1011

1112
env:
1213
MARIMO_SKIP_UPDATE_CHECK: 1
@@ -46,8 +47,17 @@ jobs:
4647
uses: pypa/hatch@install
4748

4849
- name: 📚 Build docs
50+
id: docs
4951
run: hatch run docs:build --strict
5052

53+
- name: Comment on docs failure
54+
if: failure() && steps.docs.outcome == 'failure'
55+
uses: ./.github/actions/pr-comment-on-failure
56+
with:
57+
check-name: "docs build"
58+
command: "hatch run docs:build --strict"
59+
github-token: ${{ secrets.GITHUB_TOKEN }}
60+
5161
test_check:
5262
needs: changes
5363
if: ${{ needs.changes.outputs.backend == 'true' }}
@@ -64,11 +74,29 @@ jobs:
6474
uses: pypa/hatch@install
6575

6676
- name: 🧹 Lint
77+
id: lint
6778
run: hatch run lint
6879

6980
- name: 🔍 Typecheck
81+
id: typecheck
7082
run: hatch run typecheck:check
7183

84+
- name: Comment on lint failure
85+
if: failure() && steps.lint.outcome == 'failure'
86+
uses: ./.github/actions/pr-comment-on-failure
87+
with:
88+
check-name: "lint"
89+
command: "hatch run lint"
90+
github-token: ${{ secrets.GITHUB_TOKEN }}
91+
92+
- name: Comment on typecheck failure
93+
if: failure() && steps.typecheck.outcome == 'failure'
94+
uses: ./.github/actions/pr-comment-on-failure
95+
with:
96+
check-name: "typecheck"
97+
command: "hatch run typecheck:check"
98+
github-token: ${{ secrets.GITHUB_TOKEN }}
99+
72100
# For PRs, we only run the tests for the changed files.
73101
# If there is a `test-all` label, we run the tests across unchanged files as well.
74102
test_python:

.github/workflows/test_fe.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Test FE
22
permissions:
33
contents: read
4+
pull-requests: write
45

56
on:
67
push:
@@ -51,11 +52,29 @@ jobs:
5152

5253
- name: 📦 pnpm dedupe
5354
if: github.event_name == 'pull_request'
55+
id: dedupe
5456
run: pnpm dedupe --check
5557

5658
- name: 🧹 Lint
59+
id: lint
5760
run: pnpm turbo lint
5861

62+
- name: Comment on lint failure
63+
if: failure() && steps.lint.outcome == 'failure'
64+
uses: ./.github/actions/pr-comment-on-failure
65+
with:
66+
check-name: "lint"
67+
command: "pnpm turbo lint"
68+
github-token: ${{ secrets.GITHUB_TOKEN }}
69+
70+
- name: Comment on dedupe failure
71+
if: failure() && steps.dedupe.outcome == 'failure'
72+
uses: ./.github/actions/pr-comment-on-failure
73+
with:
74+
check-name: "dedupe"
75+
command: "pnpm dedupe"
76+
github-token: ${{ secrets.GITHUB_TOKEN }}
77+
5978
test_frontend:
6079
needs: changes
6180
if: ${{ needs.changes.outputs.frontend == 'true' }}
@@ -80,11 +99,29 @@ jobs:
8099
uses: ./.github/actions/install
81100

82101
- name: 🔎 Type check
102+
id: typecheck
83103
run: pnpm turbo typecheck
84104

85105
- name: 🧪 Test
106+
id: test
86107
run: pnpm turbo test
87108

109+
- name: Comment on typecheck failure
110+
if: failure() && steps.typecheck.outcome == 'failure'
111+
uses: ./.github/actions/pr-comment-on-failure
112+
with:
113+
check-name: "typecheck"
114+
command: "pnpm turbo typecheck"
115+
github-token: ${{ secrets.GITHUB_TOKEN }}
116+
117+
- name: Comment on test failure
118+
if: failure() && steps.test.outcome == 'failure'
119+
uses: ./.github/actions/pr-comment-on-failure
120+
with:
121+
check-name: "test"
122+
command: "pnpm turbo test"
123+
github-token: ${{ secrets.GITHUB_TOKEN }}
124+
88125
build_frontend:
89126
needs: changes
90127
if: ${{ needs.changes.outputs.frontend == 'true' }}
@@ -120,6 +157,7 @@ jobs:
120157
fi
121158
122159
- name: 📦 Build
160+
id: build
123161
run: pnpm turbo build
124162
env:
125163
NODE_ENV: production
@@ -133,3 +171,11 @@ jobs:
133171
npm version 0.0.0 --no-git-tag-version
134172
pnpm turbo build:islands
135173
./islands/validate.sh
174+
175+
- name: Comment on build failure
176+
if: failure() && steps.build.outcome == 'failure'
177+
uses: ./.github/actions/pr-comment-on-failure
178+
with:
179+
check-name: "build"
180+
command: "pnpm turbo build"
181+
github-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)