-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhacky-deploy.js
More file actions
98 lines (76 loc) · 2.54 KB
/
hacky-deploy.js
File metadata and controls
98 lines (76 loc) · 2.54 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const { request } = require('http');
const deployToken = process.env.DEPLOY_AUTH_TOKEN;
const address = process.env.WEBHOOK_ADDRESS;
const challsToDeploy = process.argv.slice(2).flatMap(s => s.split(','));
console.log(`Deploying: ${challsToDeploy.join(', ')}`);
const deployStates = {
};
const deployIds = {
};
for (const chall of challsToDeploy) deployStates[chall] = "Not started";
const sendInitial = async() => {
for (const chall of challsToDeploy) {
const res = await sendReq({
"deploy": {
"__type": "deploy",
"chall": chall,
"force_wipe": false
}
});
// deployStates[chall] = res.deploy.status;
deployIds[chall] = res.deploy.poll_id;
}
};
sendInitial();
setInterval(async () => {
for (const chall of challsToDeploy) {
const res = await sendReq({
deploy: {
__type: "poll",
id: deployIds[chall]
}
});
try {
const name = res.deploy.status.padStart(9, " ");
const time = (res.deploy.status_time.secs + res.deploy.status_time.nanos * 1e-9);
deployStates[chall] = `${name} for ${time.toFixed(1)} seconds`;
deployIds[chall] = res.deploy.poll_id;
} catch (e) {
console.error(e);
console.log(res.toString());
console.log(res);
}
}
console.log('\n\nUpdate:');
challsToDeploy.forEach(chall => console.log(`${deployIds[chall]} ${chall.padStart(16, " ")}: ${deployStates[chall]}`))
console.log();
// Promise.allSettled(promises).then(() => {
// });
}, 5000);
function sendReq(json) {
return new Promise((resolve, rej) => {
const req = request(
address,
{ method: "POST", headers: {
"Authorization": `Bearer ${deployToken}`,
"Content-Type": "application/json",
} },
res => {
const chunks = [];
res.on('data', data => chunks.push(data))
res.on('end', () => {
let resBody = Buffer.concat(chunks);
switch(res.headers['content-type']) {
case 'application/json':
resBody = JSON.parse(resBody);
break;
}
resolve(resBody)
})
}
);
req.on('error', rej);
req.write(JSON.stringify(json));
req.end();
})
}