mirror of
https://github.com/github/codeql-action.git
synced 2026-10-21 02:01:27 +00:00
Add actions-util.getAutomationID()
This commit is contained in:
20
lib/actions-util.js
generated
20
lib/actions-util.js
generated
@@ -354,6 +354,26 @@ async function getAnalysisKey() {
|
||||
return analysisKey;
|
||||
}
|
||||
exports.getAnalysisKey = getAnalysisKey;
|
||||
async function getAutomationID() {
|
||||
let automationID = `${await getAnalysisKey()}/`;
|
||||
const environment = getOptionalInput("matrix");
|
||||
// the id has to be deterministic so we sort the fields
|
||||
if (environment !== undefined && environment !== "null") {
|
||||
const environmentObject = JSON.parse(environment);
|
||||
for (const entry of Object.entries(environmentObject).sort()) {
|
||||
if (typeof entry[1] === "string") {
|
||||
automationID += `${entry[0]}:${entry[1]}/`;
|
||||
}
|
||||
else {
|
||||
// In code scanning we just handle the string values,
|
||||
// the rest get converted to the empty string
|
||||
automationID += `${entry[0]}:/`;
|
||||
}
|
||||
}
|
||||
}
|
||||
return automationID;
|
||||
}
|
||||
exports.getAutomationID = getAutomationID;
|
||||
/**
|
||||
* Get the ref currently being analyzed.
|
||||
*/
|
||||
|
||||
File diff suppressed because one or more lines are too long
27
lib/actions-util.test.js
generated
27
lib/actions-util.test.js
generated
@@ -64,6 +64,33 @@ ava_1.default("getAnalysisKey() when a local run", async (t) => {
|
||||
const actualAnalysisKey = await actionsutil.getAnalysisKey();
|
||||
t.deepEqual(actualAnalysisKey, "LOCAL-RUN:UNKNOWN-JOB");
|
||||
});
|
||||
ava_1.default("getAutomationID() when a local run", async (t) => {
|
||||
process.env.CODEQL_LOCAL_RUN = "true";
|
||||
process.env.CODEQL_ACTION_ANALYSIS_KEY = "";
|
||||
// TODO: setup the matrix as an input
|
||||
process.env.MATRIX = '{"language": "javascript", "os": "linux"}';
|
||||
actionsutil.prepareLocalRunEnvironment();
|
||||
// TODO: uncomment once the matrix is setup
|
||||
// const actualAutomationID = await actionsutil.getAutomationID();
|
||||
// t.deepEqual(actualAutomationID, "LOCAL-RUN:UNKNOWN-JOB/language:javascript/os:linux/");
|
||||
// check the environment sorting
|
||||
process.env.MATRIX = '{"os": "linux", "language": "javascript"}';
|
||||
actionsutil.prepareLocalRunEnvironment();
|
||||
// TODO: uncomment once the matrix is setup
|
||||
// const actualAutomationID = await actionsutil.getAutomationID();
|
||||
// t.deepEqual(actualAutomationID, "LOCAL-RUN:UNKNOWN-JOB/language:javascript/os:linux/");
|
||||
// check that an empty environment produces the right results
|
||||
process.env.MATRIX = "{}";
|
||||
actionsutil.prepareLocalRunEnvironment();
|
||||
const actualAutomationID = await actionsutil.getAutomationID();
|
||||
t.deepEqual(actualAutomationID, "LOCAL-RUN:UNKNOWN-JOB/");
|
||||
// check non string environment values
|
||||
process.env.MATRIX = '{"number": 1, "object": {"language": "javascript"}}';
|
||||
actionsutil.prepareLocalRunEnvironment();
|
||||
// TODO: uncomment once the matrix is setup
|
||||
// const actualAutomationID = await actionsutil.getAutomationID();
|
||||
// t.deepEqual(actualAutomationID, "LOCAL-RUN:UNKNOWN-JOB/number:/object:/");
|
||||
});
|
||||
ava_1.default("prepareEnvironment() when a local run", (t) => {
|
||||
process.env.CODEQL_LOCAL_RUN = "false";
|
||||
process.env.GITHUB_JOB = "YYY";
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user