mirror of
https://github.com/dtolnay/rust-toolchain.git
synced 2025-06-08 03:36:37 +00:00
Profiles and components support
This commit is contained in:
parent
74865b8fc9
commit
f0a61e6769
10 changed files with 5143 additions and 891 deletions
47
src/args.ts
47
src/args.ts
|
@ -1,43 +1,26 @@
|
|||
import * as core from '@actions/core';
|
||||
|
||||
// Workaround for a GH bug: https://github.com/actions/toolkit/issues/127
|
||||
//
|
||||
// For input `all-features: true` it will generate the `INPUT_ALL-FEATURES: true`
|
||||
// env variable, which looks too weird.
|
||||
// Here we are trying to get proper name `INPUT_NO_DEFAULT_FEATURES` first,
|
||||
// and if it does not exist, trying the `INPUT_NO-DEFAULT-FEATURES`
|
||||
function getInput(name: string, options?: core.InputOptions): string {
|
||||
const inputFullName = name.replace(/-/g, '_');
|
||||
let value = core.getInput(inputFullName, options);
|
||||
if (value.length > 0) {
|
||||
return value
|
||||
}
|
||||
|
||||
return core.getInput(name)
|
||||
}
|
||||
|
||||
function inputBoolean(name: string): boolean {
|
||||
const value = getInput(name);
|
||||
if (value == 'true' || value == '1') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
import {input} from '@actions-rs/core';
|
||||
|
||||
export interface ToolchainOptions {
|
||||
name: string,
|
||||
target?: string,
|
||||
target: string | undefined,
|
||||
default: boolean,
|
||||
override: boolean
|
||||
override: boolean,
|
||||
profile: string | undefined,
|
||||
components: string[] | undefined,
|
||||
}
|
||||
|
||||
export function toolchain_args(): ToolchainOptions {
|
||||
let components: string[] | undefined = input.getInputList('components');
|
||||
if (components && components.length === 0) {
|
||||
components = undefined;
|
||||
}
|
||||
return {
|
||||
name: getInput('toolchain', {required: true}),
|
||||
target: getInput('target') || undefined,
|
||||
default: inputBoolean('default'),
|
||||
override: inputBoolean('override')
|
||||
name: input.getInput('toolchain', {required: true}),
|
||||
target: input.getInput('target') || undefined,
|
||||
default: input.getInputBool('default'),
|
||||
override: input.getInputBool('override'),
|
||||
profile: input.getInput('profile') || undefined,
|
||||
components: components,
|
||||
};
|
||||
}
|
||||
|
|
109
src/main.ts
109
src/main.ts
|
@ -1,91 +1,52 @@
|
|||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const https = require('https');
|
||||
|
||||
const download = require('download');
|
||||
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
|
||||
import * as args from './args';
|
||||
|
||||
function downloadRustInit(url: string, name: string): Promise<string> {
|
||||
const absPath = path.join(os.tmpdir(), name);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let req = download(url);
|
||||
let output = fs.createWriteStream(absPath, {
|
||||
mode: 0o755
|
||||
});
|
||||
|
||||
req.pipe(output);
|
||||
req.on('end', () => {
|
||||
output.close(resolve);
|
||||
});
|
||||
req.on('error', reject);
|
||||
output.on('error', reject);
|
||||
})
|
||||
.then(() => {
|
||||
return absPath;
|
||||
});
|
||||
}
|
||||
|
||||
async function get_rustup(toolchain: string): Promise<string> {
|
||||
try {
|
||||
const foundPath = await io.which('rustup', true);
|
||||
core.debug(`Found rustup at ${foundPath}`);
|
||||
return foundPath;
|
||||
} catch (error) {
|
||||
core.info('Unable to find rustup, installing it now');
|
||||
}
|
||||
|
||||
let args = [
|
||||
'-y',
|
||||
'--default-toolchain',
|
||||
toolchain,
|
||||
];
|
||||
|
||||
// Note: `target` input can't be used here for `--default-host` argument, see #8
|
||||
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
case 'linux': // Should be installed already, but just in case
|
||||
const rustupSh = await downloadRustInit('https://sh.rustup.rs', 'rustup-init.sh');
|
||||
await exec.exec(rustupSh, args);
|
||||
break;
|
||||
|
||||
case 'win32':
|
||||
const rustupExe = await downloadRustInit('http://win.rustup.rs', 'rustup-init.exe');
|
||||
await exec.exec(rustupExe, args);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown platform ${process.platform}, can't install rustup`);
|
||||
}
|
||||
|
||||
core.addPath(path.join(process.env['HOME'], '.cargo', 'bin'));
|
||||
|
||||
return 'rustup';
|
||||
}
|
||||
import {RustUp, ToolchainOptions} from '@actions-rs/core';
|
||||
|
||||
async function run() {
|
||||
const opts = args.toolchain_args();
|
||||
const rustup = await get_rustup(opts.name);
|
||||
const rustup = await RustUp.getOrInstall();
|
||||
await rustup.call(['show']);
|
||||
|
||||
await exec.exec(rustup, ['toolchain', 'install', opts.name]);
|
||||
|
||||
if (opts.default) {
|
||||
await exec.exec(rustup, ['default', opts.name]);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.override) {
|
||||
await exec.exec(rustup, ['override', 'set', opts.name]);
|
||||
if (opts.profile) {
|
||||
//@ts-ignore
|
||||
await rustup.setProfile(opts.profile);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
await rustup.installToolchain(opts.name, installOptions);
|
||||
|
||||
if (opts.target) {
|
||||
await exec.exec(rustup, ['target', 'add', '--toolchain', opts.name, opts.target]);
|
||||
await rustup.addTarget(opts.target, opts.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue