-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
input.ts
55 lines (53 loc) · 1.73 KB
/
input.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
export interface Input {
githubToken: string;
owner: string;
repo: string;
branch: string;
workflowName: string;
runId: number;
pollIntervalSeconds: number;
continueAfterSeconds: number | undefined;
abortAfterSeconds: number | undefined;
sameBranchOnly: boolean;
initialWaitSeconds: number;
}
export const parseInput = (env: Record<string, string | undefined>): Input => {
const githubToken = env["INPUT_TOKEN"] || "";
const [owner, repo] = (env.GITHUB_REPOSITORY || "").split("/");
const workflowName = env.GITHUB_WORKFLOW || "";
const branch =
env.GITHUB_HEAD_REF || env.GITHUB_REF?.substring(11) || "master";
const runId = parseInt(env.GITHUB_RUN_ID || "0", 10);
const pollIntervalSeconds = env["INPUT_POLL-INTERVAL-SECONDS"]
? parseInt(env["INPUT_POLL-INTERVAL-SECONDS"], 10)
: 60;
const continueAfterSeconds = env["INPUT_CONTINUE-AFTER-SECONDS"]
? parseInt(env["INPUT_CONTINUE-AFTER-SECONDS"], 10)
: undefined;
const abortAfterSeconds = env["INPUT_ABORT-AFTER-SECONDS"]
? parseInt(env["INPUT_ABORT-AFTER-SECONDS"], 10)
: undefined;
if (continueAfterSeconds !== undefined && abortAfterSeconds !== undefined) {
throw new Error(
"Only one of continue-after-seconds and abort-after-seconds may be defined",
);
}
const initialWaitSeconds = env["INPUT_INITIAL-WAIT-SECONDS"]
? parseInt(env["INPUT_INITIAL-WAIT-SECONDS"], 10)
: 0;
const sameBranchOnly =
env["INPUT_SAME-BRANCH-ONLY"] === "true" || !env["INPUT_SAME-BRANCH-ONLY"]; // true if not specified
return {
githubToken,
owner,
repo,
branch,
workflowName,
runId,
pollIntervalSeconds,
continueAfterSeconds,
abortAfterSeconds,
sameBranchOnly,
initialWaitSeconds,
};
};