mirror of
https://github.com/github/codeql-action.git
synced 2026-05-21 10:00:58 +00:00
Refactor artifact suffix computation into getArtifactSuffix
This commit is contained in:
Generated
+17
-14
@@ -125707,6 +125707,22 @@ async function uploadCombinedSarifArtifacts(logger, gitHubVariant, codeQlVersion
|
||||
});
|
||||
}
|
||||
}
|
||||
function getArtifactSuffix(matrix) {
|
||||
let suffix = "";
|
||||
if (matrix) {
|
||||
try {
|
||||
for (const [, matrixVal] of Object.entries(
|
||||
JSON.parse(matrix)
|
||||
).sort())
|
||||
suffix += `-${matrixVal}`;
|
||||
} catch {
|
||||
core12.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;
|
||||
}
|
||||
async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghVariant, codeQlVersion) {
|
||||
if (toUpload.length === 0) {
|
||||
return "no-artifacts-to-upload";
|
||||
@@ -125722,20 +125738,7 @@ async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghV
|
||||
await scanArtifactsForTokens(toUpload, logger);
|
||||
core12.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)
|
||||
).sort())
|
||||
suffix += `-${matrixVal}`;
|
||||
} catch {
|
||||
core12.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 {
|
||||
await artifactUploader.uploadArtifact(
|
||||
|
||||
Generated
+17
-14
@@ -130430,6 +130430,22 @@ async function tryUploadAllAvailableDebugArtifacts(codeql, config, logger, codeQ
|
||||
);
|
||||
}
|
||||
}
|
||||
function getArtifactSuffix(matrix) {
|
||||
let suffix = "";
|
||||
if (matrix) {
|
||||
try {
|
||||
for (const [, matrixVal] of Object.entries(
|
||||
JSON.parse(matrix)
|
||||
).sort())
|
||||
suffix += `-${matrixVal}`;
|
||||
} catch {
|
||||
core12.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;
|
||||
}
|
||||
async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghVariant, codeQlVersion) {
|
||||
if (toUpload.length === 0) {
|
||||
return "no-artifacts-to-upload";
|
||||
@@ -130445,20 +130461,7 @@ async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghV
|
||||
await scanArtifactsForTokens(toUpload, logger);
|
||||
core12.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)
|
||||
).sort())
|
||||
suffix += `-${matrixVal}`;
|
||||
} catch {
|
||||
core12.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 {
|
||||
await artifactUploader.uploadArtifact(
|
||||
|
||||
Generated
+17
-14
@@ -124642,6 +124642,22 @@ async function uploadCombinedSarifArtifacts(logger, gitHubVariant, codeQlVersion
|
||||
});
|
||||
}
|
||||
}
|
||||
function getArtifactSuffix(matrix) {
|
||||
let suffix = "";
|
||||
if (matrix) {
|
||||
try {
|
||||
for (const [, matrixVal] of Object.entries(
|
||||
JSON.parse(matrix)
|
||||
).sort())
|
||||
suffix += `-${matrixVal}`;
|
||||
} catch {
|
||||
core12.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;
|
||||
}
|
||||
async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghVariant, codeQlVersion) {
|
||||
if (toUpload.length === 0) {
|
||||
return "no-artifacts-to-upload";
|
||||
@@ -124657,20 +124673,7 @@ async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghV
|
||||
await scanArtifactsForTokens(toUpload, logger);
|
||||
core12.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)
|
||||
).sort())
|
||||
suffix += `-${matrixVal}`;
|
||||
} catch {
|
||||
core12.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 {
|
||||
await artifactUploader.uploadArtifact(
|
||||
|
||||
+28
-15
@@ -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