-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
55 lines (49 loc) · 1.76 KB
/
index.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
51
52
53
54
55
const core = require('@actions/core');
const github = require('@actions/github');
import tablemark from 'tablemark';
const main = async () => {
const owner = github.context.repo.owner;
const repo = github.context.repo.repo;
const token = core.getInput('github-token', {
required: true,
});
const ignoreJobsRegex = core.getInput('ignore-jobs', {
required: false,
});
const checkRunTitle = core.getInput('check-run-title', {
required: true,
});
const checkRunName = core.getInput('check-run-name');
// see: https://octokit.github.io/rest.js/v18
// eslint-disable-next-line new-cap
const octokit = new github.getOctokit(token);
// see: https://octokit.github.io/rest.js/v18#actions-list-jobs-for-workflow-run
const response = await octokit.rest.actions.listJobsForWorkflowRun({
owner,
repo,
run_id: github.context.runId,
});
// FIXME: the current context doesn't have the numerical job ID, which makes
// it impossible to properly match to jobs returned from the API.
// Since we later match to only failed jobs, it's not a problem for now.
const filteredJobs = response.data.jobs.filter(
(job) => (job.status == 'completed' && (!ignoreJobsRegex ||
!job.name.match(ignoreJobsRegex))),
);
const failure = filteredJobs.some((job) => job.conclusion == 'failure');
// see: https://octokit.github.io/rest.js/v18#checks-create-check-run
await octokit.rest.checks.create({
owner,
repo,
name: checkRunName,
head_sha: github.context.payload.pull_request.head.sha,
status: 'completed',
conclusion: failure ? 'failure' : 'success',
output: {
title: checkRunTitle,
summary: tablemark(filteredJobs.map((job) =>
({name: job.name, conclusion: job.conclusion}))),
},
});
};
main();