Dont prioritze rust-toolchain file over input variable (#45)

This commit is contained in:
Thomas Eizinger 2020-01-17 23:21:07 +11:00 committed by svartalf
parent 6a1db6369e
commit d8323be6bd
5 changed files with 41 additions and 15 deletions

View file

@ -4,7 +4,13 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### [1.0.3] - 2019-10-19 ## [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 ### Added

View file

@ -40,6 +40,16 @@ describe('actions-rs/toolchain', () => {
'INPUT_TOOLCHAIN': 'nightly', '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") expect(args.name).toBe("1.39.0")
}); });
@ -48,9 +58,7 @@ describe('actions-rs/toolchain', () => {
let args = morph(() => { let args = morph(() => {
return toolchain_args(rustToolchainFile); return toolchain_args(rustToolchainFile);
}, { }, {});
'INPUT_TOOLCHAIN': 'nightly',
});
expect(args.name).toBe("1.39.0") expect(args.name).toBe("1.39.0")
}); });

View file

@ -10,6 +10,9 @@ inputs:
Rust toolchain name. Rust toolchain name.
See https://github.com/rust-lang/rustup.rs#toolchain-specification See https://github.com/rust-lang/rustup.rs#toolchain-specification
If this is not given, the action will try and install the version specified in the `rust-toolchain` file.
required: false
target: target:
description: Target triple to install for this toolchain description: Target triple to install for this toolchain
required: false required: false

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View file

@ -28,15 +28,24 @@ export function toolchain_args(overrideFile: string): ToolchainOptions {
} }
function determineToolchain(overrideFile: string): string { function determineToolchain(overrideFile: string): string {
if (existsSync(overrideFile)) {
debug(`using toolchain override from ${overrideFile}`); const toolchainInput = input.getInput('toolchain', {required: false});
const content = readFileSync(overrideFile, {
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", encoding: "utf-8",
flag: "r" flag: "r"
}); }).trim();
return content.trim();
} else { debug(`using toolchain from rust-toolchain file: ${rustToolchainFile}`);
debug(`toolchain override file ${overrideFile} does not exist, falling back to input variable`);
return input.getInput('toolchain', {required: true}) return rustToolchainFile;
}
} }