From 28629bfb38fe9476f141610afbda5da879328654 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Sat, 1 Jun 2024 04:40:01 +0900 Subject: [PATCH] Better logger for each summary --- dist/index.js | 12 ++++++------ src/main.ts | 12 ++++-------- src/report.test.ts | 1 + src/report.ts | 10 +++++++--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/dist/index.js b/dist/index.js index bc94a8f2..41e931db 100644 --- a/dist/index.js +++ b/dist/index.js @@ -32333,8 +32333,10 @@ async function fetchChecks(token, trigger) { import { join, relative } from "path"; function summarize(check, trigger) { const { checkRun: run2, checkSuite: suite, workflow, workflowRun } = check; + const acceptable = run2.conclusion == "SUCCESS" || run2.conclusion === "SKIPPED" || run2.conclusion === "NEUTRAL" && (suite.conclusion === "SUCCESS" || suite.conclusion === "SKIPPED"); return { - acceptable: run2.conclusion == "SUCCESS" || run2.conclusion === "SKIPPED" || run2.conclusion === "NEUTRAL" && (suite.conclusion === "SUCCESS" || suite.conclusion === "SKIPPED"), + acceptable, + severity: acceptable ? run2.status === "COMPLETED" ? "notice" : "warning" : "error", workflowBasename: relative(`/${trigger.owner}/${trigger.repo}/actions/workflows/`, workflow.resourcePath), // Another file can set same workflow name. So you should filter workfrows from runId or the filename isSameWorkflow: suite.workflowRun?.databaseId === trigger.runId, @@ -32554,19 +32556,17 @@ async function run() { ); for (const summary of report.summaries) { const { - acceptable, - checkSuiteStatus, - checkSuiteConclusion, runStatus, runConclusion, jobName, workflowBasename, checkRunUrl, - eventName + eventName, + severity } = summary; const nullStr = "(null)"; (0, import_core3.info)( - `${workflowBasename}(${colorize(acceptable ? "notice" : "error", `${jobName}`)}): [suiteStatus: ${checkSuiteStatus}][suiteConclusion: ${checkSuiteConclusion ?? nullStr}][runStatus: ${runStatus}][runConclusion: ${runConclusion ?? nullStr}][eventName: ${eventName}][runURL: ${checkRunUrl}]` + `${workflowBasename}(${colorize(severity, jobName)}): [eventName: ${eventName}][runStatus: ${runStatus}][runConclusion: ${runConclusion ?? nullStr}][runURL: ${checkRunUrl}]` ); } if ((0, import_core3.isDebug)()) { diff --git a/src/main.ts b/src/main.ts index 61086e4a..7de51272 100644 --- a/src/main.ts +++ b/src/main.ts @@ -83,26 +83,22 @@ async function run(): Promise { for (const summary of report.summaries) { const { - acceptable, - checkSuiteStatus, - checkSuiteConclusion, runStatus, runConclusion, jobName, workflowBasename, checkRunUrl, eventName, + severity, } = summary; const nullStr = '(null)'; info( `${workflowBasename}(${ - colorize(acceptable ? 'notice' : 'error', `${jobName}`) - }): [suiteStatus: ${checkSuiteStatus}][suiteConclusion: ${ - checkSuiteConclusion ?? nullStr - }][runStatus: ${runStatus}][runConclusion: ${ + colorize(severity, jobName) + }): [eventName: ${eventName}][runStatus: ${runStatus}][runConclusion: ${ runConclusion ?? nullStr - }][eventName: ${eventName}][runURL: ${checkRunUrl}]`, + }][runURL: ${checkRunUrl}]`, ); } diff --git a/src/report.test.ts b/src/report.test.ts index f9249067..84a8689c 100644 --- a/src/report.test.ts +++ b/src/report.test.ts @@ -21,6 +21,7 @@ const exampleSummary = Object.freeze( checkRunUrl: 'https://example.com', runStatus: 'IN_PROGRESS', runConclusion: 'FAILURE', + severity: 'error', } satisfies Summary, ); diff --git a/src/report.ts b/src/report.ts index 5510ab11..8c70b7cf 100644 --- a/src/report.ts +++ b/src/report.ts @@ -5,6 +5,7 @@ import { Temporal } from 'temporal-polyfill'; export interface Summary { acceptable: boolean; + severity: Severity; workflowBasename: string; isSameWorkflow: boolean; @@ -22,10 +23,13 @@ export interface Summary { function summarize(check: Check, trigger: Trigger): Summary { const { checkRun: run, checkSuite: suite, workflow, workflowRun } = check; + const acceptable = (run.conclusion == 'SUCCESS') + || (run.conclusion === 'SKIPPED') + || (run.conclusion === 'NEUTRAL' && (suite.conclusion === 'SUCCESS' || suite.conclusion === 'SKIPPED')); + return { - acceptable: run.conclusion == 'SUCCESS' || run.conclusion === 'SKIPPED' - || (run.conclusion === 'NEUTRAL' - && (suite.conclusion === 'SUCCESS' || suite.conclusion === 'SKIPPED')), + acceptable, + severity: acceptable ? (run.status === 'COMPLETED' ? 'notice' : 'warning') : 'error', workflowBasename: relative(`/${trigger.owner}/${trigger.repo}/actions/workflows/`, workflow.resourcePath), // Another file can set same workflow name. So you should filter workfrows from runId or the filename isSameWorkflow: suite.workflowRun?.databaseId === trigger.runId,