mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-29 21:40:01 +00:00
Install rustup.
This commit is contained in:
parent
c5f1dc6e9e
commit
b00fdf0c6c
7 changed files with 46 additions and 12 deletions
34
index.ts
34
index.ts
|
@ -1,8 +1,39 @@
|
|||
import path from 'path';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import { CARGO_HOME, installBins, restoreCache } from './src/cargo';
|
||||
import { installToolchain } from './src/rust';
|
||||
|
||||
export async function installRustup() {
|
||||
try {
|
||||
await io.which('rustup', true);
|
||||
return;
|
||||
} catch {
|
||||
// Doesn't exist
|
||||
}
|
||||
|
||||
core.info('rustup does not exist, attempting to install');
|
||||
|
||||
const scriptPath = path.join(os.tmpdir(), 'rustup-init');
|
||||
const script = await tc.downloadTool(
|
||||
process.platform === 'win32' ? 'https://win.rustup.rs' : 'https://sh.rustup.rs',
|
||||
scriptPath,
|
||||
);
|
||||
|
||||
core.info(`Downloaded installation script to ${script}`);
|
||||
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
await fs.promises.chmod(script, 0o755);
|
||||
|
||||
await exec.exec(script, ['--default-toolchain', 'none', '-y']);
|
||||
|
||||
core.info('Installed rustup');
|
||||
}
|
||||
|
||||
async function run() {
|
||||
core.info('Setting cargo environment variables');
|
||||
|
||||
|
@ -14,6 +45,7 @@ async function run() {
|
|||
core.addPath(path.join(CARGO_HOME, 'bin'));
|
||||
|
||||
try {
|
||||
await installRustup();
|
||||
await installToolchain();
|
||||
await installBins();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue