├── .github └── workflows │ └── ci.yml ├── LICENSE ├── README.md └── action.yml /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | workflow_dispatch: 8 | schedule: [cron: "40 1 * * *"] 9 | 10 | permissions: 11 | contents: read 12 | 13 | jobs: 14 | install: 15 | name: Rust ${{matrix.rust}} on ${{matrix.os == 'ubuntu' && 'Linux' || matrix.os == 'macos' && 'macOS' || matrix.os == 'windows' && 'Windows' || '???'}} 16 | runs-on: ${{matrix.os}}-latest 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | os: [ubuntu, macos, windows] 21 | rust: [nightly, beta, stable, 1.62.0] 22 | include: 23 | - os: ubuntu 24 | rust: 1.0.0 25 | timeout-minutes: 45 26 | steps: 27 | - uses: actions/checkout@v3 28 | - name: Create toolchain file 29 | shell: bash 30 | run: | 31 | echo "[toolchain]" >> rust-toolchain.toml 32 | echo "channel = \"${{matrix.rust}}\"" >> rust-toolchain.toml 33 | cat rust-toolchain.toml 34 | - uses: ./ 35 | name: Run dsherret/rust-toolchain-file${{contains(matrix.rust, ' ') && ' for ' || '@'}}${{matrix.rust}} 36 | id: toolchain 37 | - name: echo ${{'${{steps.toolchain.outputs.cachekey}}'}} 38 | run: echo '${{steps.toolchain.outputs.cachekey}}' 39 | - name: check ${{'${{steps.toolchain.outputs.cachekey}}'}} 40 | if: matrix.rust == '1.62.0' 41 | run: cmp -s <(echo ${{steps.toolchain.outputs.cachekey}}) <(echo 20220627a831) 42 | shell: bash 43 | - run: rustc --version 44 | - run: cargo init . --bin --name CI 45 | if: matrix.rust == 'nightly' || matrix.rust == 'beta' || matrix.rust == 'stable' 46 | - run: cargo add syn@1 47 | if: matrix.rust == 'nightly' || matrix.rust == 'beta' || matrix.rust == 'stable' 48 | - run: cargo check 49 | if: matrix.rust == 'nightly' || matrix.rust == 'beta' || matrix.rust == 'stable' 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any 2 | person obtaining a copy of this software and associated 3 | documentation files (the "Software"), to deal in the 4 | Software without restriction, including without 5 | limitation the rights to use, copy, modify, merge, 6 | publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software 8 | is furnished to do so, subject to the following 9 | conditions: 10 | 11 | The above copyright notice and this permission notice 12 | shall be included in all copies or substantial portions 13 | of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Install Rust Toolchain via rust-toolchain.toml 2 | 3 | GitHub Action to install Rust's toolchain via the 4 | [`rust-toolchain.toml`](https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file) 5 | file in your repository. 6 | 7 | Fork of https://github.com/dtolnay/rust-toolchain that supports and makes it 8 | mandatory to use a rust-toolchain.toml file. Unfortunately `rust-toolchain` did 9 | not want to support installing from a rust-toolchain.toml file, so this project 10 | exists. If you do not want to use a rust-toolchain.toml file, then please use 11 | that project as this action does not support other inputs. 12 | 13 | Note: GitHub actions now 14 | [automatically sets up](https://github.com/actions-rs/toolchain/issues/126#issuecomment-1463045252) 15 | the Rust version based on the rust-toolchain.toml, but it won't setup the other 16 | defaults from `dtolnay/rust-toolchain` for you like enabling colours on the CI 17 | as this action will. 18 | 19 | ## Example workflow 20 | 21 | 1. Create a 22 | [`rust-toolchain.toml`](https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file) 23 | file in the root directory of your repository: 24 | 25 | ```toml 26 | [toolchain] 27 | channel = "1.68" 28 | components = [ "rustfmt", "clippy" ] 29 | ``` 30 | 31 | 2. Add an entry to this action in your GitHub Actions workflow file (ensure the 32 | repo is checked out first): 33 | 34 | ```yaml 35 | name: test suite 36 | on: [push, pull_request] 37 | 38 | jobs: 39 | test: 40 | name: cargo test 41 | runs-on: ubuntu-latest 42 | steps: 43 | - uses: actions/checkout@v3 44 | - uses: dsherret/rust-toolchain-file@v1 45 | - run: cargo test --all-features 46 | ``` 47 | 48 | The selection of Rust toolchain on the CI will then be made based on the 49 | rust-toolchain.toml file enabling you to easily keep it in sync with your local 50 | development versions and have a single source of truth for what version to use. 51 | 52 | ## Inputs 53 | 54 | You must define everything in the rust-toolchain.toml file. 55 | 56 | ## Outputs 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 |
NameDescription
cachekeyA short hash of the installed rustc version, appropriate for use as a cache key. "20220627a831"
nameRustup's name for the selected version of the toolchain, like "1.62.0". Suitable for use with cargo +${{steps.toolchain.outputs.name}}.
72 | 73 | ## License 74 | 75 | The scripts and documentation in this project are released under the 76 | [MIT License]. 77 | 78 | [MIT License]: LICENSE 79 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: rust-toolchain.toml install 2 | author: David Tolnay, David Sherret 3 | description: Install the Rust toolchain via a rust-toolchain.toml file 4 | branding: 5 | icon: activity 6 | color: purple 7 | 8 | outputs: 9 | cachekey: 10 | description: A short hash of the rustc version, appropriate for use as a cache key. "20220627a831" 11 | value: ${{steps.rustc-version.outputs.cachekey}} 12 | name: 13 | description: Rustup's name for the selected version of the toolchain. "1.62.0" # suitable for use with `cargo +${{steps.toolchain.outputs.name}}` 14 | value: ${{steps.parse.outputs.toolchain}} 15 | 16 | runs: 17 | using: composite 18 | steps: 19 | - id: ensure-toolchain-file 20 | run: | 21 | if [[ -f "rust-toolchain" || -f "rust-toolchain.toml" ]] 22 | then 23 | echo "Found toolchain file" 24 | else 25 | echo "No rust-toolchain or rust-toolchain.toml file found in repo." 26 | echo "Please ensure the repo is checked out first or add this file." 27 | echo "If you don't want this file, then please use https://github.com/dtolnay/rust-toolchain" 28 | exit 1 29 | fi 30 | shell: bash 31 | 32 | # Note: GitHub actions will automatically use the Rust version specified in 33 | # the root directory, so we can skip the `rustup toolchain install` 34 | - run: | 35 | : install rustup if needed 36 | if ! command -v rustup &>/dev/null; then 37 | curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y 38 | source "${CARGO_HOME:-$HOME/.cargo}/env" 39 | echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH 40 | rustup show active-toolchain || rustup toolchain install 41 | fi 42 | if: runner.os != 'Windows' 43 | shell: bash 44 | 45 | - name: create cache key 46 | id: rustc-version 47 | run: | 48 | : create cachekey 49 | DATE=$(rustc --version --verbose | sed -ne 's/^commit-date: \(20[0-9][0-9]\)-\([01][0-9]\)-\([0-3][0-9]\)$/\1\2\3/p') 50 | HASH=$(rustc --version --verbose | sed -ne 's/^commit-hash: //p') 51 | echo "cachekey=$(echo $DATE$HASH | head -c12)" >> $GITHUB_OUTPUT 52 | shell: bash 53 | 54 | - run: | 55 | : disable incremental compilation 56 | if [ -z "${CARGO_INCREMENTAL+set}" ]; then 57 | echo CARGO_INCREMENTAL=0 >> $GITHUB_ENV 58 | fi 59 | shell: bash 60 | 61 | - run: | 62 | : enable colors in Cargo output 63 | if [ -z "${CARGO_TERM_COLOR+set}" ]; then 64 | echo CARGO_TERM_COLOR=always >> $GITHUB_ENV 65 | fi 66 | shell: bash 67 | 68 | - run: | 69 | : enable Cargo sparse registry 70 | # except on 1.66 and 1.67, on which it is unstable 71 | if [ -z "${CARGO_REGISTRIES_CRATES_IO_PROTOCOL+set}" -o -f "${{runner.temp}}"/.implicit_cargo_registries_crates_io_protocol ]; then 72 | touch "${{runner.temp}}"/.implicit_cargo_registries_crates_io_protocol || true 73 | if rustc --version --verbose | (! grep -q '^release: 1\.6[67]\.'); then 74 | echo CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse >> $GITHUB_ENV 75 | else 76 | echo CARGO_REGISTRIES_CRATES_IO_PROTOCOL=git >> $GITHUB_ENV 77 | fi 78 | fi 79 | shell: bash 80 | 81 | - run: rustc --version --verbose 82 | shell: bash 83 | --------------------------------------------------------------------------------