From 3463dbc770c993d665417a5eb328f86b4d4c96e2 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Tue, 26 Dec 2023 13:52:32 +0000 Subject: [PATCH] feat: adding option to pass in if test step failed giving a better message when test step fails to run also `results.passed === 0` doesn't seem to be true when step fails from compile error --- action.yml | 4 ++++ src/main.ts | 26 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index ae80475..6d0b019 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,10 @@ inputs: description: "Report title" required: false default: "Test Report" + failed: + description: "did the test step fail" + required: false + default: "false" runs: using: "node12" main: "dist/index.js" diff --git a/src/main.ts b/src/main.ts index adb494d..cecc545 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,26 +1,33 @@ import { setFailed, getInput } from "@actions/core"; import { GitHub, context } from "@actions/github"; -import { readResults, Annotation } from "./nunit"; +import { readResults, Annotation, TestResult } from "./nunit"; function generateSummary(annotation: Annotation): string { return `* ${annotation.title}\n ${annotation.message}`; } +function resultCount(results: TestResult, failed: boolean): string { + if (results.failed > 0) return `${results.failed} tests failed`; + + // failed without results, could be from compile error + if (failed) return `Failed to run tests`; + + return `${results.passed} tests passed`; +} + async function run(): Promise { try { const path = getInput("path"); const numFailures = parseInt(getInput("numFailures")); const accessToken = getInput("access-token"); const title = getInput("reportTitle"); + const failed = getInput("failed").toLowerCase() === "true"; const results = await readResults(path); const octokit = new GitHub(accessToken); - const summary = - results.failed > 0 - ? `${results.failed} tests failed` - : `${results.passed} tests passed`; + const summary = resultCount(results, failed); let details = results.failed === 0 @@ -42,14 +49,19 @@ async function run(): Promise { } const pr = context.payload.pull_request; + + const conclusion = + failed || results.failed > 0 || results.passed === 0 + ? "failure" + : "success"; + await octokit.checks.create({ head_sha: (pr && pr["head"] && pr["head"].sha) || context.sha, name: `Tests Report: ${title}`, owner: context.repo.owner, repo: context.repo.repo, status: "completed", - conclusion: - results.failed > 0 || results.passed === 0 ? "failure" : "success", + conclusion, output: { title, summary,