Refactor generic part of uploadDebugArtifacts into uploadArtifacts

This commit is contained in:
Michael B. Gale
2026-01-20 12:49:19 +00:00
parent f950f7f442
commit 13eb1818b9
4 changed files with 50 additions and 18 deletions
+6 -3
View File
@@ -125724,9 +125724,6 @@ function getArtifactSuffix(matrix) {
return suffix;
}
async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghVariant, codeQlVersion) {
if (toUpload.length === 0) {
return "no-artifacts-to-upload";
}
const uploadSupported = isSafeArtifactUpload(codeQlVersion);
if (!uploadSupported) {
core12.info(
@@ -125734,6 +125731,12 @@ async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghV
);
return "upload-not-supported";
}
return uploadArtifacts(logger, toUpload, rootDir, artifactName, ghVariant);
}
async function uploadArtifacts(logger, toUpload, rootDir, artifactName, ghVariant) {
if (toUpload.length === 0) {
return "no-artifacts-to-upload";
}
if (isInTestMode()) {
await scanArtifactsForTokens(toUpload, logger);
core12.exportVariable("CODEQL_ACTION_ARTIFACT_SCAN_FINISHED", "true");
+6 -3
View File
@@ -130447,9 +130447,6 @@ function getArtifactSuffix(matrix) {
return suffix;
}
async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghVariant, codeQlVersion) {
if (toUpload.length === 0) {
return "no-artifacts-to-upload";
}
const uploadSupported = isSafeArtifactUpload(codeQlVersion);
if (!uploadSupported) {
core12.info(
@@ -130457,6 +130454,12 @@ async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghV
);
return "upload-not-supported";
}
return uploadArtifacts(logger, toUpload, rootDir, artifactName, ghVariant);
}
async function uploadArtifacts(logger, toUpload, rootDir, artifactName, ghVariant) {
if (toUpload.length === 0) {
return "no-artifacts-to-upload";
}
if (isInTestMode()) {
await scanArtifactsForTokens(toUpload, logger);
core12.exportVariable("CODEQL_ACTION_ARTIFACT_SCAN_FINISHED", "true");
+6 -3
View File
@@ -124659,9 +124659,6 @@ function getArtifactSuffix(matrix) {
return suffix;
}
async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghVariant, codeQlVersion) {
if (toUpload.length === 0) {
return "no-artifacts-to-upload";
}
const uploadSupported = isSafeArtifactUpload(codeQlVersion);
if (!uploadSupported) {
core12.info(
@@ -124669,6 +124666,12 @@ async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghV
);
return "upload-not-supported";
}
return uploadArtifacts(logger, toUpload, rootDir, artifactName, ghVariant);
}
async function uploadArtifacts(logger, toUpload, rootDir, artifactName, ghVariant) {
if (toUpload.length === 0) {
return "no-artifacts-to-upload";
}
if (isInTestMode()) {
await scanArtifactsForTokens(toUpload, logger);
core12.exportVariable("CODEQL_ACTION_ARTIFACT_SCAN_FINISHED", "true");
+32 -9
View File
@@ -273,6 +273,12 @@ export function getArtifactSuffix(matrix: string | undefined): string {
return suffix;
}
// Enumerates different, possible outcomes for artifact uploads.
export type UploadArtifactsResult =
| "no-artifacts-to-upload"
| "upload-successful"
| "upload-failed";
export async function uploadDebugArtifacts(
logger: Logger,
toUpload: string[],
@@ -280,15 +286,7 @@ export async function uploadDebugArtifacts(
artifactName: string,
ghVariant: GitHubVariant,
codeQlVersion: string | undefined,
): Promise<
| "no-artifacts-to-upload"
| "upload-successful"
| "upload-failed"
| "upload-not-supported"
> {
if (toUpload.length === 0) {
return "no-artifacts-to-upload";
}
): Promise<UploadArtifactsResult | "upload-not-supported"> {
const uploadSupported = isSafeArtifactUpload(codeQlVersion);
if (!uploadSupported) {
@@ -298,6 +296,31 @@ export async function uploadDebugArtifacts(
return "upload-not-supported";
}
return uploadArtifacts(logger, toUpload, rootDir, artifactName, ghVariant);
}
/**
* Uploads the specified files as a single workflow artifact.
*
* @param logger The logger to use.
* @param toUpload The list of paths to include in the artifact.
* @param rootDir The root directory of the paths to include.
* @param artifactName The base name for the artifact.
* @param ghVariant The GitHub variant.
*
* @returns The outcome of the attempt to create and upload the artifact.
*/
export async function uploadArtifacts(
logger: Logger,
toUpload: string[],
rootDir: string,
artifactName: string,
ghVariant: GitHubVariant,
): Promise<UploadArtifactsResult> {
if (toUpload.length === 0) {
return "no-artifacts-to-upload";
}
// When running in test mode, perform a best effort scan of the debug artifacts. The artifact
// scanner is basic and not reliable or fast enough for production use, but it can help catch
// some issues early.