Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
version: string
): Promise {
// Create temporary folder to download in to
let tempDownloadFolder: string =
'temp_' + Math.floor(Math.random() * 2000000000);
let tempDir: string = path.join(tempDirectory, tempDownloadFolder);
await io.mkdirP(tempDir);
let exeUrl: string;
let libUrl: string;
try {
exeUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${os.arch()}/node.lib`;
const exePath = await tc.downloadTool(exeUrl);
await io.cp(exePath, path.join(tempDir, 'node.exe'));
const libPath = await tc.downloadTool(libUrl);
await io.cp(libPath, path.join(tempDir, 'node.lib'));
} catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
exeUrl = `https://nodejs.org/dist/v${version}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/node.lib`;
const exePath = await tc.downloadTool(exeUrl);
await io.cp(exePath, path.join(tempDir, 'node.exe'));
const libPath = await tc.downloadTool(libUrl);
await io.cp(libPath, path.join(tempDir, 'node.lib'));
} else {
throw err;
}
}
return await tc.cacheDir(tempDir, 'node', version);
}
async function acquireRUbuntu(version: string): Promise {
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
let fileName: string = getFileNameUbuntu(version);
let downloadUrl: string = getDownloadUrlUbuntu(fileName);
let downloadPath: string | null = null;
try {
downloadPath = await tc.downloadTool(downloadUrl);
await io.mv(downloadPath, path.join(tempDirectory, fileName));
} catch (error) {
core.debug(error);
throw `Failed to download version ${version}: ${error}`;
}
//
// Install
//
let extPath: string = tempDirectory;
if (!extPath) {
throw new Error("Temp directory not set");
}
try {
async function downloadRelease(version: string): Promise {
// Download
let fileName: string = getFileName(version);
let downloadUrl: string = util.format(
"https://github.com/Arduino/arduino-cli/releases/download/%s/%s",
version,
fileName
);
let downloadPath: string | null = null;
try {
downloadPath = await tc.downloadTool(downloadUrl);
} catch (error) {
core.debug(error);
throw `Failed to download version ${version}: ${error}`;
}
// Extract
let extPath: string | null = null;
if (osPlat == "win32") {
extPath = await tc.extractZip(downloadPath);
} else {
extPath = await tc.extractTar(downloadPath);
}
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
return await tc.cacheDir(extPath, "arduino-cli", version);
}
async function acquireRMacOS(version: string): Promise {
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
let fileName: string = getFileNameMacOS(version);
let downloadUrl: string = getDownloadUrlMacOS(version);
let downloadPath: string | null = null;
try {
downloadPath = await tc.downloadTool(downloadUrl);
await io.mv(downloadPath, path.join(tempDirectory, fileName));
} catch (error) {
core.debug(error);
throw `Failed to download version ${version}: ${error}`;
}
//
// Extract
//
let extPath: string = tempDirectory;
if (!extPath) {
throw new Error("Temp directory not set");
}
try {
export async function setup(version: string): Promise {
let toolPath = tc.find(
'Leiningen',
utils.getCacheVersionString(version),
os.arch()
);
if (toolPath && version !== 'latest') {
core.info(`Leiningen found in cache ${toolPath}`);
} else {
let leiningenFile = await tc.downloadTool(
`https://raw.githubusercontent.com/technomancy/leiningen/${version === 'latest' ? 'stable' : version}/bin/lein${IS_WINDOWS ? '.bat' : ''}`
);
let tempDir: string = path.join(
tempDirectory,
'temp_' + Math.floor(Math.random() * 2000000000)
);
const leiningenDir = await installLeiningen(
leiningenFile,
tempDir
);
core.debug(`Leiningen installed to ${leiningenDir}`);
toolPath = await tc.cacheDir(
leiningenDir,
'Leiningen',
utils.getCacheVersionString(version)
);
async function installOnUnix(): Promise {
let script = await toolCache.downloadTool("https://sh.rustup.rs");
chmodSync(script, '777');
await exec.exec(`"${script}"`, ['-y', '--default-toolchain', 'none', '--profile=minimal']);
return path.join(process.env['HOME'] || '', '.cargo');
}
async function acquireRtools(version: string) {
let fileName: string = util.format("Rtools%s.exe", version);
let downloadUrl: string = util.format(
"http://cloud.r-project.org/bin/windows/Rtools/%s",
fileName
);
let downloadPath: string | null = null;
try {
downloadPath = await tc.downloadTool(downloadUrl);
await io.mv(downloadPath, path.join(tempDirectory, fileName));
} catch (error) {
core.debug(error);
throw `Failed to download version ${version}: ${error}`;
}
try {
await exec.exec(path.join(tempDirectory, fileName), [
"/VERYSILENT",
"/SUPPRESSMSGBOXES"
]);
} catch (error) {
core.debug(error);
throw `Failed to install Rtools: ${error}`;