Invert the priority order of the input and the rust-toolchain file
1. Not doing so would be a breaking change for users who have a rust-toolchain file with a different version from what they specify in the input. 2. Not doing so makes it overly complicated to install a specific version. Imagine you want to test your software against the version in the rust-toolchain file and nightly as-well. Without this patch, users will have the replace the content of the rust-toolchain file because it is prioritized over the input. It makes a lot more sense to prioritize the input over the file because that one is easier changed.
This commit is contained in:
parent
9cf95ed753
commit
568a53bc9a
|
@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Support for the `rust-toolchain` file: If the toolchain input is not given, we will try and install the version specified in the `rust-toolchain` file.
|
||||
|
||||
## [1.0.3] - 2019-10-19
|
||||
|
||||
### Added
|
||||
|
|
|
@ -40,6 +40,16 @@ describe('actions-rs/toolchain', () => {
|
|||
'INPUT_TOOLCHAIN': 'nightly',
|
||||
});
|
||||
|
||||
expect(args.name).toBe("nightly")
|
||||
});
|
||||
|
||||
it('uses rust-toolchain file if input does not exist', function () {
|
||||
let rustToolchainFile = tempWriteSync("1.39.0");
|
||||
|
||||
let args = morph(() => {
|
||||
return toolchain_args(rustToolchainFile);
|
||||
}, {});
|
||||
|
||||
expect(args.name).toBe("1.39.0")
|
||||
});
|
||||
|
||||
|
@ -48,9 +58,7 @@ describe('actions-rs/toolchain', () => {
|
|||
|
||||
let args = morph(() => {
|
||||
return toolchain_args(rustToolchainFile);
|
||||
}, {
|
||||
'INPUT_TOOLCHAIN': 'nightly',
|
||||
});
|
||||
}, {});
|
||||
|
||||
expect(args.name).toBe("1.39.0")
|
||||
});
|
||||
|
|
|
@ -10,6 +10,7 @@ inputs:
|
|||
Rust toolchain name.
|
||||
|
||||
See https://github.com/rust-lang/rustup.rs#toolchain-specification
|
||||
required: false
|
||||
target:
|
||||
description: Target triple to install for this toolchain
|
||||
required: false
|
||||
|
|
File diff suppressed because one or more lines are too long
29
src/args.ts
29
src/args.ts
|
@ -28,15 +28,24 @@ export function toolchain_args(overrideFile: string): ToolchainOptions {
|
|||
}
|
||||
|
||||
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})
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
const rustToolchainFile = readFileSync(overrideFile, {
|
||||
encoding: "utf-8",
|
||||
flag: "r"
|
||||
}).trim();
|
||||
|
||||
debug(`using toolchain from rust-toolchain file: ${rustToolchainFile}`);
|
||||
|
||||
return rustToolchainFile;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue