@@ -3,7 +3,12 @@ import {Annotation, TestResult} from './testParser.js'
3
3
import * as github from '@actions/github'
4
4
import { SummaryTableRow } from '@actions/core/lib/summary.js'
5
5
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
+ }
7
12
8
13
export async function annotateTestResult (
9
14
testResult : TestResult ,
@@ -14,7 +19,7 @@ export async function annotateTestResult(
14
19
updateCheck : boolean ,
15
20
annotateNotice : boolean ,
16
21
jobName : string
17
- ) : Promise < void > {
22
+ ) : Promise < CheckInfo | undefined > {
18
23
const annotations = testResult . globalAnnotations . filter (
19
24
annotation => annotateNotice || annotation . annotation_level !== 'notice'
20
25
)
@@ -53,6 +58,7 @@ export async function annotateTestResult(
53
58
core . notice ( annotation . message , properties )
54
59
}
55
60
}
61
+ return undefined // No check created, so no URL to return
56
62
} else {
57
63
// check status is being created, annotations are included in this (if not diasbled by "checkAnnotations")
58
64
if ( updateCheck ) {
@@ -67,6 +73,7 @@ export async function annotateTestResult(
67
73
core . debug ( JSON . stringify ( checks , null , 2 ) )
68
74
69
75
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 } `
70
77
71
78
if ( checkAnnotations ) {
72
79
core . info ( `ℹ️ - ${ testResult . checkName } - Updating checks (Annotations: ${ annotations . length } )` )
@@ -78,6 +85,11 @@ export async function annotateTestResult(
78
85
core . info ( `ℹ️ - ${ testResult . checkName } - Updating checks (disabled annotations)` )
79
86
await updateChecks ( octokit , check_run_id , title , testResult . summary , [ ] )
80
87
}
88
+
89
+ return {
90
+ name : testResult . checkName ,
91
+ url : checkUrl
92
+ }
81
93
} else {
82
94
const status : 'completed' | 'in_progress' | 'queued' | undefined = 'completed'
83
95
// don't send annotations if disabled
@@ -98,7 +110,13 @@ export async function annotateTestResult(
98
110
core . debug ( JSON . stringify ( createCheckRequest , null , 2 ) )
99
111
100
112
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
+ }
102
120
}
103
121
}
104
122
}
@@ -127,7 +145,8 @@ async function updateChecks(
127
145
export async function attachSummary (
128
146
table : SummaryTableRow [ ] ,
129
147
detailsTable : SummaryTableRow [ ] ,
130
- flakySummary : SummaryTableRow [ ]
148
+ flakySummary : SummaryTableRow [ ] ,
149
+ checkInfos : CheckInfo [ ] = [ ]
131
150
) : Promise < void > {
132
151
if ( table . length > 0 ) {
133
152
await core . summary . addTable ( table ) . write ( )
@@ -138,6 +157,16 @@ export async function attachSummary(
138
157
if ( flakySummary . length > 1 ) {
139
158
await core . summary . addTable ( flakySummary ) . write ( )
140
159
}
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 ( )
141
170
}
142
171
143
172
export function buildCommentIdentifier ( checkName : string [ ] ) : string {
@@ -150,7 +179,8 @@ export async function attachComment(
150
179
updateComment : boolean ,
151
180
table : SummaryTableRow [ ] ,
152
181
detailsTable : SummaryTableRow [ ] ,
153
- flakySummary : SummaryTableRow [ ]
182
+ flakySummary : SummaryTableRow [ ] ,
183
+ checkInfos : CheckInfo [ ] = [ ]
154
184
) : Promise < void > {
155
185
if ( ! context . issue . number ) {
156
186
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(
173
203
comment += '\n\n'
174
204
comment += buildTable ( flakySummary )
175
205
}
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
+
176
216
comment += `\n\n${ identifier } `
177
217
178
218
const priorComment = updateComment ? await findPriorComment ( octokit , identifier ) : undefined
0 commit comments