Skip to content

Commit 0ca78f9

Browse files
committed
fix(ci): isolate coverage reporting
1 parent ec72526 commit 0ca78f9

1 file changed

Lines changed: 59 additions & 12 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
Test:
5757
runs-on: ubuntu-latest
5858
steps:
59-
- uses: actions-rust-lang/setup-rust-toolchain@v1
59+
- uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1
6060
- uses: actions/checkout@v5
6161
- name: Install dependencies
6262
run: |
@@ -69,7 +69,6 @@ jobs:
6969
runs-on: ubuntu-latest
7070
permissions:
7171
contents: read
72-
pull-requests: write
7372
env:
7473
# Branch coverage requires nightly (-Z coverage-options=branch); don't let
7574
# nightly lint churn fail the coverage report. Stable jobs enforce warnings.
@@ -116,19 +115,67 @@ jobs:
116115
f"({count('branches-covered')} / {count('branches-valid')}) |"
117116
)
118117
PY
119-
- name: Add coverage PR comment
120-
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2
121-
if: >-
122-
github.event_name == 'pull_request' &&
123-
github.actor != 'dependabot[bot]' &&
124-
github.event.pull_request.head.repo.full_name == github.repository
125-
with:
126-
header: code-coverage
127-
recreate: true
128-
path: code-coverage-results.md
129118
- name: Write coverage to job summary
130119
if: always()
131120
run: cat code-coverage-results.md >> "$GITHUB_STEP_SUMMARY"
121+
- name: Upload coverage summary
122+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
123+
with:
124+
name: coverage-summary
125+
path: code-coverage-results.md
126+
if-no-files-found: error
127+
Coverage-Report:
128+
if: >-
129+
github.event_name == 'pull_request' &&
130+
github.actor != 'dependabot[bot]' &&
131+
github.event.pull_request.head.repo.full_name == github.repository
132+
needs: Coverage
133+
runs-on: ubuntu-latest
134+
permissions:
135+
actions: read
136+
pull-requests: write
137+
steps:
138+
- name: Download coverage summary
139+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
140+
with:
141+
name: coverage-summary
142+
path: .
143+
- name: Add coverage PR comment
144+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
145+
with:
146+
script: |
147+
const fs = require('node:fs');
148+
const marker = '<!-- Sticky Pull Request Commentcode-coverage -->';
149+
const body = `${fs.readFileSync('code-coverage-results.md', 'utf8').trimEnd()}\n\n${marker}`;
150+
const { owner, repo } = context.repo;
151+
const issue_number = context.issue.number;
152+
const comments = await github.paginate(github.rest.issues.listComments, {
153+
owner,
154+
repo,
155+
issue_number,
156+
per_page: 100,
157+
});
158+
const existing = comments.find(
159+
(comment) =>
160+
comment.user.login === 'github-actions[bot]' &&
161+
comment.body.endsWith(marker),
162+
);
163+
164+
if (existing) {
165+
await github.rest.issues.updateComment({
166+
owner,
167+
repo,
168+
comment_id: existing.id,
169+
body,
170+
});
171+
} else {
172+
await github.rest.issues.createComment({
173+
owner,
174+
repo,
175+
issue_number,
176+
body,
177+
});
178+
}
132179
Format:
133180
runs-on: ubuntu-latest
134181
steps:

0 commit comments

Comments
 (0)