2019-10-16 15:12:53 +03:00
|
|
|
import {input} from '@actions-rs/core';
|
2020-01-13 15:31:26 +02:00
|
|
|
import {info, debug} from "@actions/core";
|
|
|
|
import {existsSync, readFileSync} from 'fs';
|
2019-09-12 16:44:29 +03:00
|
|
|
|
|
|
|
export interface ToolchainOptions {
|
|
|
|
name: string,
|
2019-10-16 15:12:53 +03:00
|
|
|
target: string | undefined,
|
2019-09-12 16:44:29 +03:00
|
|
|
default: boolean,
|
2019-10-16 15:12:53 +03:00
|
|
|
override: boolean,
|
|
|
|
profile: string | undefined,
|
|
|
|
components: string[] | undefined,
|
2019-09-12 16:44:29 +03:00
|
|
|
}
|
|
|
|
|
2020-01-13 15:31:26 +02:00
|
|
|
export function toolchain_args(overrideFile: string): ToolchainOptions {
|
2019-10-16 15:12:53 +03:00
|
|
|
let components: string[] | undefined = input.getInputList('components');
|
|
|
|
if (components && components.length === 0) {
|
|
|
|
components = undefined;
|
|
|
|
}
|
2020-01-13 15:31:26 +02:00
|
|
|
|
2019-09-12 16:44:29 +03:00
|
|
|
return {
|
2020-01-13 15:31:26 +02:00
|
|
|
name: determineToolchain(overrideFile),
|
2019-10-16 15:12:53 +03:00
|
|
|
target: input.getInput('target') || undefined,
|
|
|
|
default: input.getInputBool('default'),
|
|
|
|
override: input.getInputBool('override'),
|
|
|
|
profile: input.getInput('profile') || undefined,
|
|
|
|
components: components,
|
2019-09-13 20:19:52 +03:00
|
|
|
};
|
2019-09-12 16:44:29 +03:00
|
|
|
}
|
2020-01-13 15:31:26 +02:00
|
|
|
|
|
|
|
function determineToolchain(overrideFile: string): string {
|
2020-01-17 14:21:07 +02:00
|
|
|
|
|
|
|
const toolchainInput = input.getInput('toolchain', {required: false});
|
|
|
|
|
|
|
|
if (toolchainInput) {
|
|
|
|
debug(`using toolchain from input: ${toolchainInput}`);
|
|
|
|
return toolchainInput
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!existsSync(overrideFile)) {
|
|
|
|
throw new Error("toolchain input was not given and repository does not have a rust-toolchain file")
|
2020-01-13 15:31:26 +02:00
|
|
|
}
|
2020-01-17 14:21:07 +02:00
|
|
|
|
|
|
|
const rustToolchainFile = readFileSync(overrideFile, {
|
|
|
|
encoding: "utf-8",
|
|
|
|
flag: "r"
|
|
|
|
}).trim();
|
|
|
|
|
|
|
|
debug(`using toolchain from rust-toolchain file: ${rustToolchainFile}`);
|
|
|
|
|
|
|
|
return rustToolchainFile;
|
2020-01-13 15:31:26 +02:00
|
|
|
}
|