mirror of
https://github.com/github/codeql-action
synced 2026-05-23 20:00:54 +03:00
Refactor matrix generation into its own function
This commit is contained in:
+47
-41
@@ -275,6 +275,52 @@ function stripTrailingWhitespace(content: string): string {
|
|||||||
.join("\n");
|
.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Generates the matrix for a job. */
|
||||||
|
function generateJobMatrix(
|
||||||
|
checkSpecification: Specification,
|
||||||
|
): Array<Record<string, any>> {
|
||||||
|
let matrix: Array<Record<string, any>> = [];
|
||||||
|
|
||||||
|
for (const version of checkSpecification.versions ?? defaultTestVersions) {
|
||||||
|
if (version === "latest") {
|
||||||
|
throw new Error(
|
||||||
|
'Did not recognise "version: latest". Did you mean "version: linked"?',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const runnerImages = ["ubuntu-latest", "macos-latest", "windows-latest"];
|
||||||
|
const operatingSystems = checkSpecification.operatingSystems ?? ["ubuntu"];
|
||||||
|
|
||||||
|
for (const operatingSystem of operatingSystems) {
|
||||||
|
const runnerImagesForOs = runnerImages.filter((image) =>
|
||||||
|
image.startsWith(operatingSystem),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const runnerImage of runnerImagesForOs) {
|
||||||
|
matrix.push({
|
||||||
|
os: runnerImage,
|
||||||
|
version,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkSpecification.analysisKinds) {
|
||||||
|
const newMatrix: Array<Record<string, any>> = [];
|
||||||
|
for (const matrixInclude of matrix) {
|
||||||
|
for (const analysisKind of checkSpecification.analysisKinds) {
|
||||||
|
newMatrix.push({
|
||||||
|
...matrixInclude,
|
||||||
|
"analysis-kinds": analysisKind,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matrix = newMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves setup steps and additional input definitions based on specific languages or frameworks
|
* Retrieves setup steps and additional input definitions based on specific languages or frameworks
|
||||||
* that are requested by the `checkSpecification`.
|
* that are requested by the `checkSpecification`.
|
||||||
@@ -337,51 +383,11 @@ function main(): void {
|
|||||||
|
|
||||||
console.log(`Processing: ${checkName} — "${checkSpecification.name}"`);
|
console.log(`Processing: ${checkName} — "${checkSpecification.name}"`);
|
||||||
|
|
||||||
let matrix: Array<Record<string, any>> = [];
|
const matrix: Array<Record<string, any>> = generateJobMatrix(checkSpecification);
|
||||||
|
|
||||||
for (const version of checkSpecification.versions ?? defaultTestVersions) {
|
|
||||||
if (version === "latest") {
|
|
||||||
throw new Error(
|
|
||||||
'Did not recognise "version: latest". Did you mean "version: linked"?',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const runnerImages = ["ubuntu-latest", "macos-latest", "windows-latest"];
|
|
||||||
const operatingSystems = checkSpecification.operatingSystems ?? [
|
|
||||||
"ubuntu",
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const operatingSystem of operatingSystems) {
|
|
||||||
const runnerImagesForOs = runnerImages.filter((image) =>
|
|
||||||
image.startsWith(operatingSystem),
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const runnerImage of runnerImagesForOs) {
|
|
||||||
matrix.push({
|
|
||||||
os: runnerImage,
|
|
||||||
version,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const useAllPlatformBundle = checkSpecification.useAllPlatformBundle
|
const useAllPlatformBundle = checkSpecification.useAllPlatformBundle
|
||||||
? checkSpecification.useAllPlatformBundle
|
? checkSpecification.useAllPlatformBundle
|
||||||
: "false";
|
: "false";
|
||||||
|
|
||||||
if (checkSpecification.analysisKinds) {
|
|
||||||
const newMatrix: Array<Record<string, any>> = [];
|
|
||||||
for (const matrixInclude of matrix) {
|
|
||||||
for (const analysisKind of checkSpecification.analysisKinds) {
|
|
||||||
newMatrix.push({
|
|
||||||
...matrixInclude,
|
|
||||||
"analysis-kinds": analysisKind,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
matrix = newMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine which languages or frameworks have to be installed.
|
// Determine which languages or frameworks have to be installed.
|
||||||
const setupInfo = getSetupSteps(checkSpecification);
|
const setupInfo = getSetupSteps(checkSpecification);
|
||||||
const workflowInputs = setupInfo.inputs;
|
const workflowInputs = setupInfo.inputs;
|
||||||
|
|||||||
Reference in New Issue
Block a user