| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 708446c commit 1f8caea
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ## [UNRELEASED] | |
| 4 | 4 | ||
| 5 | - No user facing changes. | ||
| 5 | + - Add sarif-id as an output for upload-sarif action and analyze action (if uploading) | ||
| 6 | + - Accept ref and hash as inputs to override the ones provided by the runner | ||
| 6 | 7 | ||
| 7 | 8 | ## 1.0.30 - 24 Jan 2022 | |
| 8 | 9 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,12 @@ inputs: | |||
| 45 | 45 | description: "The path at which the analyzed repository was checked out. Used to relativize any absolute paths in the uploaded SARIF file." | |
| 46 | 46 | required: false | |
| 47 | 47 | default: ${{ github.workspace }} | |
| 48 | + ref: | ||
| 49 | + description: "The ref where results will be uploaded. If not provided, the Action will use the GITHUB_REF environment variable." | ||
| 50 | + required: false | ||
| 51 | + sha: | ||
| 52 | + description: "The hash of the HEAD of the ref where results will be uploaded. If not provided, the Action will use the GITHUB_SHA environment variable." | ||
| 53 | + required: false | ||
| 48 | 54 | category: | |
| 49 | 55 | description: String used by Code Scanning for matching the analyses | |
| 50 | 56 | required: false | |
@@ -63,6 +69,8 @@ inputs: | |||
| 63 | 69 | outputs: | |
| 64 | 70 | db-locations: | |
| 65 | 71 | description: A map from language to absolute path for each database created by CodeQL. | |
| 72 | + sarif-id: | ||
| 73 | + description: The ID of the uploaded sarif file. | ||
| 66 | 74 | runs: | |
| 67 | 75 | using: "node12" | |
| 68 | 76 | main: "../lib/analyze-action.js" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,6 +65,24 @@ test("getRef() returns head PR ref if GITHUB_REF no longer checked out", async ( | |||
| 65 | 65 | callback.restore(); | |
| 66 | 66 | }); | |
| 67 | 67 | ||
| 68 | + test("getRef() returns ref provided as an input and ignores current HEAD", async (t) => { | ||
| 69 | + const getAdditionalInputStub = sinon.stub(actionsutil, "getOptionalInput"); | ||
| 70 | + getAdditionalInputStub.withArgs("ref").resolves("refs/pull/2/merge"); | ||
| 71 | + getAdditionalInputStub.withArgs("sha").resolves("b".repeat(40)); | ||
| 72 | + | ||
| 73 | + // These values are be ignored | ||
| 74 | + process.env["GITHUB_REF"] = "refs/pull/1/merge"; | ||
| 75 | + process.env["GITHUB_SHA"] = "a".repeat(40); | ||
| 76 | + | ||
| 77 | + const callback = sinon.stub(actionsutil, "getCommitOid"); | ||
| 78 | + callback.withArgs("refs/pull/1/merge").resolves("b".repeat(40)); | ||
| 79 | + callback.withArgs("HEAD").resolves("b".repeat(40)); | ||
| 80 | + | ||
| 81 | + const actualRef = await actionsutil.getRef(); | ||
| 82 | + t.deepEqual(actualRef, "refs/pull/2/head"); | ||
| 83 | + callback.restore(); | ||
| 84 | + }); | ||
| 85 | + | ||
| 68 | 86 | test("computeAutomationID()", async (t) => { | |
| 69 | 87 | let actualAutomationID = actionsutil.computeAutomationID( | |
| 70 | 88 | ".github/workflows/codeql-analysis.yml:analyze", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,10 +83,10 @@ export const getCommitOid = async function (ref = "HEAD"): Promise<string> { | |||
| 83 | 83 | return commitOid.trim(); | |
| 84 | 84 | } catch (e) { | |
| 85 | 85 | core.info( | |
| 86 | - `Failed to call git to get current commit. Continuing with data from environment: ${e}` | ||
| 86 | + `Failed to call git to get current commit. Continuing with data from environment or input: ${e}` | ||
| 87 | 87 | ); | |
| 88 | 88 | core.info((e as Error).stack || "NO STACK"); | |
| 89 | - return getRequiredEnvParam("GITHUB_SHA"); | ||
| 89 | + return getOptionalInput("sha") || getRequiredEnvParam("GITHUB_SHA"); | ||
| 90 | 90 | } | |
| 91 | 91 | }; | |
| 92 | 92 | ||
@@ -431,8 +431,15 @@ export function computeAutomationID( | |||
| 431 | 431 | export async function getRef(): Promise<string> { | |
| 432 | 432 | // Will be in the form "refs/heads/master" on a push event | |
| 433 | 433 | // or in the form "refs/pull/N/merge" on a pull_request event | |
| 434 | - const ref = getRequiredEnvParam("GITHUB_REF"); | ||
| 435 | - const sha = getRequiredEnvParam("GITHUB_SHA"); | ||
| 434 | + const refInput = getOptionalInput("ref"); | ||
| 435 | + const ref = refInput || getRequiredEnvParam("GITHUB_REF"); | ||
| 436 | + const sha = getOptionalInput("sha") || getRequiredEnvParam("GITHUB_SHA"); | ||
| 437 | + | ||
| 438 | + // If the ref is a user-provided input, we have to skip logic | ||
| 439 | + // and assume that it is really where they want to upload the results. | ||
| 440 | + if (refInput) { | ||
| 441 | + return refInput; | ||
| 442 | + } | ||
| 436 | 443 | ||
| 437 | 444 | // For pull request refs we want to detect whether the workflow | |
| 438 | 445 | // has run `git checkout HEAD^2` to analyze the 'head' ref rather | |
@@ -520,7 +527,7 @@ export async function createStatusReportBase( | |||
| 520 | 527 | cause?: string, | |
| 521 | 528 | exception?: string | |
| 522 | 529 | ): Promise<StatusReportBase> { | |
| 523 | - const commitOid = process.env["GITHUB_SHA"] || ""; | ||
| 530 | + const commitOid = getOptionalInput("sha") || process.env["GITHUB_SHA"] || ""; | ||
| 524 | 531 | const ref = await getRef(); | |
| 525 | 532 | const workflowRunIDStr = process.env["GITHUB_RUN_ID"]; | |
| 526 | 533 | let workflowRunID = -1; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -193,6 +193,7 @@ async function run() { | |||
| 193 | 193 | apiDetails, | |
| 194 | 194 | logger | |
| 195 | 195 | ); | |
| 196 | + core.setOutput('sarif-id', uploadResult.sarifID); | ||
| 196 | 197 | } else { | |
| 197 | 198 | logger.info("Not uploading results"); | |
| 198 | 199 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,7 @@ async function run() { | |||
| 63 | 63 | apiDetails, | |
| 64 | 64 | getActionsLogger() | |
| 65 | 65 | ); | |
| 66 | + core.setOutput('sarif-id', uploadResult.sarifID); | ||
| 66 | 67 | if (actionsUtil.getRequiredInput("wait-for-processing") === "true") { | |
| 67 | 68 | await upload_lib.waitForProcessing( | |
| 68 | 69 | parseRepositoryNwo(getRequiredEnvParam("GITHUB_REPOSITORY")), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,12 @@ inputs: | |||
| 13 | 13 | description: "The path at which the analyzed repository was checked out. Used to relativize any absolute paths in the uploaded SARIF file." | |
| 14 | 14 | required: false | |
| 15 | 15 | default: ${{ github.workspace }} | |
| 16 | + ref: | ||
| 17 | + description: "The ref where results will be uploaded. If not provided, the Action will use the GITHUB_REF environment variable." | ||
| 18 | + required: false | ||
| 19 | + sha: | ||
| 20 | + description: "The hash of the HEAD of the ref where results will be uploaded. If not provided, the Action will use the GITHUB_SHA environment variable." | ||
| 21 | + required: false | ||
| 16 | 22 | token: | |
| 17 | 23 | default: ${{ github.token }} | |
| 18 | 24 | matrix: | |
@@ -24,6 +30,9 @@ inputs: | |||
| 24 | 30 | description: If true, the Action will wait for the uploaded SARIF to be processed before completing. | |
| 25 | 31 | required: true | |
| 26 | 32 | default: "false" | |
| 33 | + outputs: | ||
| 34 | + sarif-id: | ||
| 35 | + description: The ID of the uploaded sarif file. | ||
| 27 | 36 | runs: | |
| 28 | 37 | using: 'node12' | |
| 29 | 38 | main: '../lib/upload-sarif-action.js' | |
| Back | FazBrowse Home | New Git URL |
0 commit comments