Skip to content

Commit add1437

Browse files
committed
Add workflowEventName
1 parent 8cdb7d8 commit add1437

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/actions-util.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const getCommitOid = async function (
109109
export const determineMergeBaseCommitOid = async function (): Promise<
110110
string | undefined
111111
> {
112-
if (process.env.GITHUB_EVENT_NAME !== "pull_request") {
112+
if (workflowEventName() !== "pull_request") {
113113
return undefined;
114114
}
115115

@@ -821,9 +821,21 @@ export async function sendStatusReport<S extends StatusReportBase>(
821821
}
822822
}
823823

824+
export function workflowEventName() {
825+
// If the original event is dynamic CODESCANNING_EVENT_NAME will contain the right info (push/pull_request)
826+
if (process.env["GITHUB_EVENT_NAME"] === "dynamic") {
827+
const value = process.env["CODESCANNING_EVENT_NAME"];
828+
if (value === undefined || value.length === 0) {
829+
return process.env["GITHUB_EVENT_NAME"];
830+
}
831+
return value
832+
}
833+
return process.env["GITHUB_EVENT_NAME"];
834+
}
835+
824836
// Was the workflow run triggered by a `push` event, for example as opposed to a `pull_request` event.
825837
function workflowIsTriggeredByPushEvent() {
826-
return process.env["GITHUB_EVENT_NAME"] === "push";
838+
return workflowEventName() === "push";
827839
}
828840

829841
// Is dependabot the actor that triggered the current workflow run.

src/trap-caching.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export async function downloadTrapCaches(
9191
let baseSha = "unknown";
9292
const eventPath = process.env.GITHUB_EVENT_PATH;
9393
if (
94-
process.env.GITHUB_EVENT_NAME === "pull_request" &&
94+
actionsUtil.workflowEventName() === "pull_request" &&
9595
eventPath !== undefined
9696
) {
9797
const event = JSON.parse(fs.readFileSync(path.resolve(eventPath), "utf-8"));

src/upload-lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export function buildPayload(
325325
gitHubVersion.type !== util.GitHubVariant.GHES ||
326326
semver.satisfies(gitHubVersion.version, `>=3.1`)
327327
) {
328-
if (process.env.GITHUB_EVENT_NAME === "pull_request") {
328+
if (actionsUtil.workflowEventName() === "pull_request") {
329329
if (
330330
commitOid === util.getRequiredEnvParam("GITHUB_SHA") &&
331331
mergeBaseCommitOid

0 commit comments

Comments
 (0)