Skip to content

Commit

Permalink
Better logger for each summary
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed May 31, 2024
1 parent 5a5f356 commit 28629bf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
12 changes: 6 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)()) {
Expand Down
12 changes: 4 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,22 @@ async function run(): Promise<void> {

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}]`,
);
}

Expand Down
1 change: 1 addition & 0 deletions src/report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const exampleSummary = Object.freeze(
checkRunUrl: 'https://example.com',
runStatus: 'IN_PROGRESS',
runConclusion: 'FAILURE',
severity: 'error',
} satisfies Summary,
);

Expand Down
10 changes: 7 additions & 3 deletions src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Temporal } from 'temporal-polyfill';

export interface Summary {
acceptable: boolean;
severity: Severity;
workflowBasename: string;
isSameWorkflow: boolean;

Expand All @@ -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,
Expand Down

0 comments on commit 28629bf

Please sign in to comment.