-
-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathinput.ts
More file actions
322 lines (250 loc) · 8.3 KB
/
input.ts
File metadata and controls
322 lines (250 loc) · 8.3 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import fs from 'node:fs';
import path from 'node:path';
import { Cli } from './cli/cli';
import OrchestratorQueryOverride from './orchestrator/options/orchestrator-query-override';
import Platform from './platform';
import GitHub from './github';
import os from 'node:os';
import * as core from '@actions/core';
export type InputKey = keyof typeof Input;
/**
* Input variables specified in workflows using "with" prop.
*
* Note that input is always passed as a string, even booleans.
*
* Todo: rename to UserInput and remove anything that is not direct input from the user / ci workflow
*/
class Input {
public static getInput(query: string): string | undefined {
if (GitHub.githubInputEnabled) {
const coreInput = core.getInput(query);
if (coreInput && coreInput !== '') {
return coreInput;
}
}
const alternativeQuery = Input.ToEnvVarFormat(query);
// Query input sources
if (Cli.query(query, alternativeQuery)) {
return Cli.query(query, alternativeQuery);
}
if (OrchestratorQueryOverride.query(query, alternativeQuery)) {
return OrchestratorQueryOverride.query(query, alternativeQuery);
}
if (process.env[query] !== undefined) {
return process.env[query]!;
}
if (alternativeQuery !== query && process.env[alternativeQuery] !== undefined) {
return process.env[alternativeQuery]!;
}
}
static get region(): string {
return Input.getInput('region') ?? 'eu-west-2';
}
static get githubRepo(): string | undefined {
return Input.getInput('GITHUB_REPOSITORY') ?? Input.getInput('GITHUB_REPO') ?? undefined;
}
static get branch(): string {
if (Input.getInput(`GITHUB_REF`)) {
return Input.getInput(`GITHUB_REF`)!.replace('refs/', '').replace(`head/`, '').replace(`heads/`, '');
} else if (Input.getInput('branch')) {
return Input.getInput('branch')!;
} else {
return '';
}
}
static get gitSha(): string {
if (Input.getInput(`GITHUB_SHA`)) {
return Input.getInput(`GITHUB_SHA`)!;
} else if (Input.getInput(`GitSHA`)) {
return Input.getInput(`GitSHA`)!;
}
return '';
}
static get runNumber(): string {
return Input.getInput('GITHUB_RUN_NUMBER') ?? '0';
}
static get targetPlatform(): string {
return Input.getInput('targetPlatform') ?? Platform.default;
}
static get unityVersion(): string {
return Input.getInput('unityVersion') ?? 'auto';
}
static get customImage(): string {
return Input.getInput('customImage') ?? '';
}
static get projectPath(): string {
const input = Input.getInput('projectPath');
let rawProjectPath;
if (input) {
rawProjectPath = input;
} else if (
fs.existsSync(path.join('test-project', 'ProjectSettings', 'ProjectVersion.txt')) &&
!fs.existsSync(path.join('ProjectSettings', 'ProjectVersion.txt'))
) {
rawProjectPath = 'test-project';
} else {
rawProjectPath = '.';
}
return rawProjectPath.replace(/\/$/, '');
}
static get buildProfile(): string {
return Input.getInput('buildProfile') ?? '';
}
static get runnerTempPath(): string {
return Input.getInput('RUNNER_TEMP') ?? '';
}
static get buildName(): string {
return Input.getInput('buildName') ?? Input.targetPlatform;
}
static get buildsPath(): string {
return Input.getInput('buildsPath') ?? 'build';
}
static get unityLicensingServer(): string {
return Input.getInput('unityLicensingServer') ?? '';
}
static get buildMethod(): string {
return Input.getInput('buildMethod') ?? ''; // Processed in docker file
}
static get manualExit(): boolean {
const input = Input.getInput('manualExit') ?? false;
return input === 'true';
}
static get enableGpu(): boolean {
const input = Input.getInput('enableGpu') ?? false;
return input === 'true';
}
static get customParameters(): string {
return Input.getInput('customParameters') ?? '';
}
static get versioningStrategy(): string {
return Input.getInput('versioning') ?? 'Semantic';
}
static get specifiedVersion(): string {
return Input.getInput('version') ?? '';
}
static get androidVersionCode(): string {
return Input.getInput('androidVersionCode') ?? '';
}
static get androidExportType(): string {
return Input.getInput('androidExportType') ?? 'androidPackage';
}
static get androidKeystoreName(): string {
return Input.getInput('androidKeystoreName') ?? '';
}
static get androidKeystoreBase64(): string {
return Input.getInput('androidKeystoreBase64') ?? '';
}
static get androidKeystorePass(): string {
return Input.getInput('androidKeystorePass') ?? '';
}
static get androidKeyaliasName(): string {
return Input.getInput('androidKeyaliasName') ?? '';
}
static get androidKeyaliasPass(): string {
return Input.getInput('androidKeyaliasPass') ?? '';
}
static get androidTargetSdkVersion(): string {
return Input.getInput('androidTargetSdkVersion') ?? '';
}
static get androidSymbolType(): string {
return Input.getInput('androidSymbolType') ?? 'none';
}
static get sshAgent(): string {
return Input.getInput('sshAgent') ?? '';
}
static get sshPublicKeysDirectoryPath(): string {
return Input.getInput('sshPublicKeysDirectoryPath') ?? '';
}
static get gitPrivateToken(): string | undefined {
return Input.getInput('gitPrivateToken');
}
static get runAsHostUser(): string {
return Input.getInput('runAsHostUser')?.toLowerCase() ?? 'false';
}
static get chownFilesTo() {
return Input.getInput('chownFilesTo') ?? '';
}
static get allowDirtyBuild(): boolean {
const input = Input.getInput('allowDirtyBuild') ?? false;
return input === 'true';
}
static get cacheUnityInstallationOnMac(): boolean {
const input = Input.getInput('cacheUnityInstallationOnMac') ?? false;
return input === 'true';
}
static get unityHubVersionOnMac(): string {
const input = Input.getInput('unityHubVersionOnMac') ?? '';
return input !== '' ? input : '';
}
static get unitySerial(): string | undefined {
return Input.getInput('UNITY_SERIAL');
}
static get unityLicense(): string | undefined {
return Input.getInput('UNITY_LICENSE');
}
static get dockerWorkspacePath(): string {
return Input.getInput('dockerWorkspacePath') ?? '/github/workspace';
}
static get dockerCpuLimit(): string {
return Input.getInput('dockerCpuLimit') ?? os.cpus().length.toString();
}
static get dockerMemoryLimit(): string {
const bytesInMegabyte = 1024 * 1024;
let memoryMultiplier;
switch (os.platform()) {
case 'linux':
memoryMultiplier = 0.95;
break;
case 'win32':
memoryMultiplier = 0.8;
break;
default:
memoryMultiplier = 0.75;
break;
}
return (
Input.getInput('dockerMemoryLimit') ?? `${Math.floor((os.totalmem() / bytesInMegabyte) * memoryMultiplier)}m`
);
}
static get dockerIsolationMode(): string {
return Input.getInput('dockerIsolationMode') ?? 'default';
}
static get containerRegistryRepository(): string {
return Input.getInput('containerRegistryRepository') ?? 'unityci/editor';
}
static get containerRegistryImageVersion(): string {
return Input.getInput('containerRegistryImageVersion') ?? '3';
}
static get artifactOutputTypes(): string {
return Input.getInput('artifactOutputTypes') ?? 'build,logs,test-results';
}
static get artifactUploadTarget(): string {
return Input.getInput('artifactUploadTarget') ?? 'github-artifacts';
}
static get artifactUploadPath(): string {
return Input.getInput('artifactUploadPath') ?? '';
}
static get artifactCompression(): string {
return Input.getInput('artifactCompression') ?? 'gzip';
}
static get artifactRetentionDays(): string {
return Input.getInput('artifactRetentionDays') ?? '30';
}
static get artifactCustomTypes(): string {
return Input.getInput('artifactCustomTypes') ?? '';
}
static get skipActivation(): string {
return Input.getInput('skipActivation')?.toLowerCase() ?? 'false';
}
public static ToEnvVarFormat(input: string) {
if (input.toUpperCase() === input) {
return input;
}
return input
.replace(/([A-Z])/g, ' $1')
.trim()
.toUpperCase()
.replace(/ /g, '_');
}
}
export default Input;