Skip to content

Commit aaa6134

Browse files
committed
Refactor for single repos
1 parent 06621e2 commit aaa6134

File tree

5 files changed

+645
-245
lines changed

5 files changed

+645
-245
lines changed

.github/workflows/base-coverage.yml

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,7 @@ concurrency:
1212

1313
jobs:
1414
upload-coverage:
15-
runs-on: ubuntu-24.04
16-
steps:
17-
- name: 📥 Checkout Repository
18-
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
19-
20-
- name: 💻 Node setup
21-
uses: ./.github/actions/node-setup
22-
23-
- name: 🧪 Test
24-
run: pnpm test:coverage
25-
shell: bash
26-
27-
- name: 📊 Aggregate coverage results
28-
run: node scripts/aggregate-coverage-results.js
29-
shell: bash
30-
31-
- name: ♻️ Collect coverage summaries
32-
run: |
33-
rm -rf base-coverage
34-
rsync -a \
35-
--include '*/' \
36-
--include 'coverage-summary.json' \
37-
--exclude '*' \
38-
coverage/ base-coverage/
39-
shell: bash
40-
41-
- name: 📤 Upload coverage artifact
42-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
43-
with:
44-
name: base-coverage
45-
path: base-coverage
46-
retention-days: 14
15+
uses: ./.github/workflows/coverage.yml
16+
with:
17+
monorepo: true
18+
event-type: push

.github/workflows/ci.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,11 @@ jobs:
5151
shell: bash
5252

5353
coverage:
54-
runs-on: ubuntu-24.04
5554
permissions:
5655
actions: read # download base coverage artifact via workflow run APIs
5756
contents: read # checkout
5857
pull-requests: write # comment coverage diff on PRs
59-
steps:
60-
- name: 📥 Checkout Repository
61-
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
62-
63-
- name: 💻 Node setup
64-
uses: ./.github/actions/node-setup
65-
66-
- name: 🧪 Test Coverage
67-
uses: ./.github/actions/test-coverage
68-
with:
69-
github-token: ${{ secrets.GITHUB_TOKEN }}
58+
uses: ./.github/workflows/coverage.yml
59+
with:
60+
monorepo: true
61+
event-type: pr

.github/workflows/coverage.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: 📊 Coverage
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
monorepo:
7+
description: 'Whether this is a monorepo (true) or single repo (false)'
8+
required: false
9+
type: boolean
10+
default: false
11+
event-type:
12+
description: 'Type of event: pr or push'
13+
required: true
14+
type: string
15+
16+
permissions:
17+
contents: read
18+
actions: read
19+
pull-requests: write
20+
21+
jobs:
22+
coverage:
23+
runs-on: ubuntu-24.04
24+
permissions:
25+
actions: read # download base coverage artifact via workflow run APIs
26+
contents: read # checkout
27+
pull-requests: write # comment coverage diff on PRs
28+
steps:
29+
- name: 📥 Checkout Repository
30+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
31+
32+
- name: 💻 Node setup
33+
uses: ./.github/actions/node-setup
34+
35+
- name: 🧪 Test
36+
run: pnpm test:coverage
37+
shell: bash
38+
39+
- name: 📊 Aggregate coverage results
40+
env:
41+
MONOREPO: ${{ inputs.monorepo }}
42+
run: node scripts/aggregate-coverage-results.js
43+
shell: bash
44+
45+
- name: 🔍 Locate base coverage workflow run
46+
id: locate-base-coverage
47+
if: inputs.event-type == 'pr'
48+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
49+
env:
50+
BASE_WORKFLOW: base-coverage.yml
51+
with:
52+
script: |
53+
const workflowId = process.env.BASE_WORKFLOW;
54+
const baseSha = context.payload.pull_request.base.sha;
55+
const { data } = await github.rest.actions.listWorkflowRuns({
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
workflow_id: workflowId,
59+
head_sha: baseSha,
60+
per_page: 20,
61+
});
62+
const run = data.workflow_runs.find((run) => run.conclusion === 'success');
63+
if (run) {
64+
core.info(`Found base coverage run ${run.id}`);
65+
core.setOutput('run-id', String(run.id));
66+
} else {
67+
core.warning(`No successful base coverage run found for ${baseSha}`);
68+
core.setOutput('run-id', '');
69+
}
70+
71+
- name: 📥 Download base branch coverage artifact
72+
if: inputs.event-type == 'pr' && steps.locate-base-coverage.outputs.run-id != ''
73+
continue-on-error: true
74+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
75+
with:
76+
name: base-coverage
77+
path: base-coverage
78+
github-token: ${{ secrets.GITHUB_TOKEN }}
79+
run-id: ${{ steps.locate-base-coverage.outputs.run-id }}
80+
81+
- name: 💬 Comment coverage diff
82+
if: inputs.event-type == 'pr'
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
PR_NUMBER: ${{ github.event.pull_request.number }}
86+
BASE_COVERAGE_ROOT: base-coverage
87+
MONOREPO: ${{ inputs.monorepo }}
88+
run: node scripts/comment-coverage-diff.js
89+
shell: bash
90+
91+
- name: ♻️ Collect coverage summaries
92+
if: inputs.event-type == 'push'
93+
env:
94+
MONOREPO: ${{ inputs.monorepo }}
95+
run: |
96+
rm -rf base-coverage
97+
if [ "$MONOREPO" = "true" ]; then
98+
rsync -a \
99+
--include '*/' \
100+
--include 'coverage-summary.json' \
101+
--exclude '*' \
102+
coverage/ base-coverage/
103+
else
104+
mkdir -p base-coverage
105+
cp coverage/coverage-summary.json base-coverage/coverage-summary.json
106+
fi
107+
shell: bash
108+
109+
- name: 📤 Upload coverage artifact
110+
if: inputs.event-type == 'push'
111+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
112+
with:
113+
name: base-coverage
114+
path: base-coverage
115+
retention-days: 14

0 commit comments

Comments
 (0)