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 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` `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 ```toml
# rust-toolchain.toml # rust-toolchain.toml

View file

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

View file

@ -94,17 +94,27 @@ export function detectToolchain(): Toolchain {
}); });
} else { } else {
core.info('Loading rust-toolchain.toml or rust-toolchain file'); core.info('Loading rust-toolchain.toml or rust-toolchain file');
const toolchainFile = core.getInput('rust-toolchain-file');
for (const configName of ['rust-toolchain.toml', 'rust-toolchain']) { if (toolchainFile) {
const configPath = path.join(process.cwd(), configName); 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);
if (fs.existsSync(configPath)) { if (fs.existsSync(configPath)) {
core.debug(`Found ${configName}, parsing TOML`); core.debug(`Found ${configName}, parsing TOML`);
Object.assign(toolchain, parseConfig(configPath)); Object.assign(toolchain, parseConfig(configPath));
break; break;
} }
} }
}
} }
core.info('Inheriting toolchain settings from inputs'); core.info('Inheriting toolchain settings from inputs');