2020-05-19 21:00:21 +08:00
|
|
|
const core = require('@actions/core');
|
|
|
|
|
const github = require('@actions/github');
|
|
|
|
|
const { parseTestReports } = require('./utils.js');
|
|
|
|
|
|
|
|
|
|
const action = async () => {
|
2020-10-15 23:01:37 +08:00
|
|
|
const reportPaths = core.getInput('report_paths').split(',').join('\n');
|
2020-05-19 21:00:21 +08:00
|
|
|
core.info(`Going to parse results form ${reportPaths}`);
|
|
|
|
|
const githubToken = core.getInput('github_token');
|
|
|
|
|
const name = core.getInput('check_name');
|
2020-08-15 16:43:48 +08:00
|
|
|
const commit = core.getInput('commit');
|
2020-10-16 05:21:14 +08:00
|
|
|
const failOnFailedTests = core.getInput('fail_on_test_failures') === 'true';
|
|
|
|
|
const failIfNoTests = core.getInput('fail_if_no_tests') === 'true';
|
2020-05-19 21:00:21 +08:00
|
|
|
|
|
|
|
|
let { count, skipped, annotations } = await parseTestReports(reportPaths);
|
|
|
|
|
const foundResults = count > 0 || skipped > 0;
|
|
|
|
|
const title = foundResults
|
|
|
|
|
? `${count} tests run, ${skipped} skipped, ${annotations.length} failed.`
|
|
|
|
|
: 'No test results found!';
|
|
|
|
|
core.info(`Result: ${title}`);
|
|
|
|
|
|
2020-05-22 18:17:14 +08:00
|
|
|
const pullRequest = github.context.payload.pull_request;
|
2020-10-16 05:21:14 +08:00
|
|
|
const link = (pullRequest && pullRequest.html_url) || github.context.ref;
|
|
|
|
|
const conclusion =
|
|
|
|
|
(foundResults && annotations.length === 0) || (!foundResults && !failIfNoTests)
|
|
|
|
|
? 'success'
|
|
|
|
|
: 'failure';
|
2020-05-19 21:00:21 +08:00
|
|
|
const status = 'completed';
|
2020-10-16 05:21:14 +08:00
|
|
|
const head_sha = commit || (pullRequest && pullRequest.head.sha) || github.context.sha;
|
2020-05-19 21:00:21 +08:00
|
|
|
core.info(
|
2020-05-22 18:17:14 +08:00
|
|
|
`Posting status '${status}' with conclusion '${conclusion}' to ${link} (sha: ${head_sha})`
|
2020-05-19 21:00:21 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const createCheckRequest = {
|
|
|
|
|
...github.context.repo,
|
|
|
|
|
name,
|
|
|
|
|
head_sha,
|
|
|
|
|
status,
|
|
|
|
|
conclusion,
|
|
|
|
|
output: {
|
|
|
|
|
title,
|
|
|
|
|
summary: '',
|
|
|
|
|
annotations: annotations.slice(0, 50)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
core.debug(JSON.stringify(createCheckRequest, null, 2));
|
|
|
|
|
|
2020-10-15 21:09:39 +08:00
|
|
|
// make conclusion consumable by downstream actions
|
|
|
|
|
core.setOutput('conclusion', conclusion);
|
|
|
|
|
|
2020-05-19 21:00:21 +08:00
|
|
|
const octokit = new github.GitHub(githubToken);
|
|
|
|
|
await octokit.checks.create(createCheckRequest);
|
2020-10-15 21:09:39 +08:00
|
|
|
|
|
|
|
|
// optionally fail the action if tests fail
|
2020-10-16 05:21:14 +08:00
|
|
|
if (failOnFailedTests && conclusion !== 'success') {
|
2020-10-15 21:09:39 +08:00
|
|
|
core.setFailed(`There were ${annotations.length} failed tests`);
|
|
|
|
|
}
|
2020-05-19 21:00:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = action;
|