Skip to content

Commit

Permalink
Add workflowEventName
Browse files Browse the repository at this point in the history
  • Loading branch information
David Verdeguer committed Sep 6, 2022
1 parent 8cdb7d8 commit add1437
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/actions-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -821,9 +821,21 @@ export async function sendStatusReport<S extends StatusReportBase>(
}
}

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.
Expand Down
2 changes: 1 addition & 1 deletion src/trap-caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
2 changes: 1 addition & 1 deletion src/upload-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit add1437

Please sign in to comment.