diff --git a/README.md b/README.md index 86af5ee..0b1c2fe 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 8a52c54..6d0238e 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/src/rust.ts b/src/rust.ts index a2a2459..e80d628 100644 --- a/src/rust.ts +++ b/src/rust.ts @@ -94,17 +94,27 @@ export function detectToolchain(): Toolchain { }); } else { 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']) { - const configPath = path.join(process.cwd(), configName); + 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); - if (fs.existsSync(configPath)) { - core.debug(`Found ${configName}, parsing TOML`); + if (fs.existsSync(configPath)) { + core.debug(`Found ${configName}, parsing TOML`); - Object.assign(toolchain, parseConfig(configPath)); - break; - } - } + Object.assign(toolchain, parseConfig(configPath)); + break; + } + } + } } core.info('Inheriting toolchain settings from inputs');