setup-rust-action/src/rustup.ts

38 lines
1.0 KiB
TypeScript
Raw Normal View History

2019-08-15 18:12:08 +00:00
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import * as toolCache from '@actions/tool-cache';
import * as path from 'path';
import * as os from 'os';
import {chmodSync} from 'fs';
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
export async function install(version: string) {
2019-08-15 21:22:17 +00:00
if (os.platform() == 'darwin') {
let toolPath = await acquireRust(version);
2019-08-15 18:12:08 +00:00
core.debug('Rust toolchain is cached under ' + toolPath);
2019-08-15 21:22:17 +00:00
core.addPath(path.join(toolPath, 'bin'));
}
2019-08-15 18:12:08 +00:00
}
async function acquireRust(version: string): Promise<string> {
let script: string;
try {
2019-08-15 21:22:17 +00:00
script = await toolCache.downloadTool("https://sh.rustup.rs");
2019-08-15 18:12:08 +00:00
} catch (error) {
core.debug(error);
throw `Failed to download rustup: ${error}`;
}
2019-08-15 21:22:17 +00:00
chmodSync(script, '777');
await exec.exec(`"${script}"`, ['-y', '--default-toolchain', 'none']);
2019-08-15 18:12:08 +00:00
2019-08-15 21:22:17 +00:00
let cargo = path.join(process.env['HOME'] || '', '.cargo');
2019-08-15 18:12:08 +00:00
2019-08-15 21:22:17 +00:00
return await toolCache.cacheDir(cargo, 'rust', version);
2019-08-15 18:12:08 +00:00
}