Add actions-util.getAutomationID()
This commit is contained in:
parent
c6e734ccc5
commit
519d0771c7
6 changed files with 102 additions and 2 deletions
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
|
|
@ -73,6 +73,38 @@ test("getAnalysisKey() when a local run", async (t) => {
|
|||
t.deepEqual(actualAnalysisKey, "LOCAL-RUN:UNKNOWN-JOB");
|
||||
});
|
||||
|
||||
test("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:/");
|
||||
});
|
||||
|
||||
test("prepareEnvironment() when a local run", (t) => {
|
||||
process.env.CODEQL_LOCAL_RUN = "false";
|
||||
process.env.GITHUB_JOB = "YYY";
|
||||
|
|
|
|||
|
|
@ -425,6 +425,27 @@ export async function getAnalysisKey(): Promise<string> {
|
|||
return analysisKey;
|
||||
}
|
||||
|
||||
export async function getAutomationID(): Promise<string> {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ref currently being analyzed.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue