mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-29 21:40:01 +00:00
Install bins.
This commit is contained in:
parent
354e8c068b
commit
befb8010f7
3 changed files with 59 additions and 9 deletions
|
@ -1,7 +1,9 @@
|
||||||
name: 'Setup rustup toolchain'
|
name: 'Setup Rust and Cargo'
|
||||||
author: 'Miles Johnson'
|
author: 'Miles Johnson'
|
||||||
description: 'Sets up Rust and Cargo.'
|
description: 'Sets up Rust and Cargo.'
|
||||||
inputs:
|
inputs:
|
||||||
|
bins:
|
||||||
|
description: 'Comma-separated list of global binaries to install.'
|
||||||
channel:
|
channel:
|
||||||
description: 'Toolchain specification/channel to install.'
|
description: 'Toolchain specification/channel to install.'
|
||||||
components:
|
components:
|
||||||
|
|
62
index.ts
62
index.ts
|
@ -23,6 +23,14 @@ const DEFAULT_TOOLCHAIN: Toolchain = {
|
||||||
targets: [],
|
targets: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getCargoHome(): string {
|
||||||
|
if (process.env.CARGO_HOME) {
|
||||||
|
return process.env.CARGO_HOME;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.join(os.homedir(), '.cargo');
|
||||||
|
}
|
||||||
|
|
||||||
function parseConfig(configPath: string): Partial<Toolchain> {
|
function parseConfig(configPath: string): Partial<Toolchain> {
|
||||||
const contents = fs.readFileSync(configPath, 'utf8').trim();
|
const contents = fs.readFileSync(configPath, 'utf8').trim();
|
||||||
|
|
||||||
|
@ -120,15 +128,46 @@ async function installToolchain(toolchain: Toolchain) {
|
||||||
await exec.exec('rustc', [`+${toolchain.channel}`, '--version', '--verbose']);
|
await exec.exec('rustc', [`+${toolchain.channel}`, '--version', '--verbose']);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function run() {
|
async function installBins() {
|
||||||
try {
|
const bins = core
|
||||||
await installToolchain(detectToolchain());
|
.getInput('bins')
|
||||||
} catch (error: unknown) {
|
.split(',')
|
||||||
core.setFailed((error as Error).message);
|
.map((bin) => bin.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
throw error;
|
if (bins.length === 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.info('Installing additional binaries');
|
||||||
|
|
||||||
|
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 Promise.all(
|
||||||
|
bins.map((bin) => {
|
||||||
|
const [crate, version] = bin.split('@');
|
||||||
|
const args = ['binstall', crate.startsWith('cargo-') ? crate : `cargo-${crate}`];
|
||||||
|
|
||||||
|
if (version) {
|
||||||
|
args.push('--version', version);
|
||||||
|
}
|
||||||
|
|
||||||
|
core.info(`Installing ${crate}...`);
|
||||||
|
|
||||||
|
return exec.exec('cargo', args);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function run() {
|
||||||
core.info('Setting cargo environment variables');
|
core.info('Setting cargo environment variables');
|
||||||
|
|
||||||
// Disable incremental compilation
|
// Disable incremental compilation
|
||||||
|
@ -137,9 +176,18 @@ async function run() {
|
||||||
// Always enable colored output
|
// Always enable colored output
|
||||||
core.exportVariable('CARGO_TERM_COLOR', 'always');
|
core.exportVariable('CARGO_TERM_COLOR', 'always');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await installToolchain(detectToolchain());
|
||||||
|
await installBins();
|
||||||
|
} catch (error: unknown) {
|
||||||
|
core.setFailed((error as Error).message);
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
core.info('Adding ~/.cargo/bin to PATH');
|
core.info('Adding ~/.cargo/bin to PATH');
|
||||||
|
|
||||||
core.addPath(path.join(os.homedir(), '.cargo', 'bin'));
|
core.addPath(path.join(getCargoHome(), 'bin'));
|
||||||
}
|
}
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@moonrepo/setup-rust",
|
"name": "@moonrepo/setup-rust",
|
||||||
"version": "0.1.1",
|
"version": "0.2.0",
|
||||||
"description": "A GitHub action for setting up Rust and Cargo.",
|
"description": "A GitHub action for setting up Rust and Cargo.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue