Skip to content

Commit 65fe035

Browse files
authored
Merge pull request #1355 from mikepenz/feature/1352
Add link to check in summary
2 parents a4fc445 + d3fcbd9 commit 65fe035

File tree

7 files changed

+137
-32
lines changed

7 files changed

+137
-32
lines changed

__tests__/testParser.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,12 +1452,12 @@ describe('parseTestReports', () => {
14521452

14531453
// Filter to only failure annotations for easier verification
14541454
const failureAnnotations = globalAnnotations.filter(annotation => annotation.annotation_level === 'failure')
1455-
1455+
14561456
// Should have 4 failure annotations total: 3 from testWithMultipleFailures + 1 from testWithSingleFailure
14571457
expect(failureAnnotations).toHaveLength(4)
14581458

14591459
// Verify the multiple failures test case creates separate annotations
1460-
const multipleFailuresAnnotations = failureAnnotations.filter(annotation =>
1460+
const multipleFailuresAnnotations = failureAnnotations.filter(annotation =>
14611461
annotation.title.includes('testWithMultipleFailures')
14621462
)
14631463
expect(multipleFailuresAnnotations).toHaveLength(3)
@@ -1479,7 +1479,7 @@ describe('parseTestReports', () => {
14791479
expect(multipleFailuresAnnotations[2].start_line).toBe(25)
14801480

14811481
// Verify the single failure test case (should not have failure index in title)
1482-
const singleFailureAnnotations = failureAnnotations.filter(annotation =>
1482+
const singleFailureAnnotations = failureAnnotations.filter(annotation =>
14831483
annotation.title.includes('testWithSingleFailure')
14841484
)
14851485
expect(singleFailureAnnotations).toHaveLength(1)

dist/index.js

Lines changed: 60 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/annotator.ts

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import {Annotation, TestResult} from './testParser.js'
33
import * as github from '@actions/github'
44
import {SummaryTableRow} from '@actions/core/lib/summary.js'
55
import {context, GitHub} from '@actions/github/lib/utils.js'
6-
import {buildTable} from './utils.js'
6+
import {buildLink, buildList, buildTable} from './utils.js'
7+
8+
export interface CheckInfo {
9+
name: string
10+
url: string
11+
}
712

813
export async function annotateTestResult(
914
testResult: TestResult,
@@ -14,7 +19,7 @@ export async function annotateTestResult(
1419
updateCheck: boolean,
1520
annotateNotice: boolean,
1621
jobName: string
17-
): Promise<void> {
22+
): Promise<CheckInfo | undefined> {
1823
const annotations = testResult.globalAnnotations.filter(
1924
annotation => annotateNotice || annotation.annotation_level !== 'notice'
2025
)
@@ -53,6 +58,7 @@ export async function annotateTestResult(
5358
core.notice(annotation.message, properties)
5459
}
5560
}
61+
return undefined // No check created, so no URL to return
5662
} else {
5763
// check status is being created, annotations are included in this (if not diasbled by "checkAnnotations")
5864
if (updateCheck) {
@@ -67,6 +73,7 @@ export async function annotateTestResult(
6773
core.debug(JSON.stringify(checks, null, 2))
6874

6975
const check_run_id = checks.data.check_runs[0].id
76+
const checkUrl = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/runs/${check_run_id}`
7077

7178
if (checkAnnotations) {
7279
core.info(`ℹ️ - ${testResult.checkName} - Updating checks (Annotations: ${annotations.length})`)
@@ -78,6 +85,11 @@ export async function annotateTestResult(
7885
core.info(`ℹ️ - ${testResult.checkName} - Updating checks (disabled annotations)`)
7986
await updateChecks(octokit, check_run_id, title, testResult.summary, [])
8087
}
88+
89+
return {
90+
name: testResult.checkName,
91+
url: checkUrl
92+
}
8193
} else {
8294
const status: 'completed' | 'in_progress' | 'queued' | undefined = 'completed'
8395
// don't send annotations if disabled
@@ -98,7 +110,13 @@ export async function annotateTestResult(
98110
core.debug(JSON.stringify(createCheckRequest, null, 2))
99111

100112
core.info(`ℹ️ - ${testResult.checkName} - Creating check (Annotations: ${adjustedAnnotations.length})`)
101-
await octokit.rest.checks.create(createCheckRequest)
113+
const checkResponse = await octokit.rest.checks.create(createCheckRequest)
114+
115+
// Return the check URL for use in job summary
116+
return {
117+
name: testResult.checkName,
118+
url: `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/runs/${checkResponse.data.id}`
119+
}
102120
}
103121
}
104122
}
@@ -127,7 +145,8 @@ async function updateChecks(
127145
export async function attachSummary(
128146
table: SummaryTableRow[],
129147
detailsTable: SummaryTableRow[],
130-
flakySummary: SummaryTableRow[]
148+
flakySummary: SummaryTableRow[],
149+
checkInfos: CheckInfo[] = []
131150
): Promise<void> {
132151
if (table.length > 0) {
133152
await core.summary.addTable(table).write()
@@ -138,6 +157,16 @@ export async function attachSummary(
138157
if (flakySummary.length > 1) {
139158
await core.summary.addTable(flakySummary).write()
140159
}
160+
161+
// Add check links to the job summary if any checks were created
162+
if (checkInfos.length > 0) {
163+
const links = checkInfos.map(checkInfo => {
164+
return buildLink(`View ${checkInfo.name}`, checkInfo.url)
165+
})
166+
core.summary.addList(links)
167+
}
168+
core.summary.addSeparator()
169+
core.summary.write()
141170
}
142171

143172
export function buildCommentIdentifier(checkName: string[]): string {
@@ -150,7 +179,8 @@ export async function attachComment(
150179
updateComment: boolean,
151180
table: SummaryTableRow[],
152181
detailsTable: SummaryTableRow[],
153-
flakySummary: SummaryTableRow[]
182+
flakySummary: SummaryTableRow[],
183+
checkInfos: CheckInfo[] = []
154184
): Promise<void> {
155185
if (!context.issue.number) {
156186
core.warning(`⚠️ Action requires a valid issue number (PR reference) to be able to attach a comment..`)
@@ -173,6 +203,16 @@ export async function attachComment(
173203
comment += '\n\n'
174204
comment += buildTable(flakySummary)
175205
}
206+
207+
// Add check links to the job summary if any checks were created
208+
if (checkInfos.length > 0) {
209+
const links = checkInfos.map(checkInfo => {
210+
return buildLink(`View ${checkInfo.name}`, checkInfo.url)
211+
})
212+
comment += buildList(links)
213+
comment += `\n\n`
214+
}
215+
176216
comment += `\n\n${identifier}`
177217

178218
const priorComment = updateComment ? await findPriorComment(octokit, identifier) : undefined

src/main.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from '@actions/core'
22
import * as github from '@actions/github'
3-
import {annotateTestResult, attachComment, attachSummary} from './annotator.js'
3+
import {annotateTestResult, attachComment, attachSummary, CheckInfo} from './annotator.js'
44
import {parseTestReports, TestResult} from './testParser.js'
55
import {buildTable, readTransformers, retrieve} from './utils.js'
66
import {GitHub} from '@actions/github/lib/utils.js'
@@ -155,10 +155,11 @@ export async function run(): Promise<void> {
155155
core.endGroup()
156156
core.startGroup(`🚀 Publish results`)
157157

158+
const checkInfos: CheckInfo[] = []
158159
if (!skipAnnotations) {
159160
try {
160161
for (const testResult of testResults) {
161-
await annotateTestResult(
162+
const checkInfo = await annotateTestResult(
162163
testResult,
163164
token,
164165
headSha,
@@ -168,6 +169,9 @@ export async function run(): Promise<void> {
168169
annotateNotice,
169170
jobName
170171
)
172+
if (checkInfo) {
173+
checkInfos.push(checkInfo)
174+
}
171175
}
172176
} catch (error) {
173177
core.error(`❌ Failed to create checks using the provided token. (${error})`)
@@ -192,7 +196,7 @@ export async function run(): Promise<void> {
192196
)
193197
if (jobSummary && supportsJobSummary) {
194198
try {
195-
await attachSummary(table, detailTable, flakyTable)
199+
await attachSummary(table, detailTable, flakyTable, checkInfos)
196200
} catch (error) {
197201
core.error(`❌ Failed to set the summary using the provided token. (${error})`)
198202
}
@@ -204,7 +208,7 @@ export async function run(): Promise<void> {
204208

205209
if (comment && (!skipCommentWithoutTests || mergedResult.totalCount > 0)) {
206210
const octokit: InstanceType<typeof GitHub> = github.getOctokit(token)
207-
await attachComment(octokit, checkName, updateComment, table, detailTable, flakyTable)
211+
await attachComment(octokit, checkName, updateComment, table, detailTable, flakyTable, checkInfos)
208212
}
209213

210214
core.setOutput('summary', buildTable(table))

0 commit comments

Comments
 (0)