-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.js
71 lines (59 loc) · 1.86 KB
/
main.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 core = require("@actions/core");
const utils = require("./utils");
const { upMany, upAll, run } = require("docker-compose/dist/v2");
let annotate = true; // Default annotate to true
try {
const composeFiles = utils.parseComposeFiles(
core.getMultilineInput("compose-file")
);
if (!composeFiles.length) {
return;
}
annotate = core.getInput("annotate") || true; // Override if "annotate" input is provided
const services = core.getMultilineInput("services", { required: false });
const options = {
config: composeFiles,
log: true,
composeOptions: utils.parseFlags(core.getInput("compose-flags")),
commandOptions: utils.parseFlags(core.getInput("up-flags")),
};
const promise =
services.length > 0 ? upMany(services, options) : upAll(options);
promise
.then(() => {
console.log("compose started");
// Run tests command.
const testContainer = core.getInput("test-container");
const testCommand = core.getInput("test-command");
console.log("testContainer", testContainer);
console.log("testCommand", testCommand);
if (testCommand && testContainer) {
setTimeout(() => {
const test = run(testContainer, testCommand, {
config: composeFiles,
});
test
.then((out) => {
console.log(out.out);
console.log("tests passed");
})
.catch((err) => {
console.log(err.out);
console.log(err.err);
if (annotate) {
core.setFailed(`tests failed ${JSON.stringify(err)}`);
}
});
}, 10000);
}
})
.catch((err) => {
if (annotate) {
core.setFailed(`compose up failed ${JSON.stringify(err)}`);
}
});
} catch (error) {
if (annotate) {
core.setFailed(error.message);
}
}