Add option to specify the toolchain config file

This commit is contained in:
Stefan Kuhn 2023-04-23 11:46:38 +00:00
parent 21cbaddcd4
commit afaa4e3396
3 changed files with 21 additions and 9 deletions

View file

@ -17,7 +17,7 @@ jobs:
This action will automatically install the appropriate toolchain with `rustup` by inspecting the
`RUSTUP_TOOLCHAIN` environment variable or the `rust-toolchain.toml` (preferred) or `rust-toolchain`
configuration files. If no toolchain found, will default to `stable`.
configuration files. To specify the location of the toolchain configuration files you can use `rust-toolchain-file` option. If no toolchain found, will default to `stable`.
```toml
# rust-toolchain.toml

View file

@ -9,6 +9,8 @@ inputs:
cache:
description: 'Toggle caching of ~/.cargo/registry and /target/debug directories.'
default: true
rust-toolchain-file:
description: 'Path to a rust-toolchain file to install.'
channel:
description: 'Toolchain specification/channel to install.'
components:

View file

@ -94,7 +94,16 @@ export function detectToolchain(): Toolchain {
});
} else {
core.info('Loading rust-toolchain.toml or rust-toolchain file');
const toolchainFile = core.getInput('rust-toolchain-file');
if (toolchainFile) {
if (fs.existsSync(toolchainFile)) {
Object.assign(toolchain, parseConfig(toolchainFile));
} else {
core.setFailed('Not found toolchain config file');
throw new Error('Not found toolchain config file');
}
} else {
for (const configName of ['rust-toolchain.toml', 'rust-toolchain']) {
const configPath = path.join(process.cwd(), configName);
@ -106,6 +115,7 @@ export function detectToolchain(): Toolchain {
}
}
}
}
core.info('Inheriting toolchain settings from inputs');