Skip to content

Commit ec71d95

Browse files
committed
split codecov uploading into separate repo
Some PRs run with lowered permissions that don't have access to secrets. This is generally good, but means they don't have a token to upload to Codecov. Split out the uploading to a separate workflow that is triggered by the completion of the test workflow.
1 parent 91ba572 commit ec71d95

File tree

2 files changed

+74
-16
lines changed

2 files changed

+74
-16
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: test
2+
name: Test
33
on:
44
push:
55
branches:
@@ -73,9 +73,6 @@ jobs:
7373
DEVEL_COVER_OPTIONS: '-ignore,^local/'
7474
steps:
7575
- uses: actions/checkout@v4
76-
if: matrix.resolver == 'snapshot'
77-
- uses: actions/checkout@v4
78-
if: matrix.resolver != 'snapshot'
7976
- uses: actions/setup-node@v4
8077
with:
8178
node-version: '22'
@@ -95,11 +92,6 @@ jobs:
9592
--resolver ${{ matrix.resolver }}
9693
- name: Build assets
9794
run: npm run build
98-
- name: Run tests without coverage
99-
if: matrix.resolver != 'snapshot'
100-
run: carton exec prove -lr --jobs 2 t
101-
env:
102-
TEST_TIDYALL_VERBOSE: 1
10395
- name: Install Codecovbash
10496
if: matrix.resolver == 'snapshot'
10597
uses: perl-actions/install-with-cpm@v1
@@ -108,17 +100,19 @@ jobs:
108100
Devel::Cover
109101
Devel::Cover::Report::Codecovbash
110102
sudo: false
111-
- name: Run tests with coverage
103+
- name: Configure Code Coverage
104+
id: coverage
112105
if: matrix.resolver == 'snapshot'
106+
run: >
107+
echo "switches=-MDevel::Cover=+ignore,^t/" >> "$GITHUB_OUTPUT"
108+
- name: Run tests
113109
run: carton exec prove -lr --jobs 2 t
114110
env:
115-
HARNESS_PERL_SWITCHES: -MDevel::Cover=+ignore,^t/
111+
HARNESS_PERL_SWITCHES: $${ steps.coverage.outputs.switches }}
116112
- name: Generate Codecov report
117113
if: matrix.resolver == 'snapshot'
118114
run: cover -report codecovbash
119-
- uses: codecov/codecov-action@v4
120-
if: matrix.resolver == 'snapshot'
115+
- uses: actions/upload-artifact@v4
121116
with:
122-
fail_ci_if_error: true
123-
file: ./cover_db/codecov.json
124-
token: ${{ secrets.CODECOV_TOKEN }}
117+
name: codecov.json
118+
path: ./cover_db/codecov.json

.github/workflows/upload-coverage.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Upload Coverage Report
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Test"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
upload:
11+
name: Upload
12+
runs-on: ubuntu-latest
13+
if: >
14+
github.event.workflow_run.event == 'pull_request' &&
15+
github.event.workflow_run.conclusion == 'success'
16+
steps:
17+
- uses: actions/download-artifact@v4
18+
with:
19+
pattern: codecov.json
20+
id: ${{ github.event.workflow_run.id }}
21+
- uses: actions/checkout@v4
22+
name: Checkout codecov.yml
23+
with:
24+
path: repo
25+
sparse-checkout: |
26+
codecov.yml
27+
sparse-checkout-cone-mode: false
28+
- uses: actions/github-script@v7
29+
name: Find associated pull request
30+
id: pr
31+
with:
32+
script: |
33+
const response = await github.rest.search.issuesAndPullRequests({
34+
q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}',
35+
per_page: 1,
36+
})
37+
const items = response.data.items
38+
if (items.length < 1) {
39+
console.error('No PRs found')
40+
return
41+
}
42+
const pullRequest = items[0]
43+
console.info("Pull request number is", pullRequest.number)
44+
return pullRequest
45+
- name:
46+
env:
47+
PR_DATA: ${{ steps.id.outputs.result }}
48+
EVENT_DATA: ${{ toJson(github.event) }}
49+
run: 'printf "pr:\n%s\nevent:\n%s\n" "$PR_DATA" "$EVENT_DATA"'
50+
# - uses: codecov/codecov-action@v4
51+
# if: hashFiles('codecov.json')
52+
# with:
53+
# codecov_yml_path: repo/codecov.yml
54+
# disable_search: true
55+
# file: codecov.json
56+
# token: ${{ secrets.CODECOV_TOKEN }}
57+
# commit_parent: ${{ }}
58+
# job_code: ${{ github.event.workflow.name }}
59+
# os: ${{ }}
60+
# override_branch: ${{ }}
61+
# override_build: ${{ }}
62+
# override_build_url: ${{ }}
63+
# override_commit: ${{ }}
64+
# override_pr: ${{ }}

0 commit comments

Comments
 (0)