-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
148 lines (133 loc) · 5.46 KB
/
Copy pathpost-test-status.yml
File metadata and controls
148 lines (133 loc) · 5.46 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
name: Post Test Status
# This workflow runs in the base repo context (with write permissions)
# even for fork PRs, allowing us to post commit statuses and check runs.
#
# Add any status posting or check run creation for fork PRs here to avoid
# "Resource not accessible by integration" errors.
on:
workflow_run:
workflows: ["Dash Testing"]
types:
- completed
jobs:
post-skipped-statuses:
name: Post Statuses for Skipped Jobs
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
permissions:
statuses: write
actions: read
steps:
- name: Post statuses for skipped jobs
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const runId = context.payload.workflow_run.id;
const headSha = context.payload.workflow_run.head_sha;
// Define jobs that need a success status posted when skipped
const skippedStatusJobs = [
{
jobName: 'Dash Table Visual Tests',
statusContext: 'percy/dash-table-test',
description: 'Skipped — no dash-table changes'
}
// Add more jobs here as needed
];
// Get all jobs for the workflow run
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({
owner,
repo,
run_id: runId,
});
// Post status for each skipped job
for (const { jobName, statusContext, description } of skippedStatusJobs) {
const job = jobs.find(j => j.name === jobName);
if (job && job.conclusion === 'skipped') {
await github.rest.repos.createCommitStatus({
owner,
repo,
sha: headSha,
state: 'success',
context: statusContext,
description: description,
});
console.log(`Posted skipped status for ${statusContext}`);
} else {
console.log(`Job "${jobName}" status: ${job?.conclusion ?? 'not found'} - no status posted`);
}
}
- name: Post Percy status for fork/Dependabot PRs
# Percy needs PERCY_TOKEN to run, which is unavailable to fork PRs (and to
# Dependabot unless added to Dependabot secrets). Without a build, the
# Percy GitHub App never posts the required `percy/dash` status and the PR
# is blocked. Post a success status here so the check resolves — but only
# if Percy hasn't already posted one, so a real Percy result is never
# clobbered (e.g. when Dependabot does have the token).
if: >
github.event.workflow_run.head_repository.full_name != github.repository ||
github.event.workflow_run.actor.login == 'dependabot[bot]'
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const sha = context.payload.workflow_run.head_sha;
const statusContext = 'percy/dash';
const { data: { statuses } } = await github.rest.repos.getCombinedStatus({
owner,
repo,
ref: sha,
});
if (statuses.some(s => s.context === statusContext)) {
console.log(`'${statusContext}' already posted — leaving it untouched.`);
return;
}
await github.rest.repos.createCommitStatus({
owner,
repo,
sha,
state: 'success',
context: statusContext,
description: 'Skipped — Percy unavailable for fork/Dependabot PRs',
});
console.log(`Posted skipped status for ${statusContext}`);
test-report:
name: Consolidated Test Report (Fork PR)
runs-on: ubuntu-latest
# Run for fork PRs and Dependabot PRs. Both run with a read-only
# GITHUB_TOKEN in the main workflow, so the check run is created here in the
# base-repo context instead. Other same-repo PRs are handled in the main workflow.
if: |
github.event.workflow_run.event == 'pull_request' &&
(github.event.workflow_run.head_repository.full_name != github.repository ||
github.event.workflow_run.actor.login == 'dependabot[bot]')
permissions:
checks: write
actions: read
steps:
# dorny/test-reporter runs `git ls-files` to resolve test paths, so the
# repo must be checked out. This workflow_run job otherwise has no checkout.
- name: Checkout repository
uses: actions/checkout@v4
- name: Download test results artifact
uses: actions/download-artifact@v4
with:
pattern: '*-results-*'
path: test-results
merge-multiple: false
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: List downloaded results
run: find test-results -name "*.xml" -type f 2>/dev/null || echo "No XML files found"
- name: Publish Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: Test Results Summary
path: 'test-results/**/*.xml'
reporter: java-junit
fail-on-error: false
fail-on-empty: false
list-suites: 'failed'
list-tests: 'failed'
max-annotations: '50'