-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathscheduleBuildsFromTheQueue.ts
More file actions
70 lines (60 loc) · 2.36 KB
/
Copy pathscheduleBuildsFromTheQueue.ts
File metadata and controls
70 lines (60 loc) · 2.36 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
import { RepoVersionInfo } from '../../model/repoVersionInfo';
import { Scheduler } from './scheduler';
import { Discord } from '../../service/discord';
import { CiJobs } from '../../model/ciJobs';
import { Cleaner } from './cleaner';
/**
* When a new Unity version gets ingested:
* - a CI Job for that version gets created.
*
* When a new repository version gets ingested
* - a CI Job for a new base image gets created
* - a CI Job for a new hub image gets created
* - a CI Job for every Unity version gets created
* - Any CI Jobs for older repository versions get status "superseded"
*
* This schedule is based on that knowledge and assumption
*/
export const scheduleBuildsFromTheQueue = async (
githubPrivateKey: string,
githubClientSecret: string,
) => {
const repoVersionInfo = await RepoVersionInfo.getLatest();
const numSuperseded = await CiJobs.markJobsBeforeRepoVersionAsSuperseded(repoVersionInfo.version);
if (numSuperseded >= 1) {
await Discord.sendDebug(
`[Build queue] Superseded ${CiJobs.pluralise(
numSuperseded,
)} from older repo versions before scheduling.`,
);
}
const recoveredBuilds = await Cleaner.recoverMaxedOutFailedBuilds(repoVersionInfo.version);
if (recoveredBuilds.length >= 1) {
await Discord.sendDebug(
`[Build queue] Recovered ${recoveredBuilds.length} maxed-out failed build(s) for repo version ${repoVersionInfo.version}.`,
);
}
const scheduler = await new Scheduler(repoVersionInfo).init(githubPrivateKey, githubClientSecret);
const testVersion = '0.1.0';
if (repoVersionInfo.version === testVersion) {
await Discord.sendDebug('[Build queue] No longer building test versions.');
return;
}
if (!(await scheduler.ensureThatBaseImageHasBeenBuilt())) {
await Discord.sendDebug('[Build queue] Waiting for base image to be ready.');
return;
}
if (!(await scheduler.ensureThatHubImageHasBeenBuilt())) {
await Discord.sendDebug('[Build queue] Waiting for hub image to be ready.');
return;
}
if (!(await scheduler.ensureThereAreNoFailedJobs())) {
await Discord.sendDebug('[Build queue] Retrying failed jobs before scheduling new jobs.');
return;
}
if (!(await scheduler.buildLatestEditorImages())) {
await Discord.sendDebug('[Build queue] Editor images are building.');
return;
}
await Discord.sendDebug('[Build queue] Idle 🎈');
};