-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
61 lines (54 loc) · 1.67 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
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as core from "@actions/core";
import duration from "duration-js";
import {
curl,
upgrade as upgradeCurl,
isVersion as isCurlVersion,
} from "./curl";
process.on("unhandledRejection", (reason) => {
if (reason instanceof Error) {
core.error(reason.stack); // Because Github won't print it otherwise
core.setFailed(reason);
} else {
core.setFailed(`${reason}`);
}
});
async function run() {
const urlString = core.getInput("url", { required: true });
const maxAttemptsString = core.getInput("max-attempts");
const retryDelay = core.getInput("retry-delay");
const followRedirect = core.getBooleanInput("follow-redirect");
const retryAll = core.getBooleanInput("retry-all");
const cookie = core.getInput("cookie");
const basicAuth = core.getInput("basic-auth");
const urls = urlString.split("|");
const retryDelaySeconds = duration.parse(retryDelay).seconds();
const maxAttempts = parseInt(maxAttemptsString);
if (retryAll) {
const isUpToDate = await isCurlVersion("7.71.0");
if (!isUpToDate) {
core.warning(
"The installed version of curl does not support retry-all-errors. " +
"It will be upgraded automatically. If you don't want this to happen, you need to either " +
"upgrade it manually, or turn off retry-all."
);
await upgradeCurl();
}
}
for (const url of urls) {
// We don't need to do it in parallel, we're going to have to
// wait for all of them anyway
await curl(url, {
maxAttempts,
retryDelaySeconds,
retryAll,
followRedirect,
cookie,
basicAuth
});
}
core.info("Success");
}
run().catch((e) => {
core.setFailed(e);
});