diff --git a/src/actions-util.ts b/src/actions-util.ts index 38daf99c7..f6ee5c168 100644 --- a/src/actions-util.ts +++ b/src/actions-util.ts @@ -109,7 +109,7 @@ export const getCommitOid = async function ( export const determineMergeBaseCommitOid = async function (): Promise< string | undefined > { - if (process.env.GITHUB_EVENT_NAME !== "pull_request") { + if (workflowEventName() !== "pull_request") { return undefined; } @@ -821,9 +821,21 @@ export async function sendStatusReport( } } +export function workflowEventName() { + // If the original event is dynamic CODESCANNING_EVENT_NAME will contain the right info (push/pull_request) + if (process.env["GITHUB_EVENT_NAME"] === "dynamic") { + const value = process.env["CODESCANNING_EVENT_NAME"]; + if (value === undefined || value.length === 0) { + return process.env["GITHUB_EVENT_NAME"]; + } + return value + } + return process.env["GITHUB_EVENT_NAME"]; +} + // Was the workflow run triggered by a `push` event, for example as opposed to a `pull_request` event. function workflowIsTriggeredByPushEvent() { - return process.env["GITHUB_EVENT_NAME"] === "push"; + return workflowEventName() === "push"; } // Is dependabot the actor that triggered the current workflow run. diff --git a/src/trap-caching.ts b/src/trap-caching.ts index d5ae7d0da..295319788 100644 --- a/src/trap-caching.ts +++ b/src/trap-caching.ts @@ -91,7 +91,7 @@ export async function downloadTrapCaches( let baseSha = "unknown"; const eventPath = process.env.GITHUB_EVENT_PATH; if ( - process.env.GITHUB_EVENT_NAME === "pull_request" && + actionsUtil.workflowEventName() === "pull_request" && eventPath !== undefined ) { const event = JSON.parse(fs.readFileSync(path.resolve(eventPath), "utf-8")); diff --git a/src/upload-lib.ts b/src/upload-lib.ts index 5b483da9a..114b3d507 100644 --- a/src/upload-lib.ts +++ b/src/upload-lib.ts @@ -325,7 +325,7 @@ export function buildPayload( gitHubVersion.type !== util.GitHubVariant.GHES || semver.satisfies(gitHubVersion.version, `>=3.1`) ) { - if (process.env.GITHUB_EVENT_NAME === "pull_request") { + if (actionsUtil.workflowEventName() === "pull_request") { if ( commitOid === util.getRequiredEnvParam("GITHUB_SHA") && mergeBaseCommitOid