Skip to content

Commit da90651

Browse files
authored
Merge pull request #1492 from github/koesie10/retry-artifacts
Add retry for finding result-index artifact
2 parents 5067fbc + 80867e6 commit da90651

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

extensions/ql-vscode/src/remote-queries/gh-actions-api-client.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { RemoteQuery } from './remote-query';
1010
import { RemoteQueryFailureIndexItem, RemoteQueryResultIndex, RemoteQuerySuccessIndexItem } from './remote-query-result-index';
1111
import { getErrorMessage } from '../pure/helpers-pure';
1212

13+
export const RESULT_INDEX_ARTIFACT_NAME = 'result-index';
14+
1315
interface ApiSuccessIndexItem {
1416
nwo: string;
1517
id: string;
@@ -44,7 +46,7 @@ export async function getRemoteQueryIndex(
4446
const artifactsUrlPath = `/repos/${owner}/${repoName}/actions/artifacts`;
4547

4648
const artifactList = await listWorkflowRunArtifacts(credentials, owner, repoName, workflowRunId);
47-
const resultIndexArtifactId = tryGetArtifactIDfromName('result-index', artifactList);
49+
const resultIndexArtifactId = tryGetArtifactIDfromName(RESULT_INDEX_ARTIFACT_NAME, artifactList);
4850
if (!resultIndexArtifactId) {
4951
return undefined;
5052
}
@@ -116,6 +118,27 @@ export async function downloadArtifactFromLink(
116118
return path.join(extractedPath, downloadLink.innerFilePath || '');
117119
}
118120

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+
119142
/**
120143
* Downloads the result index artifact and extracts the result index items.
121144
* @param credentials Credentials for authenticating to the GitHub API.

extensions/ql-vscode/src/remote-queries/remote-queries-monitor.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode';
22
import { Credentials } from '../authentication';
33
import { Logger } from '../logging';
4-
import { getWorkflowStatus } from './gh-actions-api-client';
4+
import { getWorkflowStatus, isArtifactAvailable, RESULT_INDEX_ARTIFACT_NAME } from './gh-actions-api-client';
55
import { RemoteQuery } from './remote-query';
66
import { RemoteQueryWorkflowResult } from './remote-query-workflow-result';
77

@@ -42,7 +42,25 @@ export class RemoteQueriesMonitor {
4242
remoteQuery.controllerRepository.name,
4343
remoteQuery.actionsWorkflowRunId);
4444

45-
if (workflowStatus.status !== 'InProgress') {
45+
// Even if the workflow indicates it has completed, artifacts
46+
// might still take a while to become available. So we need to
47+
// check for the artifact before we can declare the workflow
48+
// as having completed.
49+
if (workflowStatus.status === 'CompletedSuccessfully') {
50+
const resultIndexAvailable = await isArtifactAvailable(
51+
credentials,
52+
remoteQuery.controllerRepository.owner,
53+
remoteQuery.controllerRepository.name,
54+
remoteQuery.actionsWorkflowRunId,
55+
RESULT_INDEX_ARTIFACT_NAME
56+
);
57+
58+
if (resultIndexAvailable) {
59+
return workflowStatus;
60+
}
61+
62+
// We don't have a result-index yet, so we'll keep monitoring.
63+
} else if (workflowStatus.status !== 'InProgress') {
4664
return workflowStatus;
4765
}
4866

0 commit comments

Comments
 (0)