-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.js
62 lines (46 loc) · 1.38 KB
/
post.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
const core = require('@actions/core');
const axios = require('axios')
const VMMETER_PID = 'vmmeter-pid'
const VMMETER_PORT = 'vmmeter-port'
async function run() {
try {
const time = (new Date()).toTimeString();
core.setOutput("end-time", time);
let vmPort = core.getState('vmmeter-port')
if(vmPort == '') {
let logs = ""
try {
logs = fs.readFileSync('/tmp/vmmeter.log', 'utf8')
} catch {
}
core.warning(`vmmeter port not found in state`);
if(logs.length) {
core.warning(`Logs from /tmp/vmmeter.log: ${logs}`);
}
return;
}
let results = "Results not available"
await axios({"method": "get", "url": `http://127.0.0.1:${vmPort}/collect`, "headers": {}}).
then((response) => {
console.log(response.data)
results = response.data
}).
catch(err => {
try {
let data = fs.readFileSync('/tmp/vmmeter.log', 'utf8')
core.warning(`Failed to collect metrics: ${err.message}, logs: ${data}`);
} catch {
core.warning(`Failed to collect metrics: ${err.message}, no logs at: /tmp/vmmeter.log)`);
}
})
if(core.getBooleanInput("createSummary")) {
await core.summary
.addHeading('Metering Results')
.addCodeBlock(results, "text")
.write()
}
} catch (error) {
core.warning(error.message);
}
}
run()