forked from hypoport/mandrill-prometheus-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrigade.js
71 lines (59 loc) · 2.19 KB
/
brigade.js
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
const { events, Job, Group } = require("brigadier");
const { TestingJobGenerator, ImageJobGenerator, NotificationJobGenerator, BuildStatus, Debugger } = require("./spotahome");
const buildStatusSuccess = "success";
const eventTypePush = "push";
const eventTypeExec = "exec";
const eventTypePullRequest = "pull_request";
const eventTypeAfter = "after";
const eventTypeError = "error";
/**
* fullBuild is the most complete kind of build on the pipeline,
* it runs the unit tests, build the release image and pushes to
* a registry.
*/
function fullBuild(e, project) {
let ijg = new ImageJobGenerator(e, project);
env = {
IMAGE_VERSION: e.revision.commit,
PUSH_IMAGE: "true",
TARGET: "mandrill-prometheus-exporter"
}
let buildJob = ijg.dockerImageEnvironment("./hack/build-image.sh", env);
// Run the tests and then build release.
Group.runEach([buildJob])
}
/**
* debugFullBuild is like fullbuild but prints the received event information.
* useful while developing. WARNING: project is not printed because it has secrets
* and could be leaked by accident.
*/
function debugFullBuild(e, project) {
let d = new Debugger(e, project);
d.debugEvent(e);
fullBuild(e, project);
}
/**
* buildStatusToGithub will put the correct build status on github.
*/
function buildStatusToGithub(e, project) {
// Only set state of build when is a push or PR.
if ([eventTypePush, eventTypePullRequest].includes(e.cause.event.type)) {
// Set correct status
let state = BuildStatus.Failure;
if (e.cause.trigger == buildStatusSuccess) {
state = BuildStatus.Success;
}
// Set the status on github.
let njg = new NotificationJobGenerator(e, project);
njg.githubStatus(state).run();
// Set if the commit es deployable.
njg.githubSetToiletDeployable(state).run();
} else {
console.log(`Build finished with ${e.cause.trigger} state`);
}
}
events.on(eventTypePush, fullBuild);
events.on(eventTypeExec, debugFullBuild);
// Final events after build (failure or success).
events.on(eventTypeAfter, buildStatusToGithub);
events.on(eventTypeError, buildStatusToGithub);