-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
79 lines (63 loc) · 1.89 KB
/
main.ts
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
import * as core from "@actions/core";
import * as exc from "@actions/exec";
import * as io from "@actions/io";
import * as tc from "@actions/tool-cache";
import * as restm from "typed-rest-client/RestClient";
const process = require("process");
async function run() {
let version = await latestVersion();
let warpBin = await download(version);
core.addPath(warpBin);
await exc.exec("warp setup");
}
function repoToken() {
return core.getInput("repo-token");
}
function hostTriple() {
let arch;
switch (process.arch) {
case "arm64":
arch = "aarch64";
break;
case "x64":
arch = "x86_64";
break;
default:
throw new Error(`Unsupported architecture ${process.arch}.`);
}
let platform;
switch (process.platform) {
case "linux":
platform = "unknown-linux-gnu";
break;
case "darwin":
platform = "apple-darwin";
break;
default:
throw new Error(`Unsupported platform ${process.platform}.`);
}
return `${arch}-${platform}`;
}
interface Release {
tag_name: string;
}
async function latestVersion(): Promise<string> {
let client = new restm.RestClient("setup-warp", "", [], {
headers: { Authorization: `Bearer ${repoToken()}` },
});
let releaseUrl = "https://api.github.com/repos/warp-build/warp/releases";
let results = (await client.get<Array<Release>>(releaseUrl)).result || [];
let latestTag = results[0].tag_name;
return latestTag;
}
async function download(version: string): Promise<string> {
let url =
`https://github.com/warp-build/warp/releases/download/${version}/warp-${version}-${hostTriple()}.tar.gz`;
let downloadPath = await tc.downloadTool(url);
let extPath: string = downloadPath + "-extracted";
await io.mkdirP(extPath);
await exc.exec(`tar`, ["xzf", downloadPath], { cwd: extPath });
let cachePath = await tc.cacheDir(extPath, "warp", version);
return cachePath;
}
run();