-
Notifications
You must be signed in to change notification settings - Fork 12.2k
212 lines (187 loc) · 9.28 KB
/
e2e-report.yml
File metadata and controls
212 lines (187 loc) · 9.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: E2E Report
on:
workflow_run:
workflows: ["PR Update"]
types:
- completed
workflow_dispatch:
inputs:
pr_number:
description: 'The PR number to generate report for'
required: true
type: string
jobs:
get-pr-info:
name: Get PR Info
runs-on: ubuntu-latest
# For workflow_run: only run if the triggering workflow failed
# For workflow_dispatch: always run (inputs are provided manually)
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'failure' }}
permissions:
actions: read
pull-requests: read
outputs:
pr-number: ${{ steps.get-info.outputs.pr-number }}
head-branch: ${{ steps.get-info.outputs.head-branch }}
has-blob-reports: ${{ steps.get-info.outputs.has-blob-reports }}
source-run-id: ${{ steps.get-info.outputs.source-run-id }}
source-run-number: ${{ steps.get-info.outputs.source-run-number }}
source-run-attempt: ${{ steps.get-info.outputs.source-run-attempt }}
source-head-sha: ${{ steps.get-info.outputs.source-head-sha }}
steps:
- name: Get PR and run info
id: get-info
uses: actions/github-script@v7
with:
script: |
const isDispatch = context.eventName === 'workflow_dispatch';
if (isDispatch) {
// For workflow_dispatch: look up everything from PR number
const prNumber = context.payload.inputs.pr_number;
console.log('Looking up PR:', prNumber);
// Get PR details
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: parseInt(prNumber)
});
const headSha = pr.head.sha;
const headBranch = pr.head.ref;
console.log('PR head SHA:', headSha);
console.log('PR head branch:', headBranch);
// Find the "PR Update" workflow
const { data: workflows } = await github.rest.actions.listRepoWorkflows({
owner: context.repo.owner,
repo: context.repo.repo
});
const prUpdateWorkflow = workflows.workflows.find(w => w.name === 'PR Update');
if (!prUpdateWorkflow) {
core.setFailed('Could not find "PR Update" workflow');
return;
}
console.log('Found PR Update workflow ID:', prUpdateWorkflow.id);
// Find the most recent completed run for this branch with blob-report artifacts
// We search by branch instead of SHA to handle cases where:
// 1. The PR was updated after E2E tests ran (artifacts exist for older SHA)
// 2. The current run for the SHA is still queued/in-progress
const { data: runs } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: prUpdateWorkflow.id,
branch: headBranch,
status: 'completed',
per_page: 20
});
console.log('Found', runs.workflow_runs.length, 'completed runs for branch', headBranch);
// Find a run with blob-report artifacts
let selectedRun = null;
let hasBlobReports = false;
for (const run of runs.workflow_runs) {
console.log('Checking run', run.id, 'conclusion:', run.conclusion);
const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: run.id
});
const blobReports = artifacts.artifacts.filter(a => a.name.startsWith('blob-report-'));
if (blobReports.length > 0) {
console.log('Found run with blob reports:', run.id, 'artifacts:', blobReports.map(a => a.name));
selectedRun = run;
hasBlobReports = true;
break;
}
}
if (!selectedRun) {
console.log('No runs found with blob-report artifacts');
core.setOutput('pr-number', prNumber);
core.setOutput('head-branch', headBranch);
core.setOutput('source-head-sha', headSha);
core.setOutput('has-blob-reports', 'false');
core.setOutput('source-run-id', '');
core.setOutput('source-run-number', '');
core.setOutput('source-run-attempt', '');
return;
}
core.setOutput('pr-number', prNumber);
core.setOutput('head-branch', headBranch);
core.setOutput('source-head-sha', headSha);
core.setOutput('source-run-id', selectedRun.id.toString());
core.setOutput('source-run-number', selectedRun.run_number.toString());
core.setOutput('source-run-attempt', selectedRun.run_attempt.toString());
core.setOutput('has-blob-reports', 'true');
return;
}
// For workflow_run: extract from payload
const workflowRun = context.payload.workflow_run;
const headSha = workflowRun.head_sha;
const headBranch = workflowRun.head_branch;
console.log('Head SHA:', headSha);
console.log('Head Branch:', headBranch);
// Set source run info
core.setOutput('source-run-id', workflowRun.id.toString());
core.setOutput('source-run-number', workflowRun.run_number.toString());
core.setOutput('source-run-attempt', workflowRun.run_attempt.toString());
core.setOutput('source-head-sha', headSha);
// Check for blob report artifacts
const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: workflowRun.id
});
const blobReports = artifacts.artifacts.filter(a => a.name.startsWith('blob-report-'));
console.log('Found blob reports:', blobReports.map(a => a.name));
core.setOutput('has-blob-reports', blobReports.length > 0 ? 'true' : 'false');
// Try to get PR number from workflow_run payload first
if (workflowRun.pull_requests && workflowRun.pull_requests.length > 0) {
const prNumber = workflowRun.pull_requests[0].number;
console.log('PR number from payload:', prNumber);
core.setOutput('pr-number', prNumber.toString());
core.setOutput('head-branch', headBranch);
return;
}
// Fall back to API lookup
try {
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: headSha
});
if (prs.length === 0) {
console.log('No PRs found for commit');
core.setOutput('pr-number', '');
core.setOutput('head-branch', headBranch);
return;
}
// Find open PR or use first one
const openPr = prs.find(pr => pr.state === 'open') || prs[0];
console.log('PR number from API:', openPr.number);
core.setOutput('pr-number', openPr.number.toString());
core.setOutput('head-branch', openPr.head.ref);
} catch (e) {
console.log('Error fetching PR:', e);
core.setOutput('pr-number', '');
core.setOutput('head-branch', headBranch);
}
merge-reports:
name: Merge reports
needs: [get-pr-info]
if: ${{ needs.get-pr-info.outputs.has-blob-reports == 'true' && needs.get-pr-info.outputs.pr-number != '' }}
uses: ./.github/workflows/merge-reports.yml
with:
source_run_id: ${{ needs.get-pr-info.outputs.source-run-id }}
source_run_number: ${{ needs.get-pr-info.outputs.source-run-number }}
source_run_attempt: ${{ needs.get-pr-info.outputs.source-run-attempt }}
source_head_sha: ${{ needs.get-pr-info.outputs.source-head-sha }}
# No secrets: inherit - merge-reports only needs the default GITHUB_TOKEN for artifact download
publish-report:
name: Publish HTML report
needs: [get-pr-info, merge-reports]
if: ${{ needs.get-pr-info.outputs.pr-number != '' }}
uses: ./.github/workflows/publish-report.yml
with:
head_branch: ${{ needs.get-pr-info.outputs.head-branch }}
source_run_id: ${{ needs.get-pr-info.outputs.source-run-id }}
source_run_number: ${{ needs.get-pr-info.outputs.source-run-number }}
source_run_attempt: ${{ needs.get-pr-info.outputs.source-run-attempt }}
pr_number: ${{ needs.get-pr-info.outputs.pr-number }}
secrets: inherit