Add workflowEventName

This commit is contained in:
David Verdeguer 2022-09-07 00:05:40 +02:00
parent 8cdb7d8545
commit add14375d5
3 changed files with 16 additions and 4 deletions

View file

@ -109,7 +109,7 @@ export const getCommitOid = async function (
export const determineMergeBaseCommitOid = async function (): Promise< export const determineMergeBaseCommitOid = async function (): Promise<
string | undefined string | undefined
> { > {
if (process.env.GITHUB_EVENT_NAME !== "pull_request") { if (workflowEventName() !== "pull_request") {
return undefined; return undefined;
} }
@ -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. // Was the workflow run triggered by a `push` event, for example as opposed to a `pull_request` event.
function workflowIsTriggeredByPushEvent() { function workflowIsTriggeredByPushEvent() {
return process.env["GITHUB_EVENT_NAME"] === "push"; return workflowEventName() === "push";
} }
// Is dependabot the actor that triggered the current workflow run. // Is dependabot the actor that triggered the current workflow run.

View file

@ -91,7 +91,7 @@ export async function downloadTrapCaches(
let baseSha = "unknown"; let baseSha = "unknown";
const eventPath = process.env.GITHUB_EVENT_PATH; const eventPath = process.env.GITHUB_EVENT_PATH;
if ( if (
process.env.GITHUB_EVENT_NAME === "pull_request" && actionsUtil.workflowEventName() === "pull_request" &&
eventPath !== undefined eventPath !== undefined
) { ) {
const event = JSON.parse(fs.readFileSync(path.resolve(eventPath), "utf-8")); const event = JSON.parse(fs.readFileSync(path.resolve(eventPath), "utf-8"));

View file

@ -325,7 +325,7 @@ export function buildPayload(
gitHubVersion.type !== util.GitHubVariant.GHES || gitHubVersion.type !== util.GitHubVariant.GHES ||
semver.satisfies(gitHubVersion.version, `>=3.1`) semver.satisfies(gitHubVersion.version, `>=3.1`)
) { ) {
if (process.env.GITHUB_EVENT_NAME === "pull_request") { if (actionsUtil.workflowEventName() === "pull_request") {
if ( if (
commitOid === util.getRequiredEnvParam("GITHUB_SHA") && commitOid === util.getRequiredEnvParam("GITHUB_SHA") &&
mergeBaseCommitOid mergeBaseCommitOid