mirror of
https://github.com/github/codeql-action.git
synced 2026-10-21 10:11:28 +00:00
Refactor artifact suffix computation into getArtifactSuffix
This commit is contained in:
@@ -246,6 +246,33 @@ export async function tryUploadAllAvailableDebugArtifacts(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When a build matrix is used, multiple different jobs arising from the matrix may attempt to upload
|
||||
* workflow artifacts with the same base name. In that case, only one of the uploads will succeed and
|
||||
* the others will fail. This function inspects the matrix object to compute a suffix for the artifact
|
||||
* name that uniquely identifies the matrix values of the current job to avoid name clashes.
|
||||
*
|
||||
* @param matrix A stringified JSON value, usually the value of the `matrix` input.
|
||||
* @returns A suffix that uniquely identifies the `matrix` value for the current job, or `""` if there
|
||||
* is no matrix value.
|
||||
*/
|
||||
export function getArtifactSuffix(matrix: string | undefined): string {
|
||||
let suffix = "";
|
||||
if (matrix) {
|
||||
try {
|
||||
for (const [, matrixVal] of Object.entries(
|
||||
JSON.parse(matrix) as any[][],
|
||||
).sort())
|
||||
suffix += `-${matrixVal}`;
|
||||
} catch {
|
||||
core.info(
|
||||
"Could not parse user-specified `matrix` input into JSON. The debug artifact will not be named with the user's `matrix` input.",
|
||||
);
|
||||
}
|
||||
}
|
||||
return suffix;
|
||||
}
|
||||
|
||||
export async function uploadDebugArtifacts(
|
||||
logger: Logger,
|
||||
toUpload: string[],
|
||||
@@ -279,21 +306,7 @@ export async function uploadDebugArtifacts(
|
||||
core.exportVariable("CODEQL_ACTION_ARTIFACT_SCAN_FINISHED", "true");
|
||||
}
|
||||
|
||||
let suffix = "";
|
||||
const matrix = getOptionalInput("matrix");
|
||||
if (matrix) {
|
||||
try {
|
||||
for (const [, matrixVal] of Object.entries(
|
||||
JSON.parse(matrix) as any[][],
|
||||
).sort())
|
||||
suffix += `-${matrixVal}`;
|
||||
} catch {
|
||||
core.info(
|
||||
"Could not parse user-specified `matrix` input into JSON. The debug artifact will not be named with the user's `matrix` input.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const suffix = getArtifactSuffix(getOptionalInput("matrix"));
|
||||
const artifactUploader = await getArtifactUploaderClient(logger, ghVariant);
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user