1
1
import * as core from "@actions/core" ;
2
2
import * as github from "@actions/github" ;
3
3
import { type ActionConfig , getConfig } from "./action.ts" ;
4
- import { getBranchName } from "./utils.ts" ;
4
+ import type { BranchNameResult } from "./utils.ts" ;
5
5
6
6
type Octokit = ReturnType < ( typeof github ) [ "getOctokit" ] > ;
7
7
@@ -71,7 +71,7 @@ export async function getWorkflowId(workflowFilename: string): Promise<number> {
71
71
} ,
72
72
) ;
73
73
let workflowId : number | undefined ;
74
-
74
+ let workflowIdUrl : string | undefined ;
75
75
for await ( const response of workflowIterator ) {
76
76
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
77
77
if ( response . status !== 200 ) {
@@ -80,11 +80,13 @@ export async function getWorkflowId(workflowFilename: string): Promise<number> {
80
80
) ;
81
81
}
82
82
83
- workflowId = response . data . find ( ( workflow ) =>
83
+ const workflowData = response . data . find ( ( workflow ) =>
84
84
new RegExp ( sanitisedFilename ) . test ( workflow . path ) ,
85
- ) ?. id ;
85
+ ) ;
86
+ workflowId = workflowData ?. id ;
86
87
87
88
if ( workflowId !== undefined ) {
89
+ workflowIdUrl = workflowData ?. html_url ;
88
90
break ;
89
91
}
90
92
}
@@ -93,6 +95,15 @@ export async function getWorkflowId(workflowFilename: string): Promise<number> {
93
95
throw new Error ( `Unable to find ID for Workflow: ${ workflowFilename } ` ) ;
94
96
}
95
97
98
+ core . info (
99
+ `Fetched Workflow ID:\n` +
100
+ ` Repository: ${ config . owner } /${ config . repo } \n` +
101
+ ` Workflow ID: '${ workflowId } '\n` +
102
+ ` Input Filename: '${ workflowFilename } '\n` +
103
+ ` Sanitised Filename: '${ sanitisedFilename } '\n` +
104
+ ` URL: ${ workflowIdUrl } ` ,
105
+ ) ;
106
+
96
107
return workflowId ;
97
108
} catch ( error ) {
98
109
if ( error instanceof Error ) {
@@ -140,22 +151,28 @@ export async function getWorkflowRunUrl(runId: number): Promise<string> {
140
151
}
141
152
}
142
153
143
- export async function getWorkflowRunIds ( workflowId : number ) : Promise < number [ ] > {
154
+ export async function getWorkflowRunIds (
155
+ workflowId : number ,
156
+ branch : BranchNameResult ,
157
+ ) : Promise < number [ ] > {
144
158
try {
145
- const branchName = getBranchName ( config . ref ) ;
159
+ const useBranchFilter =
160
+ ! branch . isTag &&
161
+ branch . branchName !== undefined &&
162
+ branch . branchName !== "" ;
146
163
147
164
// https://docs.github.com/en/rest/reference/actions#list-workflow-runs
148
165
const response = await octokit . rest . actions . listWorkflowRuns ( {
149
166
owner : config . owner ,
150
167
repo : config . repo ,
151
168
workflow_id : workflowId ,
152
- ...( branchName
169
+ ...( useBranchFilter
153
170
? {
154
- branch : branchName ,
155
- per_page : 5 ,
171
+ branch : branch . branchName ,
172
+ per_page : 10 ,
156
173
}
157
174
: {
158
- per_page : 10 ,
175
+ per_page : 20 ,
159
176
} ) ,
160
177
} ) ;
161
178
@@ -170,10 +187,13 @@ export async function getWorkflowRunIds(workflowId: number): Promise<number[]> {
170
187
( workflowRun ) => workflowRun . id ,
171
188
) ;
172
189
190
+ const branchMsg = useBranchFilter
191
+ ? `true (${ branch . branchName } )`
192
+ : `false (${ branch . ref } )` ;
173
193
core . debug (
174
194
"Fetched Workflow Runs:\n" +
175
195
` Repository: ${ config . owner } /${ config . repo } \n` +
176
- ` Branch: ${ branchName } \n` +
196
+ ` Branch Filter : ${ branchMsg } \n` +
177
197
` Workflow ID: ${ workflowId } \n` +
178
198
` Runs Fetched: [${ runIds . join ( ", " ) } ]` ,
179
199
) ;
0 commit comments