forked from Jtalk/url-health-check-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (52 loc) · 1.64 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
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 skipValidation = core.getBooleanInput("skip-validation");
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,
skipValidation,
});
}
core.info("Success");
}
run().catch((e) => {
core.setFailed(e);
});