generated from actions/typescript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
runner.ts
107 lines (98 loc) · 2.17 KB
/
runner.ts
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import * as path from "path";
import * as exec from "@actions/exec";
interface Options {
token: string;
profile: string;
parallel: boolean;
parallel_finished: boolean;
flag_name: string;
working_directory: string;
ignore: string;
}
export async function goveralls(options: Options) {
if (options.parallel_finished) {
await finish(options);
} else {
await run(options);
}
}
// copy environment values related to Go
const go_environment_values = [
"PATH",
"GOROOT",
"GOPATH",
"GOBIN",
"GOTMPDIR",
"GOTOOLDIR",
"GOOS",
"GOARCH",
// GOCACHE and fall back directories
"GOCACHE",
"LocalAppData",
"HOME",
"XDG_CACHE_HOME",
// GitHub events information
"GITHUB_WORKFLOW",
"GITHUB_RUN_ID",
"GITHUB_RUN_NUMBER",
"GITHUB_ACTION",
"GITHUB_ACTIONS",
"GITHUB_ACTOR",
"GITHUB_REPOSITORY",
"GITHUB_EVENT_NAME",
"GITHUB_EVENT_PATH",
"GITHUB_WORKSPACE",
"GITHUB_SHA",
"GITHUB_REF",
"GITHUB_HEAD_REF",
"GITHUB_BASE_REF",
];
async function run(options: Options) {
const env = {
COVERALLS_TOKEN: options.token,
};
for (const name of go_environment_values) {
const value = process.env[name];
if (value) {
env[name] = value;
}
}
const args = [
`-coverprofile=${options.profile}`,
"-service=github",
`-ignore=${options.ignore}`,
];
if (options.parallel) {
args.push("-parallel");
if (options.flag_name !== "") {
args.push(`-flagname=${options.flag_name}`);
}
}
await exec.exec(get_goveralls_path(), args, {
env: env,
cwd: options.working_directory,
});
}
async function finish(options: Options) {
const env = {
COVERALLS_TOKEN: options.token,
};
for (const name of go_environment_values) {
const value = process.env[name];
if (value) {
env[name] = value;
}
}
const args = ["-parallel-finish", "-service=github"];
await exec.exec(get_goveralls_path(), args, {
env: env,
cwd: options.working_directory,
});
}
function get_goveralls_path(): string {
const name =
process.platform === "win32"
? "goveralls_windows_amd64.exe"
: `goveralls_${process.platform}_amd64`;
return path.join(__dirname, "..", "bin", name);
}