1
0
Files
setup-deno/src/install.js
T

93 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-06-27 13:07:03 +05:30
const os = require("os");
const path = require("path");
2024-09-12 03:46:45 -07:00
const fs = require("fs/promises");
2021-04-10 02:16:12 +02:00
const process = require("process");
const core = require("@actions/core");
const tc = require("@actions/tool-cache");
/**
2021-05-18 23:34:43 +02:00
* @param {import("./version").Version} version
2021-04-10 02:16:12 +02:00
*/
async function install(version) {
const cachedPath = tc.find(
"deno",
2024-09-13 07:41:34 -07:00
version.kind === "canary" ? `0.0.0-${version.version}` : version.version,
2021-04-10 02:16:12 +02:00
);
if (cachedPath) {
core.info(`Using cached Deno installation from ${cachedPath}.`);
core.addPath(cachedPath);
return;
}
const zip = zipName();
2024-09-13 07:41:34 -07:00
const url = version.kind === "canary"
2021-04-10 02:16:12 +02:00
? `https://dl.deno.land/canary/${version.version}/${zip}`
: `https://dl.deno.land/release/v${version.version}/${zip}`;
2021-04-10 02:16:12 +02:00
core.info(`Downloading Deno from ${url}.`);
const zipPath = await tc.downloadTool(url);
const extractedFolder = await tc.extractZip(zipPath);
2024-09-12 03:46:45 -07:00
const binaryName = core.getInput("deno-binary-name");
if (binaryName !== "deno") {
await fs.rename(
path.join(
extractedFolder,
process.platform === "win32" ? "deno.exe" : "deno",
),
path.join(
extractedFolder,
process.platform === "win32" ? binaryName + ".exe" : binaryName,
),
);
}
2021-04-10 02:16:12 +02:00
const newCachedPath = await tc.cacheDir(
extractedFolder,
2024-09-12 03:46:45 -07:00
binaryName,
version.isCanary ? `0.0.0-${version.version}` : version.version,
2021-04-10 02:16:12 +02:00
);
core.info(`Cached Deno to ${newCachedPath}.`);
core.addPath(newCachedPath);
2021-06-27 13:07:03 +05:30
const denoInstallRoot = process.env.DENO_INSTALL_ROOT ||
path.join(os.homedir(), ".deno", "bin");
core.addPath(denoInstallRoot);
2021-04-10 02:16:12 +02:00
}
/** @returns {string} */
function zipName() {
let arch;
switch (process.arch) {
case "arm64":
arch = "aarch64";
break;
case "x64":
arch = "x86_64";
break;
default:
throw new Error(`Unsupported architechture ${process.arch}.`);
}
let platform;
switch (process.platform) {
case "linux":
platform = "unknown-linux-gnu";
break;
case "darwin":
platform = "apple-darwin";
break;
case "win32":
platform = "pc-windows-msvc";
break;
default:
throw new Error(`Unsupported platform ${process.platform}.`);
}
return `deno-${arch}-${platform}.zip`;
}
module.exports = {
install,
};