Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
feat: adding option to pass in if test step failed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
James-Frowen committed Dec 26, 2023
1 parent 8cf8aa9 commit 3463dbc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 19 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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
Expand All @@ -42,14 +49,19 @@ async function run(): Promise<void> {
}

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

0 comments on commit 3463dbc

Please sign in to comment.