-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
39 lines (36 loc) · 1.25 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
import fs from "fs/promises";
import {exec} from "child_process";
import {promisify} from "util";
import generateFancyReport from "./gen.js";
if (!process.env.GITHUB_WORKSPACE) {
await fs.access("./clone").catch(e => {
if (e.code !== "ENOENT") throw e;
return promisify(exec)("git clone --depth 1 --branch master https://github.com/ScratchAddons/ScratchAddons.git clone");
});
}
await promisify(exec)("npx tap --no-coverage -R json ./test/*.js > ./taptest.json").catch(e => e);
const parsedResult = JSON.parse(await fs.readFile("./taptest.json", "utf8"));
if (parsedResult.stats.failures === 0) {
console.log("Test passed successfully.");
process.exit(0);
}
process.exitCode = 1;
const report = generateFancyReport(parsedResult);
if (process.env.CI || process.env.HOT_RUN) {
const {Octokit} = await import("octokit");
const octokit = new Octokit({
auth: process.env.GH_TOKEN,
userAgent: "unittest for ScratchAddons (via octokit)"
});
octokit.rest.issues.create({
...report,
owner: "ScratchAddons",
repo: "ScratchAddons",
labels: ["status: needs triage", "scope: test failure", "type: bug"]
});
console.error("Test failed; created issue");
} else {
console.log(report.title);
console.log("\n\n");
console.log(report.body);
}