Improve logging & fix wrong SHA used

This commit is contained in:
Michal Dorner 2021-02-17 08:28:52 +01:00
parent c5671cf48a
commit 96237b3119
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
3 changed files with 7 additions and 3 deletions

View file

@ -10,6 +10,7 @@ const asyncStream = promisify(stream.pipeline)
export function getCheckRunContext(): {sha: string; runId: number} {
if (github.context.eventName === 'workflow_run') {
core.info('Action was triggered by workflow_run: using SHA and RUN_ID from triggering workflow')
const event = github.context.payload as EventPayloads.WebhookPayloadWorkflowRun
if (!event.workflow_run) {
throw new Error("Event of type 'workflow_run' is missing 'workflow_run' field")
@ -21,7 +22,8 @@ export function getCheckRunContext(): {sha: string; runId: number} {
}
const runId = github.context.runId
if (github.context.eventName === 'pullrequest' && github.context.payload.pull_request) {
if (github.context.payload.pull_request) {
core.info(`Action was triggered by ${github.context}: using SHA from head of source branch`)
const pr = github.context.payload.pull_request as EventPayloads.WebhookPayloadPullRequestPullRequest
return {sha: pr.head.sha, runId}
}