mirror of
https://github.com/dtolnay/rust-toolchain.git
synced 2025-06-07 19:26:37 +00:00
Initial version
This commit is contained in:
commit
644dd49b85
12 changed files with 5315 additions and 0 deletions
41
src/args.ts
Normal file
41
src/args.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export interface ToolchainOptions {
|
||||
name: string,
|
||||
default: boolean,
|
||||
override: boolean
|
||||
}
|
||||
|
||||
export function toolchain_args(): ToolchainOptions {
|
||||
return {
|
||||
name: getInput('toolchain', {required: true}),
|
||||
default: inputBoolean('default'),
|
||||
override: inputBoolean('override')
|
||||
}
|
||||
}
|
27
src/main.ts
Normal file
27
src/main.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
import * as args from './args';
|
||||
|
||||
async function do_exec(program: string, args: string[]) {
|
||||
try {
|
||||
await exec.exec(program, args);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
let opts = args.toolchain_args();
|
||||
await do_exec('rustup', ['toolchain', 'install', opts.name]);
|
||||
|
||||
if (opts.default) {
|
||||
await do_exec('rustup', ['default', opts.name]);
|
||||
}
|
||||
|
||||
if (opts.override) {
|
||||
await do_exec('rustup', ['override', opts.name]);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
Loading…
Add table
Add a link
Reference in a new issue