Skip to content

Commit 13eb181

Browse files
committed
Refactor generic part of uploadDebugArtifacts into uploadArtifacts
1 parent f950f7f commit 13eb181

File tree

4 files changed

+50
-18
lines changed

4 files changed

+50
-18
lines changed

lib/analyze-action-post.js

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

lib/init-action-post.js

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

lib/upload-sarif-action-post.js

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

src/debug-artifacts.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,20 @@ export function getArtifactSuffix(matrix: string | undefined): string {
273273
return suffix;
274274
}
275275

276+
// Enumerates different, possible outcomes for artifact uploads.
277+
export type UploadArtifactsResult =
278+
| "no-artifacts-to-upload"
279+
| "upload-successful"
280+
| "upload-failed";
281+
276282
export async function uploadDebugArtifacts(
277283
logger: Logger,
278284
toUpload: string[],
279285
rootDir: string,
280286
artifactName: string,
281287
ghVariant: GitHubVariant,
282288
codeQlVersion: string | undefined,
283-
): Promise<
284-
| "no-artifacts-to-upload"
285-
| "upload-successful"
286-
| "upload-failed"
287-
| "upload-not-supported"
288-
> {
289-
if (toUpload.length === 0) {
290-
return "no-artifacts-to-upload";
291-
}
289+
): Promise<UploadArtifactsResult | "upload-not-supported"> {
292290
const uploadSupported = isSafeArtifactUpload(codeQlVersion);
293291

294292
if (!uploadSupported) {
@@ -298,6 +296,31 @@ export async function uploadDebugArtifacts(
298296
return "upload-not-supported";
299297
}
300298

299+
return uploadArtifacts(logger, toUpload, rootDir, artifactName, ghVariant);
300+
}
301+
302+
/**
303+
* Uploads the specified files as a single workflow artifact.
304+
*
305+
* @param logger The logger to use.
306+
* @param toUpload The list of paths to include in the artifact.
307+
* @param rootDir The root directory of the paths to include.
308+
* @param artifactName The base name for the artifact.
309+
* @param ghVariant The GitHub variant.
310+
*
311+
* @returns The outcome of the attempt to create and upload the artifact.
312+
*/
313+
export async function uploadArtifacts(
314+
logger: Logger,
315+
toUpload: string[],
316+
rootDir: string,
317+
artifactName: string,
318+
ghVariant: GitHubVariant,
319+
): Promise<UploadArtifactsResult> {
320+
if (toUpload.length === 0) {
321+
return "no-artifacts-to-upload";
322+
}
323+
301324
// When running in test mode, perform a best effort scan of the debug artifacts. The artifact
302325
// scanner is basic and not reliable or fast enough for production use, but it can help catch
303326
// some issues early.

0 commit comments

Comments
 (0)