Skip to content

Commit a16b43a

Browse files
committed
Try to upload codedov reports even if forked branches
Forks won't have access to the token. Rather than allowing tokenless uploads for everyone, we run it in a different workflow which hopefully does have the token.
1 parent 35647b5 commit a16b43a

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

.github/workflows/codecov.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Upload coverage to Codecov
3+
4+
on:
5+
workflow_run:
6+
workflows: ["test"]
7+
types: [completed]
8+
9+
permissions: {}
10+
11+
jobs:
12+
upload:
13+
runs-on: ubuntu-24.04
14+
if: github.event.workflow_run.conclusion == 'success'
15+
permissions: {}
16+
steps:
17+
- name: Download coverage artifacts
18+
uses: actions/download-artifact@v4
19+
with:
20+
run-id: ${{ github.event.workflow_run.id }}
21+
github-token: ${{ github.token }}
22+
path: coverage
23+
- name: Upload to Codecov
24+
uses: codecov/codecov-action@v5
25+
with:
26+
fail_ci_if_error: true
27+
files: >-
28+
coverage/playwright-coverage/codecov.json,
29+
coverage/test-coverage/codecov.json
30+
token: ${{ secrets.CODECOV_TOKEN }}
31+
override_commit: ${{ github.event.workflow_run.head_sha }}
32+
override_pr: ${{ github.event.workflow_run.pull_requests[0].number }}

.github/workflows/test.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,23 @@ jobs:
107107
docker stop ${{ steps.start-container.outputs.container_id }}
108108
docker cp ${{ steps.start-container.outputs.container_id }}:/app/cover_db ./cover_db
109109
- name: Install Codecovbash
110-
if: secrets.CODECOV_TOKEN != ''
111110
uses: perl-actions/install-with-cpm@v1
112111
with:
113112
install: |
114113
Devel::Cover
115114
Devel::Cover::Report::Codecovbash
116115
sudo: true
117116
- name: Generate Codecov report
118-
if: secrets.CODECOV_TOKEN != ''
119117
run: cover -report codecovbash
118+
- name: Upload coverage artifact
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: playwright-coverage
122+
path: ./cover_db/codecov.json
120123
- uses: codecov/codecov-action@v5
121124
if: secrets.CODECOV_TOKEN != ''
122125
with:
123-
fail_ci_if_error: true
126+
fail_ci_if_error: false
124127
file: ./cover_db/codecov.json
125128
token: ${{ secrets.CODECOV_TOKEN }}
126129
test:
@@ -143,9 +146,7 @@ jobs:
143146
steps:
144147
- name: Enable coverage
145148
id: coverage
146-
if: >
147-
matrix.resolver == 'snapshot'
148-
&& secrets.CODECOV_TOKEN != ''
149+
if: matrix.resolver == 'snapshot'
149150
run: echo "enabled=1" >> "$GITHUB_OUTPUT"
150151
- uses: actions/checkout@v6
151152
- uses: actions/setup-node@v6
@@ -183,9 +184,15 @@ jobs:
183184
- name: Generate Codecov report
184185
if: steps.coverage.outputs.enabled
185186
run: cover -report codecovbash
186-
- uses: codecov/codecov-action@v5
187+
- name: Upload coverage artifact
187188
if: steps.coverage.outputs.enabled
189+
uses: actions/upload-artifact@v4
190+
with:
191+
name: test-coverage
192+
path: ./cover_db/codecov.json
193+
- uses: codecov/codecov-action@v5
194+
if: steps.coverage.outputs.enabled && secrets.CODECOV_TOKEN != ''
188195
with:
189-
fail_ci_if_error: true
196+
fail_ci_if_error: false
190197
file: ./cover_db/codecov.json
191198
token: ${{ secrets.CODECOV_TOKEN }}

0 commit comments

Comments
 (0)