generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 3
/
destroy.js
58 lines (52 loc) · 1.62 KB
/
destroy.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
const core = require('@actions/core');
const process = require('process');
const artifact = require('@actions/artifact');
// most @actions toolkit packages have async methods
async function run() {
try {
core.info(`Destroying synapse ...`);
var pid = core.getState("synapse-pid");
var cwd = core.getState("synapse-dir");
// Polite termination is for those without pull requests to merge.
try {
process.kill(pid, 15);
await sleep(10000);
try {
process.kill(pid, 9);
core.warn("Synapse did not shutdown in 10s. Terminating");
} catch(e) {
// expected that synapse PID is not available to be terminated here.
}
} catch(e) {
core.error("Synapse was no-longer running at teardown time")
}
// Tidy up the synapse directory to contain only log files
// (useful for an artifact upload)
const upload = core.getBooleanInput('uploadLogs', {required: true});
if (upload) {
const artifactName = core.getInput('artifactName');
const artifactClient = artifact.create();
const files = [
`${cwd}/homeserver.yaml`,
`${cwd}/homeserver.log`,
`${cwd}/custom.yaml`,
`${cwd}/additional.yaml`,
`${cwd}/out.log`,
`${cwd}/err.log`
];
const rootDirectory = `${cwd}`;
const options = {
continueOnError: true
}
await artifactClient.uploadArtifact(artifactName, files, rootDirectory, options);
}
} catch (error) {
core.setFailed(error.message);
}
}
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
run();