-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateBuild.ts
56 lines (52 loc) · 1.35 KB
/
createBuild.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
import * as core from '@actions/core';
export async function createBuild({
apiKey,
apiBaseUrl,
gameId,
windowsChunkTotal,
macChunkTotal,
windowsGameName,
macGameName,
}: {
apiKey: string;
apiBaseUrl: string;
gameId: string;
windowsChunkTotal: number;
macChunkTotal: number;
windowsGameName: string | null;
macGameName: string | null;
}) {
const body = new FormData();
body.append('windowsChunkTotal', windowsChunkTotal.toString());
body.append('macChunkTotal', macChunkTotal.toString());
body.append('chunkNumber', '0');
if (windowsGameName) {
body.append('windowsGameName', windowsGameName);
}
if (macGameName) {
body.append('macGameName', macGameName);
}
if (!windowsGameName && !macGameName) {
throw new Error('Either windowsGameName or macGameName must be provided');
}
core.info('Initializing build');
const initResponse = await fetch(
`${apiBaseUrl}/v3/upload/games/${gameId}/builds`,
{
method: 'POST',
headers: {
'x-api-key': apiKey,
},
body,
}
);
if (!initResponse.ok) {
const text = await initResponse.text();
throw new Error(
`Failed to initialize build: ${apiBaseUrl} ${initResponse.status} ${text}`
);
}
const { result: buildId } = await initResponse.json();
core.info(`Build initialized with ID: ${buildId}`);
return buildId;
}