2020-03-24 21:26:10 +08:00
|
|
|
import * as core from "@actions/core";
|
2020-01-13 21:31:26 +08:00
|
|
|
import path from "path";
|
2019-09-12 21:44:29 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
import * as args from "./args";
|
|
|
|
import * as versions from "./versions";
|
|
|
|
import { RustUp, ToolchainOptions } from "@actions-rs/core";
|
2019-09-14 01:19:52 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
async function run(): Promise<void> {
|
2020-01-13 21:31:26 +08:00
|
|
|
// we use path.join to make sure this works on Windows, Linux and MacOS
|
2020-03-24 21:26:10 +08:00
|
|
|
const toolchainOverridePath = path.join(process.cwd(), "rust-toolchain");
|
2020-01-13 21:31:26 +08:00
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
const opts = args.getToolchainArgs(toolchainOverridePath);
|
2019-10-16 20:12:53 +08:00
|
|
|
const rustup = await RustUp.getOrInstall();
|
2020-03-24 21:26:10 +08:00
|
|
|
await rustup.call(["show"]);
|
2019-09-14 01:19:52 +08:00
|
|
|
|
2019-10-16 20:12:53 +08:00
|
|
|
let shouldSelfUpdate = false;
|
2020-03-24 21:26:10 +08:00
|
|
|
if (opts.profile && !(await rustup.supportProfiles())) {
|
2019-10-16 20:12:53 +08:00
|
|
|
shouldSelfUpdate = true;
|
|
|
|
}
|
2020-03-24 21:26:10 +08:00
|
|
|
if (opts.components && !(await rustup.supportComponents())) {
|
2019-10-16 20:12:53 +08:00
|
|
|
shouldSelfUpdate = true;
|
|
|
|
}
|
|
|
|
if (shouldSelfUpdate) {
|
2020-03-24 21:26:10 +08:00
|
|
|
core.startGroup("Updating rustup");
|
2019-10-16 20:12:53 +08:00
|
|
|
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) {
|
2020-03-24 21:26:10 +08:00
|
|
|
// @ts-ignore: TS2345
|
2019-10-16 20:12:53 +08:00
|
|
|
await rustup.setProfile(opts.profile);
|
2019-09-14 16:57:12 +08:00
|
|
|
}
|
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
const installOptions: ToolchainOptions = {
|
2019-10-16 20:12:53 +08:00
|
|
|
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
|
|
|
}
|
2020-03-24 21:26:10 +08:00
|
|
|
|
|
|
|
// Extra funny case.
|
|
|
|
// Due to `rustup` issue (https://github.com/rust-lang/rustup/issues/2146)
|
|
|
|
// right now installing `nightly` toolchain with extra components might fail
|
|
|
|
// if that specific `nightly` version does not have this component
|
|
|
|
// available.
|
|
|
|
//
|
|
|
|
// See https://github.com/actions-rs/toolchain/issues/53 also.
|
|
|
|
//
|
|
|
|
// By default `rustup` does not downgrade, as it does when you are
|
|
|
|
// updating already installed `nightly`, so we need to pass the
|
|
|
|
// corresponding flag manually.
|
|
|
|
//
|
|
|
|
// We are doing it only if both following conditions apply:
|
|
|
|
//
|
|
|
|
// 1. Requested toolchain is `"nightly"` (exact string match).
|
|
|
|
// 2. At least one component is requested.
|
|
|
|
//
|
|
|
|
// All other cases are not triggering automatic downgrade,
|
|
|
|
// for example, installing specific nightly version
|
|
|
|
// as in `"nightly-2020-03-20"` or `"stable"`.
|
|
|
|
//
|
|
|
|
// Motivation is that users probably want the latest one nightly
|
|
|
|
// with rustfmt and clippy (miri, etc) and they don't really care
|
|
|
|
// about what exact nightly it is.
|
|
|
|
// In case if it's not the nightly at all or it is a some specific
|
|
|
|
// nightly version, they know what they are doing.
|
|
|
|
if (opts.name == "nightly" && opts.components) {
|
|
|
|
installOptions.allowDowngrade = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2020-01-26 23:18:21 +08:00
|
|
|
|
|
|
|
await versions.gatherInstalledVersions();
|
2019-09-15 17:24:13 +08:00
|
|
|
}
|
|
|
|
|
2020-03-24 21:26:10 +08:00
|
|
|
async function main(): Promise<void> {
|
2019-09-15 17:24:13 +08:00
|
|
|
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();
|