forked from andymckay/cancel-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (29 loc) · 865 Bytes
/
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
const https = require("https");
const options = {
hostname: "api.github.com",
path: `/repos/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}/cancel`,
headers: {
Authorization: `token ${process.env.INPUT_TOKEN}`,
"Content-Type": "application/json",
"User-Agent": "actions/cancel-action",
},
method: "POST",
};
const req = https.request(options, (res) => {
res.on("data", (data) => {
if (res.statusCode != 202) {
let parsed = JSON.parse(data);
console.log(`Error: ${parsed.message}`);
process.exit(1);
} else {
console.log("Cancelled successfully.");
process.exit(0);
}
});
});
req.on("error", (error) => {
console.log(`HTTP Error: ${error}`);
process.exit(1);
});
req.end();
console.log(`::warning::Cancelled the workflow run from job ${process.env.GITHUB_JOB}`);