This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
forked from mikepenz/action-junit-report-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.js
50 lines (43 loc) · 1.68 KB
/
action.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const core = require('@actions/core');
const github = require('@actions/github');
const { Octokit } = require("@octokit/rest");
const { parseTestReports } = require('./utils.js');
const action = async () => {
const reportPaths = core.getInput('report_paths');
core.info(`Going to parse results form ${reportPaths}`);
const githubToken = core.getInput('github_token');
const name = core.getInput('check_name');
const commit = core.getInput('commit');
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}`);
const pullRequest = github.context.payload.pull_request;
const link = pullRequest && pullRequest.html_url || github.context.ref;
const conclusion = annotations.length === 0 ? 'success' : 'failure';
const status = 'completed';
const head_sha = commit || pullRequest && pullRequest.head.sha || github.context.sha;
core.info(
`Posting status '${status}' with conclusion '${conclusion}' to ${link} (sha: ${head_sha})`
);
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));
const octokit = new Octokit({
auth: githubToken,
});
await octokit.checks.create(createCheckRequest);
};
module.exports = action;