-
Notifications
You must be signed in to change notification settings - Fork 18
/
curl.js
88 lines (80 loc) · 2.4 KB
/
curl.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
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
import * as core from "@actions/core";
import { exec, getExecOutput } from "@actions/exec";
import * as path from "path";
import * as os from "os";
import * as semver from "semver";
export async function curl(
url,
{ maxAttempts, retryDelaySeconds, retryAll, followRedirect, cookie, basicAuth }
) {
const options = ["--fail", "-sv"];
if (maxAttempts > 1) {
options.push(
"--retry",
`${maxAttempts}`,
"--retry-delay",
`${retryDelaySeconds}`,
"--retry-connrefused"
);
}
if (followRedirect) {
options.push("-L");
}
if (retryAll) {
options.push("--retry-all-errors");
}
if(cookie) {
options.push("--cookie", `${cookie}`);
}
if(basicAuth) {
options.push("-u", `${basicAuth}`);
}
options.push(url);
core.info(`Checking ${url}`);
core.debug(`Command: curl ${options.join(" ")}`);
return exec("curl", options);
}
export async function isVersion(atLeast) {
const curlVersionOutput = await getExecOutput("curl --version");
const rawVersion = curlVersionOutput.stdout.match(/curl (\d+\.\d+\.\d+)/)[1];
const installed = semver.clean(rawVersion);
return semver.gte(installed, atLeast);
}
export async function upgrade() {
const upgrader = {
linux: {
exec: async () => {
const binDir = path.join(os.homedir(), ".bin");
const curlPath = path.join(binDir, "curl");
// From https://curl.se/download.html#Linux
const curlUrl = `https://github.com/moparisthebest/static-curl/releases/download/v7.78.0/curl-amd64`;
await exec("mkdir", ["-p", binDir]);
await exec("wget", ["-O", curlPath, curlUrl]);
await exec("chmod", ["+x", curlPath]);
core.addPath(binDir);
},
},
win32: {
exec: async () => {
await exec("choco", ["install", "curl"]);
// If this is the first time chocolatey is run, it won't be in the PATH.
// It sounds like a runner setup issue, to be fair, but we still need it to work.
core.addPath("C:\\ProgramData\\chocolatey\\bin");
},
},
darwin: {
exec: async () => {
await exec("brew", ["install", "curl"]);
},
},
};
const platformUpgrader = upgrader[process.platform];
if (!platformUpgrader) {
throw new Error(
`Unsupported platform: ${
process.platform
}, supported platforms: ${Object.keys(upgrader).join(", ")}`
);
}
await platformUpgrader.exec();
}