Add createCheck to display test results in GitHub UI

pull/97/head
David Finol 2021-02-22 23:47:51 -06:00
parent b3bcba9d25
commit 6a619e780c
6 changed files with 22 additions and 9 deletions

View File

@ -32,6 +32,10 @@ inputs:
required: false required: false
default: 'false' default: 'false'
description: 'Creates a check with the Test Results' description: 'Creates a check with the Test Results'
checkName:
required: false
default: 'Test Results'
description: 'Name for the check created when createCheck is true.'
githubToken: githubToken:
required: false required: false
default: '' default: ''

File diff suppressed because one or more lines are too long

View File

@ -13,6 +13,7 @@ async function action() {
artifactsPath, artifactsPath,
useHostNetwork, useHostNetwork,
createCheck, createCheck,
checkName,
githubToken, githubToken,
customParameters, customParameters,
} = Input.getFromUser(); } = Input.getFromUser();
@ -39,9 +40,9 @@ async function action() {
} }
if (createCheck) { if (createCheck) {
const fail = await ResultsCheck.publishResults(artifactsPath, githubToken); const fail = await ResultsCheck.publishResults(artifactsPath, checkName, githubToken);
if (fail > 0) { if (fail > 0) {
core.setFailed('Tests Failed! See Test Results for details.'); core.setFailed(`Tests Failed! Check ${checkName} for details.`);
} }
} }
} }

View File

@ -22,6 +22,7 @@ class Input {
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts'; const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
const rawUseHostNetwork = getInput('useHostNetwork') || 'false'; const rawUseHostNetwork = getInput('useHostNetwork') || 'false';
const rawCreateCheck = getInput('createCheck') || 'false'; const rawCreateCheck = getInput('createCheck') || 'false';
const checkName = getInput('checkName') || 'Test Results';
const githubToken = getInput('githubToken') || ''; const githubToken = getInput('githubToken') || '';
const customParameters = getInput('customParameters') || ''; // Validate input const customParameters = getInput('customParameters') || ''; // Validate input
if (!includes(this.testModes, testMode)) { if (!includes(this.testModes, testMode)) {
@ -57,6 +58,7 @@ class Input {
artifactsPath, artifactsPath,
useHostNetwork, useHostNetwork,
createCheck, createCheck,
checkName,
githubToken, githubToken,
customParameters, customParameters,
}; };

View File

@ -8,7 +8,7 @@ import ReportConverter from './report-converter';
import { RunMeta } from './ts/meta.ts'; import { RunMeta } from './ts/meta.ts';
class ResultsCheck { class ResultsCheck {
static async publishResults(artifactsPath, githubToken) { static async publishResults(artifactsPath, checkName, githubToken) {
// Parse all reports // Parse all reports
const runs = []; const runs = [];
const files = fs.readdirSync(artifactsPath); const files = fs.readdirSync(artifactsPath);
@ -41,7 +41,13 @@ class ResultsCheck {
core.info(runSummary.summary); core.info(runSummary.summary);
// Create check // Create check
await ResultsCheck.createCheck(githubToken, runs, runSummary, runSummary.extractAnnotations()); await ResultsCheck.createCheck(
checkName,
githubToken,
runs,
runSummary,
runSummary.extractAnnotations(),
);
return runSummary.failed; return runSummary.failed;
} }
@ -54,7 +60,7 @@ class ResultsCheck {
return ReportConverter.convertReport(path.basename(filepath), report); return ReportConverter.convertReport(path.basename(filepath), report);
} }
static async createCheck(githubToken, runs, runSummary, annotations) { static async createCheck(checkName, githubToken, runs, runSummary, annotations) {
const pullRequest = github.context.payload.pull_request; const pullRequest = github.context.payload.pull_request;
const headSha = (pullRequest && pullRequest.head.sha) || github.context.sha; const headSha = (pullRequest && pullRequest.head.sha) || github.context.sha;
@ -65,7 +71,7 @@ class ResultsCheck {
core.info(`Posting results for ${headSha}`); core.info(`Posting results for ${headSha}`);
const createCheckRequest = { const createCheckRequest = {
...github.context.repo, ...github.context.repo,
name: 'Test Results', name: checkName,
head_sha: headSha, head_sha: headSha,
status: 'completed', status: 'completed',
conclusion: 'neutral', conclusion: 'neutral',

View File

@ -78,7 +78,7 @@ export class RunMeta extends Meta {
get mark(): string { get mark(): string {
if (this.failed > 0) return '❌️'; if (this.failed > 0) return '❌️';
else if (this.skipped === 0) return '✔️'; else if (this.skipped === 0) return '';
return '⚠️'; return '⚠️';
} }
} }
@ -111,7 +111,7 @@ export class TestMeta extends Meta {
get mark(): string { get mark(): string {
if (this.isFailed()) return '❌️'; if (this.isFailed()) return '❌️';
else if (this.isSkipped()) return '⚠️'; else if (this.isSkipped()) return '⚠️';
return '✔️'; return '';
} }
} }