Install binstall by downloading.

This commit is contained in:
Miles Johnson 2023-04-16 14:35:54 -07:00
parent 949b836c1d
commit 80fcf1ca2f
3 changed files with 66 additions and 8 deletions

View file

@ -3,6 +3,7 @@ import os from 'os';
import path from 'path';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache';
import TOML from '@ltd/j-toml';
interface Toolchain {
@ -66,7 +67,7 @@ function detectToolchain(): Toolchain {
channel: process.env.RUSTUP_TOOLCHAIN,
});
} else {
core.info('Searching for rust-toolchain.toml or rust-toolchain file');
core.info('Loading rust-toolchain.toml or rust-toolchain file');
for (const configName of ['rust-toolchain.toml', 'rust-toolchain']) {
const configPath = path.join(process.cwd(), configName);
@ -128,6 +129,47 @@ async function installToolchain(toolchain: Toolchain) {
await exec.exec('rustc', [`+${toolchain.channel}`, '--version', '--verbose']);
}
async function downloadAndInstallBinstall(binDir: string) {
core.info('cargo-binstall does not exist, attempting to install');
let arch;
let file;
switch (process.arch) {
case 'x64':
arch = 'x86_64';
break;
case 'arm64':
arch = 'aarch64';
break;
default:
throw new Error(`Unsupported architecture: ${process.arch}`);
}
switch (process.platform) {
case 'linux':
file = `${arch}-unknown-linux-gnu.tgz`;
break;
case 'darwin':
file = `${arch}-apple-darwin.zip`;
break;
case 'win32':
file = `${arch}-pc-windows-msvc.zip`;
break;
default:
throw new Error(`Unsupported platform: ${process.platform}`);
}
const url = `https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-${file}`;
const dlPath = await tc.downloadTool(url);
if (url.endsWith('.zip')) {
await tc.extractZip(dlPath, binDir);
} else if (url.endsWith('.tgz')) {
await tc.extractTar(dlPath, binDir);
}
}
async function installBins() {
const bins = core
.getInput('bins')
@ -144,12 +186,8 @@ async function installBins() {
const binDir = path.join(getCargoHome(), 'bin');
core.debug('Checking if cargo-binstall has been installed');
if (!fs.existsSync(path.join(binDir, 'cargo-binstall'))) {
core.debug('Not installed, attempting to install');
await exec.exec('cargo', ['install', 'cargo-binstall']);
await downloadAndInstallBinstall(binDir);
}
await exec.exec('cargo', ['binstall', '--no-confirm', '--log-level', 'info', ...bins]);

View file

@ -1,6 +1,6 @@
{
"name": "@moonrepo/setup-rust",
"version": "0.2.2",
"version": "0.2.3",
"description": "A GitHub action for setting up Rust and Cargo.",
"main": "dist/index.js",
"scripts": {
@ -18,6 +18,7 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/tool-cache": "^2.0.1",
"@ltd/j-toml": "^1.38.0"
},
"devDependencies": {

21
pnpm-lock.yaml generated
View file

@ -7,6 +7,9 @@ dependencies:
'@actions/exec':
specifier: ^1.1.1
version: 1.1.1
'@actions/tool-cache':
specifier: ^2.0.1
version: 2.0.1
'@ltd/j-toml':
specifier: ^1.38.0
version: 1.38.0
@ -62,6 +65,17 @@ packages:
resolution: {integrity: sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==}
dev: false
/@actions/tool-cache@2.0.1:
resolution: {integrity: sha512-iPU+mNwrbA8jodY8eyo/0S/QqCKDajiR8OxWTnSk/SnYg0sj8Hp4QcUEVC1YFpHWXtrfbQrE13Jz4k4HXJQKcA==}
dependencies:
'@actions/core': 1.10.0
'@actions/exec': 1.1.1
'@actions/http-client': 2.1.0
'@actions/io': 1.1.3
semver: 6.3.0
uuid: 3.4.0
dev: false
/@babel/code-frame@7.21.4:
resolution: {integrity: sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==}
engines: {node: '>=6.9.0'}
@ -2226,7 +2240,6 @@ packages:
/semver@6.3.0:
resolution: {integrity: sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==}
hasBin: true
dev: true
/semver@7.3.8:
resolution: {integrity: sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==}
@ -2499,6 +2512,12 @@ packages:
punycode: 2.3.0
dev: true
/uuid@3.4.0:
resolution: {integrity: sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==}
deprecated: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
hasBin: true
dev: false
/uuid@8.3.2:
resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
hasBin: true