Adds ref and SHA as inputs, and sarif-id as output
This commit is contained in:
parent
e9aa2c6f62
commit
980fd4ed38
7 changed files with 51 additions and 6 deletions
|
|
@ -65,6 +65,24 @@ test("getRef() returns head PR ref if GITHUB_REF no longer checked out", async (
|
|||
callback.restore();
|
||||
});
|
||||
|
||||
test("getRef() returns ref provided as an input and ignores current HEAD", async (t) => {
|
||||
const getAdditionalInputStub = sinon.stub(actionsutil, "getOptionalInput");
|
||||
getAdditionalInputStub.withArgs("ref").resolves("refs/pull/2/merge");
|
||||
getAdditionalInputStub.withArgs("sha").resolves("b".repeat(40));
|
||||
|
||||
// These values are be ignored
|
||||
process.env["GITHUB_REF"] = "refs/pull/1/merge";
|
||||
process.env["GITHUB_SHA"] = "a".repeat(40);
|
||||
|
||||
const callback = sinon.stub(actionsutil, "getCommitOid");
|
||||
callback.withArgs("refs/pull/1/merge").resolves("b".repeat(40));
|
||||
callback.withArgs("HEAD").resolves("b".repeat(40));
|
||||
|
||||
const actualRef = await actionsutil.getRef();
|
||||
t.deepEqual(actualRef, "refs/pull/2/head");
|
||||
callback.restore();
|
||||
});
|
||||
|
||||
test("computeAutomationID()", async (t) => {
|
||||
let actualAutomationID = actionsutil.computeAutomationID(
|
||||
".github/workflows/codeql-analysis.yml:analyze",
|
||||
|
|
|
|||
|
|
@ -83,10 +83,10 @@ export const getCommitOid = async function (ref = "HEAD"): Promise<string> {
|
|||
return commitOid.trim();
|
||||
} catch (e) {
|
||||
core.info(
|
||||
`Failed to call git to get current commit. Continuing with data from environment: ${e}`
|
||||
`Failed to call git to get current commit. Continuing with data from environment or input: ${e}`
|
||||
);
|
||||
core.info((e as Error).stack || "NO STACK");
|
||||
return getRequiredEnvParam("GITHUB_SHA");
|
||||
return getOptionalInput("sha") || getRequiredEnvParam("GITHUB_SHA");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -431,8 +431,15 @@ export function computeAutomationID(
|
|||
export async function getRef(): Promise<string> {
|
||||
// Will be in the form "refs/heads/master" on a push event
|
||||
// or in the form "refs/pull/N/merge" on a pull_request event
|
||||
const ref = getRequiredEnvParam("GITHUB_REF");
|
||||
const sha = getRequiredEnvParam("GITHUB_SHA");
|
||||
const refInput = getOptionalInput("ref");
|
||||
const ref = refInput || getRequiredEnvParam("GITHUB_REF");
|
||||
const sha = getOptionalInput("sha") || getRequiredEnvParam("GITHUB_SHA");
|
||||
|
||||
// If the ref is a user-provided input, we have to skip logic
|
||||
// and assume that it is really where they want to upload the results.
|
||||
if (refInput) {
|
||||
return refInput;
|
||||
}
|
||||
|
||||
// For pull request refs we want to detect whether the workflow
|
||||
// has run `git checkout HEAD^2` to analyze the 'head' ref rather
|
||||
|
|
@ -520,7 +527,7 @@ export async function createStatusReportBase(
|
|||
cause?: string,
|
||||
exception?: string
|
||||
): Promise<StatusReportBase> {
|
||||
const commitOid = process.env["GITHUB_SHA"] || "";
|
||||
const commitOid = getOptionalInput("sha") || process.env["GITHUB_SHA"] || "";
|
||||
const ref = await getRef();
|
||||
const workflowRunIDStr = process.env["GITHUB_RUN_ID"];
|
||||
let workflowRunID = -1;
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ async function run() {
|
|||
apiDetails,
|
||||
logger
|
||||
);
|
||||
core.setOutput('sarif-id', uploadResult.sarifID);
|
||||
} else {
|
||||
logger.info("Not uploading results");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ async function run() {
|
|||
apiDetails,
|
||||
getActionsLogger()
|
||||
);
|
||||
core.setOutput('sarif-id', uploadResult.sarifID);
|
||||
if (actionsUtil.getRequiredInput("wait-for-processing") === "true") {
|
||||
await upload_lib.waitForProcessing(
|
||||
parseRepositoryNwo(getRequiredEnvParam("GITHUB_REPOSITORY")),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue