Only support a rust-toolchain.toml file

This commit is contained in:
David Sherret 2023-03-09 15:21:05 -05:00
parent e12eda571d
commit 9bde10f6e6
4 changed files with 39 additions and 165 deletions

View file

@ -2,7 +2,7 @@ name: CI
on: on:
push: push:
branches: [master] branches: [main]
pull_request: pull_request:
workflow_dispatch: workflow_dispatch:
schedule: [cron: "40 1 * * *"] schedule: [cron: "40 1 * * *"]
@ -25,8 +25,13 @@ jobs:
timeout-minutes: 45 timeout-minutes: 45
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Create toolchain file
run: |
echo "[toolchain]" >> rust-toolchain.toml
echo "channel = \"${{matrix.rust}}\"" >> rust-toolchain.toml
cat rust-toolchain.toml
- uses: ./ - uses: ./
name: Run dtolnay/rust-toolchain${{contains(matrix.rust, ' ') && ' for ' || '@'}}${{matrix.rust}} name: Run dsherret/rust-toolchain-file${{contains(matrix.rust, ' ') && ' for ' || '@'}}${{matrix.rust}}
id: toolchain id: toolchain
with: with:
toolchain: ${{matrix.rust}} toolchain: ${{matrix.rust}}

View file

@ -1,12 +1,19 @@
# Install Rust Toolchain # Install Rust Toolchain via rust-toolchain.toml
This GitHub Action installs a Rust toolchain using rustup. It is designed for Fork of https://github.com/dtolnay/rust-toolchain that supports and makes it mandatory to use a rust-toolchain.toml file.
one-line concise usage and good defaults.
<br>
## Example workflow ## Example workflow
Create a [`rust-toolchain.toml`](https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file) file:
```toml
[toolchain]
channel = "1.68"
components = [ "rustfmt", "clippy" ]
```
Then add an entry to this action in your github actions:
```yaml ```yaml
name: test suite name: test suite
on: [push, pull_request] on: [push, pull_request]
@ -17,45 +24,15 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable - uses: dsherret/rust-toolchain-file@1
- run: cargo test --all-features - run: cargo test --all-features
``` ```
The selection of Rust toolchain is made based on the particular @rev of this The selection of Rust toolchain is made based on the rust-toolchain.toml file.
Action being requested. For example "dtolnay/rust-toolchain@nightly" pulls in
the nightly Rust toolchain, while "dtolnay/rust-toolchain@1.42.0" pulls in
1.42.0.
<br>
## Inputs ## Inputs
All inputs are optional. None. You must define everything in the rust-toolchain.toml file.
<table>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
<tr>
<td><code>toolchain</code></td>
<td>
Rustup toolchain specifier e.g. <code>stable</code>, <code>nightly</code>, <code>1.42.0</code>, <code>nightly-2022-01-01</code>.
<b>Important: the default is to match the @rev as described above.</b>
When passing an explicit <code>toolchain</code> as an input instead of @rev, you'll want to use "dtolnay/rust-toolchain@master" as the revision of the action.
</td>
</tr>
<tr>
<td><code>targets</code></td>
<td>Comma-separated string of additional targets to install e.g. <code>wasm32-unknown-unknown</code></td>
</tr>
<tr>
<td><code>components</code></td>
<td>Comma-separated string of additional components to install e.g. <code>clippy, rustfmt</code></td>
</tr>
</table>
<br>
## Outputs ## Outputs
@ -74,31 +51,6 @@ All inputs are optional.
</tr> </tr>
</table> </table>
<br>
## Toolchain expressions
The following forms are available for projects that use a sliding window of
compiler support.
```yaml
# Installs the most recent stable toolchain as of the specified time
# offset, which may be written in years, months, weeks, or days.
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable 18 months ago
```
```yaml
# Installs the stable toolchain which preceded the most recent one by
# the specified number of minor versions.
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable minus 8 releases
```
<br>
## License ## License
The scripts and documentation in this project are released under the [MIT The scripts and documentation in this project are released under the [MIT

View file

@ -1,24 +1,10 @@
name: rustup toolchain install name: rust-toolchain.toml setup
author: David Tolnay author: David Tolnay, David Sherret
description: Install the Rust toolchain description: Install the Rust toolchain via a rust-toolchain.toml file
branding: branding:
icon: activity icon: activity
color: purple color: purple
inputs:
toolchain:
description: Rust toolchain specification -- see https://rust-lang.github.io/rustup/concepts/toolchains.html#toolchain-specification
required: true
targets:
description: Comma-separated list of target triples to install for this toolchain
required: false
target:
description: Alias for `targets`
required: false
components:
description: Comma-separated list of components to be additionally installed
required: false
outputs: outputs:
cachekey: cachekey:
description: A short hash of the rustc version, appropriate for use as a cache key. "20220627a831" description: A short hash of the rustc version, appropriate for use as a cache key. "20220627a831"
@ -30,22 +16,17 @@ outputs:
runs: runs:
using: composite using: composite
steps: steps:
- id: parse - id: ensure-toolchain-file
run: | run: |
: parse toolchain version if [[ -f "rust-toolchain" || -f "rust-toolchain.toml" ]]
if [[ $toolchain =~ ^stable' '[0-9]+' '(year|month|week|day)s?' 'ago$ ]]; then then
if [[ ${{runner.os}} == macOS ]]; then echo "found toolchain"
echo "toolchain=1.$((($(date -v-$(sed 's/stable \([0-9]*\) \(.\).*/\1\2/' <<< $toolchain) +%s)/60/60/24-16569)/7/6))" >> $GITHUB_OUTPUT
else else
echo "toolchain=1.$((($(date --date "${toolchain#stable }" +%s)/60/60/24-16569)/7/6))" >> $GITHUB_OUTPUT echo "No rust-toolchain or rust-toolchain.toml file found in repo."
echo "Please ensure the repo is checked out first or add this file."
echo "If you don't want this file, then please use https://github.com/dtolnay/rust-toolchain"
exit 1
fi fi
elif [[ $toolchain =~ ^stable' 'minus' '[0-9]+' 'releases?$ ]]; then
echo "toolchain=1.$((($(date +%s)/60/60/24-16569)/7/6-${toolchain//[^0-9]/}))" >> $GITHUB_OUTPUT
else
echo "toolchain=$toolchain" >> $GITHUB_OUTPUT
fi
env:
toolchain: ${{inputs.toolchain}}
shell: bash shell: bash
- id: flags - id: flags
@ -68,18 +49,15 @@ runs:
if: runner.os != 'Windows' if: runner.os != 'Windows'
shell: bash shell: bash
- name: rustup toolchain install ${{steps.parse.outputs.toolchain}} - name: rustup toolchain install
run: rustup toolchain install ${{steps.parse.outputs.toolchain}}${{steps.flags.outputs.targets}}${{steps.flags.outputs.components}} --profile minimal${{steps.flags.outputs.downgrade}} --no-self-update run: rustup toolchain install --no-self-update
shell: bash
- run: rustup default ${{steps.parse.outputs.toolchain}}
shell: bash shell: bash
- id: rustc-version - id: rustc-version
run: | run: |
: create cachekey : create cachekey
DATE=$(rustc +${{steps.parse.outputs.toolchain}} --version --verbose | sed -ne 's/^commit-date: \(20[0-9][0-9]\)-\([01][0-9]\)-\([0-3][0-9]\)$/\1\2\3/p') 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')
HASH=$(rustc +${{steps.parse.outputs.toolchain}} --version --verbose | sed -ne 's/^commit-hash: //p') HASH=$(rustc --version --verbose | sed -ne 's/^commit-hash: //p')
echo "cachekey=$(echo $DATE$HASH | head -c12)" >> $GITHUB_OUTPUT echo "cachekey=$(echo $DATE$HASH | head -c12)" >> $GITHUB_OUTPUT
shell: bash shell: bash
@ -102,7 +80,7 @@ runs:
# except on 1.66 and 1.67, on which it is unstable # except on 1.66 and 1.67, on which it is unstable
if [ -z "${CARGO_REGISTRIES_CRATES_IO_PROTOCOL+set}" -o -f "${{runner.temp}}"/.implicit_cargo_registries_crates_io_protocol ]; then if [ -z "${CARGO_REGISTRIES_CRATES_IO_PROTOCOL+set}" -o -f "${{runner.temp}}"/.implicit_cargo_registries_crates_io_protocol ]; then
touch "${{runner.temp}}"/.implicit_cargo_registries_crates_io_protocol || true touch "${{runner.temp}}"/.implicit_cargo_registries_crates_io_protocol || true
if rustc +${{steps.parse.outputs.toolchain}} --version --verbose | (! grep -q '^release: 1\.6[67]\.'); then if rustc --version --verbose | (! grep -q '^release: 1\.6[67]\.'); then
echo CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse >> $GITHUB_ENV echo CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse >> $GITHUB_ENV
else else
echo CARGO_REGISTRIES_CRATES_IO_PROTOCOL=git >> $GITHUB_ENV echo CARGO_REGISTRIES_CRATES_IO_PROTOCOL=git >> $GITHUB_ENV
@ -110,5 +88,5 @@ runs:
fi fi
shell: bash shell: bash
- run: rustc +${{steps.parse.outputs.toolchain}} --version --verbose - run: rustc --version --verbose
shell: bash shell: bash

View file

@ -1,61 +0,0 @@
#!/bin/bash
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
if ! git diff-index --quiet HEAD; then
echo "Not running update-revs.sh because git working directory is dirty" >&2
exit 1
fi
patch_releases=(
1.12.1 1.15.1 1.22.1 1.24.1 1.26.1 1.26.2 1.27.1 1.27.2 1.29.1 1.29.2 1.30.1
1.31.1 1.34.1 1.34.2 1.41.1 1.43.1 1.44.1 1.45.1 1.45.2 1.52.1 1.56.1 1.58.1
1.62.1 1.66.1 1.67.1
)
releases() {
printf "%s\n" 1.{0..70}.0 ${patch_releases[@]} | sort -V
}
base=$(git rev-parse HEAD)
push=()
declare -A minor
for rev in `releases`; do
minor[${rev%.*}]=$rev
done
for rev in `releases` stable beta nightly; do
echo "Updating $rev branch"
git checkout --quiet "$base"
git branch --quiet --delete --force $rev &>/dev/null || true
sed -i "s/required: true/required: false\n default: $rev/" action.yml
git add action.yml
git commit --quiet --message "toolchain: $rev"
git checkout --quiet -b $rev
push+=("$rev:refs/heads/$rev")
if [ "${minor[${rev%.*}]}" == $rev ]; then
push+=("$rev:refs/heads/${rev%.*}")
fi
done
for tool in clippy miri; do
echo "Updating $tool branch"
git checkout --quiet --detach nightly
git branch --quiet --delete --force $tool &>/dev/null || true
if [ $tool == miri ]; then
default="miri, rust-src"
echo -e " - uses: dtolnay/install@xargo\n with:\n bin: xargo-check" >> action.yml
else
default=$tool
fi
sed -i "/required: false/{N;s/\n$/\n default: $default\n/}" action.yml
git add action.yml
git commit --quiet --message "components: $tool"
git checkout --quiet -b $tool
push+=("$tool:refs/heads/$tool")
done
git checkout --quiet "$base"
echo "git push origin --force-with-lease ${push[@]}"