forked from egor-tensin/setup-clang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
47 lines (44 loc) · 1.75 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
#!/usr/bin/env -S deno run -Aq
import * as core from "npm:@actions/core";
import * as tc from "npm:@actions/tool-cache";
import process from "node:process";
import { join } from "node:path";
import { createWriteStream } from "node:fs";
import { chmod } from "node:fs/promises";
import { pipeline } from "node:stream/promises";
import semver from "npm:semver";
import { $ } from "npm:execa";
async function downloadTool(url: string): string {
const dest = join(
process.env.RUNNER_TEMP,
Math.random().toString() + url.match(/\.[^/]+$/)[0]
);
core.debug(`Downloading ${url} to ${dest}`);
const response = await fetch(url);
await pipeline(response.body, createWriteStream(dest));
return dest;
}
let version = core.getInput("llvm-version")
if (!/\d+/.test(version)) {
const response = await fetch("https://releases.llvm.org")
const text = await response.text()
const releases = eval(text.match(/var RELEASES = (.*?);/s)[1])
const versions = releases.map(x => x[1])
if (version === "latest") {
version = "*"
}
version = semver.maxSatisfying(versions, version);
version = version.match(/\d+/)[0]
}
if (process.platform === "linux" && (process.arch === "x64" || process.arch === "arm64")) {
let path = await downloadTool("https://apt.llvm.org/llvm.sh")
await chmod(path, 0o775)
const $$ = $({ stdio: "inherit" })
await $$`sudo ${path} ${version}`
} else if (process.platform === "darwin" && process.arch === "x64") {
throw new DOMException("macOS not implemented yet", "NotSupportedError")
} else if (process.platform === "win32" && process.arch === "x64") {
throw new DOMException("Windows not implemented yet", "NotSupportedError")
} else {
throw new DOMException(`${process.platform}/${process.arch} is not supported`, "NotSupportedError")
}