2019-09-12 21:44:29 +08:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as exec from '@actions/exec';
|
2019-09-14 01:19:52 +08:00
|
|
|
import * as io from '@actions/io';
|
2020-01-13 21:31:26 +08:00
|
|
|
import path from "path";
|
2019-09-12 21:44:29 +08:00
|
|
|
|
|
|
|
import * as args from './args';
|
2019-10-16 20:12:53 +08:00
|
|
|
import {RustUp, ToolchainOptions} from '@actions-rs/core';
|
2019-09-14 01:19:52 +08:00
|
|
|
|
2019-09-12 21:44:29 +08:00
|
|
|
async function run() {
|
2020-01-13 21:31:26 +08:00
|
|
|
// we use path.join to make sure this works on Windows, Linux and MacOS
|
|
|
|
let toolchainOverrideFile = path.join(process.cwd(), "rust-toolchain");
|
|
|
|
|
|
|
|
const opts = args.toolchain_args(toolchainOverrideFile);
|
2019-10-16 20:12:53 +08:00
|
|
|
const rustup = await RustUp.getOrInstall();
|
|
|
|
await rustup.call(['show']);
|
2019-09-14 01:19:52 +08:00
|
|
|
|
2019-10-16 20:12:53 +08:00
|
|
|
let shouldSelfUpdate = false;
|
|
|
|
if (opts.profile && !await rustup.supportProfiles()) {
|
|
|
|
shouldSelfUpdate = true;
|
|
|
|
}
|
|
|
|
if (opts.components && !await rustup.supportComponents()) {
|
|
|
|
shouldSelfUpdate = true;
|
|
|
|
}
|
|
|
|
if (shouldSelfUpdate) {
|
|
|
|
core.startGroup('Updating rustup');
|
|
|
|
try {
|
|
|
|
await rustup.selfUpdate();
|
|
|
|
} finally {
|
|
|
|
core.endGroup();
|
|
|
|
}
|
|
|
|
}
|
2019-09-14 16:57:12 +08:00
|
|
|
|
2019-10-16 20:12:53 +08:00
|
|
|
if (opts.profile) {
|
|
|
|
//@ts-ignore
|
|
|
|
await rustup.setProfile(opts.profile);
|
2019-09-14 16:57:12 +08:00
|
|
|
}
|
|
|
|
|
2019-10-16 20:12:53 +08:00
|
|
|
let installOptions: ToolchainOptions = {
|
|
|
|
default: opts.default,
|
|
|
|
override: opts.override,
|
|
|
|
};
|
|
|
|
if (opts.components) {
|
|
|
|
installOptions.components = opts.components;
|
|
|
|
}
|
|
|
|
// We already did it just now, there is no reason to do that again,
|
|
|
|
// so it would skip few network calls.
|
|
|
|
if (shouldSelfUpdate) {
|
|
|
|
installOptions.noSelfUpdate = true;
|
2019-09-14 16:57:12 +08:00
|
|
|
}
|
2019-10-16 20:12:53 +08:00
|
|
|
await rustup.installToolchain(opts.name, installOptions);
|
2019-09-14 16:57:12 +08:00
|
|
|
|
|
|
|
if (opts.target) {
|
2019-10-16 20:12:53 +08:00
|
|
|
await rustup.addTarget(opts.target, opts.name);
|
2019-09-15 17:24:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
try {
|
|
|
|
await run();
|
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
2019-09-14 16:57:12 +08:00
|
|
|
}
|
2019-09-12 21:44:29 +08:00
|
|
|
}
|
|
|
|
|
2019-09-15 17:24:13 +08:00
|
|
|
main();
|