Install rustup
only on MacOS
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as rustup from './rustup';
|
||||
import * as os from 'os';
|
||||
|
||||
@@ -8,6 +9,8 @@ async function run() {
|
||||
|
||||
if(version) {
|
||||
await rustup.install(version);
|
||||
|
||||
exec.exec('rustup', ['default', version]);
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
|
@@ -6,68 +6,32 @@ import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import {chmodSync} from 'fs';
|
||||
|
||||
let osPlat: string = os.platform();
|
||||
let osArch: string = os.arch();
|
||||
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
||||
const WINDOWS: boolean = osPlat == 'win32';
|
||||
|
||||
export async function install(version: string) {
|
||||
let toolPath = toolCache.find('rust', version);
|
||||
if (os.platform() == 'darwin') {
|
||||
let toolPath = await acquireRust(version);
|
||||
|
||||
if (!toolPath) {
|
||||
toolPath = await acquireRust(version);
|
||||
core.debug('Rust toolchain is cached under ' + toolPath);
|
||||
}
|
||||
|
||||
toolPath = path.join(toolPath, 'bin');
|
||||
core.addPath(toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
}
|
||||
}
|
||||
|
||||
async function acquireRust(version: string): Promise<string> {
|
||||
let script: string;
|
||||
|
||||
try {
|
||||
script = await toolCache.downloadTool(rustupUrl());
|
||||
script = await toolCache.downloadTool("https://sh.rustup.rs");
|
||||
} catch (error) {
|
||||
core.debug(error);
|
||||
throw `Failed to download rustup: ${error}`;
|
||||
}
|
||||
|
||||
if(WINDOWS) {
|
||||
await io.cp(script, script + '.exe');
|
||||
script += '.exe';
|
||||
chmodSync(script, '777');
|
||||
await exec.exec(`"${script}"`, ['-y', '--default-toolchain', 'none']);
|
||||
|
||||
console.log(await io.which('rustup', true));
|
||||
let cargo = path.join(process.env['HOME'] || '', '.cargo');
|
||||
|
||||
await exec.exec(
|
||||
`"${script}"`,
|
||||
[
|
||||
'-y',
|
||||
'--default-toolchain',
|
||||
'none',
|
||||
]
|
||||
);
|
||||
} else {
|
||||
chmodSync(script, '777');
|
||||
|
||||
await exec.exec(`"${script}"`, ['-y', '--default-toolchain', version]);
|
||||
}
|
||||
|
||||
return await toolCache.cacheDir(binRoot(), 'rust', version);
|
||||
}
|
||||
|
||||
function rustupUrl(): string {
|
||||
if(WINDOWS) {
|
||||
return "https://win.rustup.rs"
|
||||
} else {
|
||||
return "https://sh.rustup.rs"
|
||||
}
|
||||
}
|
||||
|
||||
function binRoot(): string {
|
||||
if(WINDOWS) {
|
||||
return path.join(process.env['USERPROFILE'] || '', '.cargo');
|
||||
} else {
|
||||
return path.join(process.env['HOME'] || '', '.cargo');
|
||||
}
|
||||
return await toolCache.cacheDir(cargo, 'rust', version);
|
||||
}
|
||||
|
Reference in New Issue
Block a user