forked from adambirds/docker-compose-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
64 lines (54 loc) · 1.66 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
const core = require("@actions/core");
const compose = require("docker-compose");
const utils = require("./utils");
//const path = require("path");
try {
const composeFiles = utils.parseComposeFiles(
core.getMultilineInput("compose-file")
);
if (!composeFiles.length) {
return;
}
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
? compose.upMany(services, options)
: compose.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 = compose.exec(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);
core.setFailed(`tests failed ${JSON.stringify(err)}`);
});
}, 10000);
}
})
.catch((err) => {
core.setFailed(`compose up failed ${JSON.stringify(err)}`);
});
} catch (error) {
core.setFailed(error.message);
}