Skip to content

Commit ebab191

Browse files
authored
Merge pull request dtolnay#31 from dtolnay/expr
Add toolchain expressions like '18 months ago'
2 parents 0f2a412 + dab5f91 commit ebab191

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,36 @@ jobs:
1818
matrix:
1919
name: [Linux]
2020
os: [ubuntu]
21-
rust: [nightly, beta, stable, 1.62.0, 1.0.0]
21+
rust: [nightly, beta, stable, 1.62.0, 1.0.0, 18 months ago, stable minus 8 releases]
2222
include:
2323
- name: macOS
2424
os: macos
2525
rust: nightly
2626
- name: macOS
2727
os: macos
2828
rust: 1.62.0
29+
- name: macOS
30+
os: macos
31+
rust: 18 months ago
32+
- name: macOS
33+
os: macos
34+
rust: stable minus 8 releases
2935
- name: Windows
3036
os: windows
3137
rust: nightly
3238
- name: Windows
3339
os: windows
3440
rust: 1.62.0
41+
- name: Windows
42+
os: windows
43+
rust: 18 months ago
44+
- name: Windows
45+
os: windows
46+
rust: stable minus 8 releases
3547
steps:
3648
- uses: actions/checkout@v3
3749
- uses: ./
38-
name: Run dtolnay/rust-toolchain@${{matrix.rust}}
50+
name: Run dtolnay/rust-toolchain${{contains(matrix.rust, ' ') && ' for ' || '@'}}${{matrix.rust}}
3951
id: toolchain
4052
with:
4153
toolchain: ${{matrix.rust}}

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
This GitHub Action installs a Rust toolchain using rustup. It is designed for
44
one-line concise usage and good defaults.
55

6+
<br>
7+
68
## Example workflow
79

810
```yaml
@@ -24,6 +26,8 @@ Action being requested. For example "dtolnay/rust-toolchain@nightly" pulls in
2426
the nightly Rust toolchain, while "dtolnay/[email protected]" pulls in
2527
1.42.0.
2628
29+
<br>
30+
2731
## Inputs
2832
2933
All inputs are optional.
@@ -51,6 +55,31 @@ All inputs are optional.
5155
</tr>
5256
</table>
5357
58+
<br>
59+
60+
## Toolchain expressions
61+
62+
The following forms are available for projects that use a sliding window of
63+
compiler support.
64+
65+
```yaml
66+
# Installs the most recent stable toolchain as of the specified time
67+
# offset, which may be written in years, months, weeks, or days.
68+
- uses: dtolnay/rust-toolchain@master
69+
with:
70+
toolchain: 18 months ago
71+
```
72+
73+
```yaml
74+
# Installs the stable toolchain which preceded the most recent one by
75+
# the specified number of minor versions.
76+
- uses: dtolnay/rust-toolchain@master
77+
with:
78+
toolchain: stable minus 8 releases
79+
```
80+
81+
<br>
82+
5483
## License
5584
5685
The scripts and documentation in this project are released under the [MIT

action.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ outputs:
2727
runs:
2828
using: composite
2929
steps:
30+
- id: parse
31+
run: |
32+
: parse toolchain version
33+
if [[ $toolchain =~ ^[0-9]+' '(year|month|week|day)s?' 'ago$ ]]; then
34+
if [[ ${{runner.os}} == macOS ]]; then
35+
echo "::set-output name=toolchain::1.$((($(date -v-$(sed 's/\([0-9]*\) \(.\).*/\1\2/' <<< $toolchain) +%s)/60/60/24-16569)/7/6))"
36+
else
37+
echo "::set-output name=toolchain::1.$((($(date --date "$toolchain" +%s)/60/60/24-16569)/7/6))"
38+
fi
39+
elif [[ $toolchain =~ ^stable' 'minus' '[0-9]+' 'releases?$ ]]; then
40+
echo "::set-output name=toolchain::1.$((($(date +%s)/60/60/24-16569)/7/6-${toolchain//[^0-9]/}))"
41+
else
42+
echo "::set-output name=toolchain::$toolchain"
43+
fi
44+
env:
45+
toolchain: ${{inputs.toolchain}}
46+
shell: bash
47+
3048
- id: flags
3149
run: |
3250
: construct rustup command line
@@ -47,18 +65,18 @@ runs:
4765
if: runner.os != 'Windows'
4866
shell: bash
4967
50-
- name: rustup toolchain install ${{inputs.toolchain}}
51-
run: rustup toolchain install ${{inputs.toolchain}}${{steps.flags.outputs.targets}}${{steps.flags.outputs.components}} --profile minimal${{steps.flags.outputs.downgrade}} --no-self-update
68+
- name: rustup toolchain install ${{steps.parse.outputs.toolchain}}
69+
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
5270
shell: bash
5371

54-
- run: rustup default ${{inputs.toolchain}}
72+
- run: rustup default ${{steps.parse.outputs.toolchain}}
5573
shell: bash
5674

5775
- id: rustc-version
5876
run: |
5977
: create cachekey
60-
DATE=$(rustc +${{inputs.toolchain}} --version --verbose | sed -ne 's/^commit-date: \(20[0-9][0-9]\)-\([01][0-9]\)-\([0-3][0-9]\)$/\1\2\3/p')
61-
HASH=$(rustc +${{inputs.toolchain}} --version --verbose | sed -ne 's/^commit-hash: //p')
78+
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')
79+
HASH=$(rustc +${{steps.parse.outputs.toolchain}} --version --verbose | sed -ne 's/^commit-hash: //p')
6280
echo "::set-output name=cachekey::$(echo $DATE$HASH | head -c12)"
6381
shell: bash
6482

@@ -67,5 +85,5 @@ runs:
6785
echo CARGO_INCREMENTAL=0 >> $GITHUB_ENV
6886
shell: bash
6987
70-
- run: rustc +${{inputs.toolchain}} --version --verbose
88+
- run: rustc +${{steps.parse.outputs.toolchain}} --version --verbose
7189
shell: bash

0 commit comments

Comments
 (0)