mirror of
https://github.com/dtolnay/rust-toolchain.git
synced 2025-06-08 03:36:37 +00:00
Allow to override toolchain from rust-toolchain file (#35)
This commit is contained in:
parent
e2aeba25b2
commit
6a1db6369e
10 changed files with 168 additions and 34 deletions
22
src/args.ts
22
src/args.ts
|
@ -1,5 +1,6 @@
|
|||
import * as core from '@actions/core';
|
||||
import {input} from '@actions-rs/core';
|
||||
import {info, debug} from "@actions/core";
|
||||
import {existsSync, readFileSync} from 'fs';
|
||||
|
||||
export interface ToolchainOptions {
|
||||
name: string,
|
||||
|
@ -10,13 +11,14 @@ export interface ToolchainOptions {
|
|||
components: string[] | undefined,
|
||||
}
|
||||
|
||||
export function toolchain_args(): ToolchainOptions {
|
||||
export function toolchain_args(overrideFile: string): ToolchainOptions {
|
||||
let components: string[] | undefined = input.getInputList('components');
|
||||
if (components && components.length === 0) {
|
||||
components = undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
name: input.getInput('toolchain', {required: true}),
|
||||
name: determineToolchain(overrideFile),
|
||||
target: input.getInput('target') || undefined,
|
||||
default: input.getInputBool('default'),
|
||||
override: input.getInputBool('override'),
|
||||
|
@ -24,3 +26,17 @@ export function toolchain_args(): ToolchainOptions {
|
|||
components: components,
|
||||
};
|
||||
}
|
||||
|
||||
function determineToolchain(overrideFile: string): string {
|
||||
if (existsSync(overrideFile)) {
|
||||
debug(`using toolchain override from ${overrideFile}`);
|
||||
const content = readFileSync(overrideFile, {
|
||||
encoding: "utf-8",
|
||||
flag: "r"
|
||||
});
|
||||
return content.trim();
|
||||
} else {
|
||||
debug(`toolchain override file ${overrideFile} does not exist, falling back to input variable`);
|
||||
return input.getInput('toolchain', {required: true})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
import path from "path";
|
||||
|
||||
import * as args from './args';
|
||||
import {RustUp, ToolchainOptions} from '@actions-rs/core';
|
||||
|
||||
async function run() {
|
||||
const opts = args.toolchain_args();
|
||||
// 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);
|
||||
const rustup = await RustUp.getOrInstall();
|
||||
await rustup.call(['show']);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue