-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathci.js
77 lines (66 loc) · 1.98 KB
/
ci.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Octokit } from '@octokit/action';
import { mkdirSync } from 'node:fs';
import { join } from 'node:path/posix';
import { JSONFileMap } from 'utilium/fs.js';
const octokit = new Octokit();
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const head_sha = process.env.GITHUB_SHA;
mkdirSync(join(import.meta.dirname, '../tmp'), { recursive: true });
const checks = new JSONFileMap(join(import.meta.dirname, '../tmp/checks.json'));
/** Maps test names and shortcuts to full check names */
export const checkNames = {
// Basic ones
format: 'Formatting',
lint: 'Linting',
build: 'Build',
// Tests
'Common tests': 'Unit tests: common',
memory: 'Unit tests: InMemory',
context: 'Unit tests: contexts',
index: 'Unit tests: Index',
port: 'Unit tests: Port',
fetch: 'Unit tests: Fetch',
cow: 'Unit tests: Copy-On-Write',
'single-buffer': 'Unit tests: SingleBuffer',
};
/** Create a new GitHub check run */
export async function createCheck(id, name) {
const response = await octokit.request('POST /repos/{owner}/{repo}/check-runs', {
owner,
repo,
name,
head_sha,
status: 'queued',
started_at: new Date().toISOString(),
});
checks.set(id, { id: response.data.id, completed: false });
}
/**
* Move an existing check run from "queued" to "in_progress".
*/
export async function startCheck(id) {
const check = checks.get(id);
await octokit.request('PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}', {
owner,
repo,
check_run_id: check.id,
status: 'in_progress',
started_at: new Date().toISOString(),
});
}
/** Complete a check run */
export async function completeCheck(id, conclusion, title = '', summary = '') {
const check = checks.get(id);
if (check.completed) return;
await octokit.request('PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}', {
owner,
repo,
check_run_id: check.id,
status: 'completed',
completed_at: new Date().toISOString(),
conclusion,
output: { title, summary },
});
check.completed = true;
checks.set(id, check);
}