-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (41 loc) · 1.25 KB
/
index.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
const http = require("http");
const crypto = require("crypto");
const exec = require("child_process").exec;
const config = require("dotenv-extended").load({
errorOnMissing: true,
errorOnRegex: true,
});
const server = http.createServer();
server.listen(config.PORT, (error) => {
if (error) {
throw Error(`Failed to run on port ${config.PORT}`);
}
console.log(`Server is listening on port ${config.PORT}`);
});
server.on("request", (request, response) => {
request.on("data", (chunk) => {
const signature =
"sha1=" +
crypto
.createHmac("sha1", config.WEBHOOK_SECRET)
.update(chunk.toString())
.digest("hex");
if (request.headers["x-hub-signature"] == signature) {
console.log(`
Event "${request.headers["x-github-event"]}":
Perfrom build of "${config.REPOSITORY_LOCATION}" application and deploy it.
`);
exec("bash build.sh", (error, stdout, stderr) => {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
if (error !== null) {
response.writeHead(500);
console.log(`exec error: ${error}`);
} else {
console.log(`Build completed successfully.`);
}
});
}
});
response.end();
});