async function run()

in index.js [154:209]


async function run() {
    console.log("Running action")
    try {
        console.log("Checking this is a pull request")
        // Ensure this action is triggered within a PR context
        if (!context.payload.pull_request) {
            core.setFailed('This action must be triggered by a pull request')
            return
        }

        console.log(`owner: ${owner}, repo: ${repo}, pr: ${prNumber}`)


        console.log("Gathering workflow data...")
        // Get the current workflow run's ID and use it to fetch its details
        const start = workflowRef.indexOf("workflows/") + "workflows/".length
        const end = workflowRef.indexOf("@")
        const workflowPath = workflowRef.substring(start, end)

        console.log(`Gathering workflow runs for ${workflowPath}...`)
        const { data: runs } = await octokit.rest.actions.listWorkflowRuns({
            owner,
            repo,
            workflow_id: workflowPath,
            branch: mainBranch,
            status: 'completed',
        })

        const sortedRuns = runs.workflow_runs.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))
        const latestRun = sortedRuns[0]
        const flags = await getOverrideFlags()
        const overridden = await isWorkflowOverridden(flags)

        if (!latestRun) {
            console.log(`No run of this workflow found on ${mainBranch}, must be new.`)
            return
        }

        console.log("Creating, updating, or removing comment, as necessary")
        await updateStatusComment(overridden, latestRun.conclusion, latestRun?.html_url)

        if (latestRun.conclusion !== 'success') {
            let msg = `Latest run of workflow on ${mainBranch} branch is failing: ${latestRun?.html_url}`
            if (overridden) {
                console.log(msg)
                console.log("Override flag found, not failing the run.")
            } else {
                core.setFailed(msg)
            }
        } else {
            console.log(`Latest run of workflow on ${mainBranch} branch is successful: ${latestRun?.html_url}`)
        }
    } catch (error) {
        core.setFailed(`Action failed with error: ${error}`)
    }
}