-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
43 lines (36 loc) · 1.53 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
const path = require("path");
const core = require("@actions/core");
const toolCache = require("@actions/tool-cache");
const semver = require("semver");
function findArchive({version, nodePlatform}) {
const wabtPlatform = nodePlatformToWabtPlatform({nodePlatform, version});
const directoryName = `wabt-${version}`;
return [directoryName, `https://github.com/WebAssembly/wabt/releases/download/${version}/${directoryName}-${wabtPlatform}.tar.gz`]
}
function nodePlatformToWabtPlatform({nodePlatform, version}) {
switch (nodePlatform) {
case "darwin":
return semver.gte(version, "1.0.30") ? "macos-12" : "macos";
case "linux":
return semver.gte(version, "1.0.35") ? "ubuntu-20.04" : "ubuntu";
case "win32":
return "windows";
default:
throw new Error("unrecognised platform: " + nodePlatform);
}
}
async function install() {
try {
const version = core.getInput("wabt-version");
const nodePlatform = process.platform;
const [archiveDirectory, archiveUrl] = findArchive({version, nodePlatform});
core.info(`Download from ${archiveUrl}`);
const archivePath = await toolCache.downloadTool(archiveUrl);
const tempDir = await toolCache.extractTar(archivePath, undefined, "xz");
const toolPath = await toolCache.cacheDir(path.join(tempDir, archiveDirectory), "wabt", version);
core.addPath(path.join(toolPath, "bin"));
} catch (error) {
core.setFailed(error.message);
}
}
install();