@@ -10,6 +10,8 @@ import { RemoteQuery } from './remote-query';
1010import { RemoteQueryFailureIndexItem , RemoteQueryResultIndex , RemoteQuerySuccessIndexItem } from './remote-query-result-index' ;
1111import { getErrorMessage } from '../pure/helpers-pure' ;
1212
13+ export const RESULT_INDEX_ARTIFACT_NAME = 'result-index' ;
14+
1315interface ApiSuccessIndexItem {
1416 nwo : string ;
1517 id : string ;
@@ -43,7 +45,8 @@ export async function getRemoteQueryIndex(
4345 const workflowUri = `https://github.com/${ owner } /${ repoName } /actions/runs/${ workflowRunId } ` ;
4446 const artifactsUrlPath = `/repos/${ owner } /${ repoName } /actions/artifacts` ;
4547
46- const [ artifactList , resultIndexArtifactId ] = await waitForArtifact ( credentials , owner , repoName , workflowRunId , 'result-indx' ) ;
48+ const artifactList = await listWorkflowRunArtifacts ( credentials , owner , repoName , workflowRunId ) ;
49+ const resultIndexArtifactId = tryGetArtifactIDfromName ( RESULT_INDEX_ARTIFACT_NAME , artifactList ) ;
4750 if ( ! resultIndexArtifactId ) {
4851 return undefined ;
4952 }
@@ -115,6 +118,27 @@ export async function downloadArtifactFromLink(
115118 return path . join ( extractedPath , downloadLink . innerFilePath || '' ) ;
116119}
117120
121+ /**
122+ * Checks whether a specific artifact is present in the list of artifacts of a workflow run.
123+ * @param credentials Credentials for authenticating to the GitHub API.
124+ * @param owner
125+ * @param repo
126+ * @param workflowRunId The ID of the workflow run to get the artifact for.
127+ * @param artifactName The artifact name, as a string.
128+ * @returns A boolean indicating if the artifact is available.
129+ */
130+ export async function isArtifactAvailable (
131+ credentials : Credentials ,
132+ owner : string ,
133+ repo : string ,
134+ workflowRunId : number ,
135+ artifactName : string ,
136+ ) : Promise < boolean > {
137+ const artifactList = await listWorkflowRunArtifacts ( credentials , owner , repo , workflowRunId ) ;
138+
139+ return tryGetArtifactIDfromName ( artifactName , artifactList ) !== undefined ;
140+ }
141+
118142/**
119143 * Downloads the result index artifact and extracts the result index items.
120144 * @param credentials Credentials for authenticating to the GitHub API.
@@ -254,44 +278,6 @@ function tryGetArtifactIDfromName(
254278 return artifact ?. id ;
255279}
256280
257- /**
258- * Wait for an artifact to be available in a workflow run.
259- * @param credentials Credentials for authenticating to the GitHub API.
260- * @param owner
261- * @param repo
262- * @param workflowRunId The ID of the workflow run to get the artifact for.
263- * @param artifactName The artifact name, as a string.
264- * @param maxAttempts The maximum number of attempts to download the artifact.
265- * @returns An array containing the full list of artifacts and the ID of the artifact with the given name.
266- */
267- async function waitForArtifact (
268- credentials : Credentials ,
269- owner : string ,
270- repo : string ,
271- workflowRunId : number ,
272- artifactName : string ,
273- maxAttempts = 10 ,
274- intervalBetweenAttempts = 1000
275- ) : Promise < [ Awaited < ReturnType < typeof listWorkflowRunArtifacts > > , number | undefined ] > {
276- let attemptCount = 0 ;
277- let artifactList : Awaited < ReturnType < typeof listWorkflowRunArtifacts > > = [ ] ;
278-
279- while ( attemptCount < maxAttempts ) {
280- artifactList = await listWorkflowRunArtifacts ( credentials , owner , repo , workflowRunId ) ;
281-
282- const resultIndexArtifactId = tryGetArtifactIDfromName ( artifactName , artifactList ) ;
283- if ( resultIndexArtifactId ) {
284- return [ artifactList , resultIndexArtifactId ] ;
285- }
286-
287- await new Promise ( resolve => setTimeout ( resolve , intervalBetweenAttempts ) ) ;
288-
289- attemptCount ++ ;
290- }
291-
292- return [ artifactList , undefined ] ;
293- }
294-
295281/**
296282 * Downloads an artifact from a workflow run.
297283 * @param credentials Credentials for authenticating to the GitHub API.
0 commit comments