-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext.ts
More file actions
87 lines (72 loc) 路 2.1 KB
/
Copy pathcontext.ts
File metadata and controls
87 lines (72 loc) 路 2.1 KB
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
import { getInput } from "@actions/core";
export class Environment
{
public static GetVariable(name: string): string | undefined;
public static GetVariable(name: string, defaultValue: string): string;
public static GetVariable(name: string, defaultValue?: string)
{
const value = process.env[name];
if (value === undefined)
{
return defaultValue;
}
return value;
}
public readonly branchName: string;
public readonly commitSha: string;
public constructor()
{
this.branchName = Environment.GetVariable("GITHUB_REF_NAME")!;
this.commitSha = Environment.GetVariable("GITHUB_SHA")!;
}
}
export class Inputs
{
public static Get(name: string): string | undefined;
public static Get<T>(name: string, parser: (input: string) => T): T;
public static Get<T>(name: string, parser?: (input: string) => T)
{
const input = getInput(name);
if (parser !== undefined)
{
return parser(input);
}
return input ? input : undefined;
}
public readonly registry?: string;
public readonly repository: string;
public readonly shaLength: number;
public constructor()
{
this.registry = Inputs.Get("registry");
this.repository = Inputs.Get("repository")!;
this.shaLength = Inputs.Get("shaLength", (input) =>
{
const value = Number(input);
if (value < 1)
{
throw new Error("`shaLength` must be greater than 0.");
}
if (value > 39)
{
throw new Error("`shaLength` must be less than 40.");
}
if (!Number.isInteger(value))
{
throw new Error("`shaLength` must be an integer.");
}
return value;
});
}
}
export class Context
{
public readonly env: Environment;
public readonly inputs: Inputs;
public constructor()
{
this.env = new Environment();
this.inputs = new Inputs();
}
}
export default new Context();