Skip to content

Commit 5840045

Browse files
committed
feat: restore original toolchain if installed
1 parent d90e664 commit 5840045

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

bevy_lint/action.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ description: |
66
This action currently uses Rustup to install the required toolchain components, and it uses
77
`cargo install` to install the linter itself. The linter will be installed to `~/.cargo/bin` and
88
will be available through the `PATH` by default.
9-
10-
Note that this currently will override the default Rustup toolchain to nightly. You can fix this
11-
by calling `rustup default` after this action is run.
129
runs:
1310
using: composite
1411
steps:
12+
# `dtolnay/rust-toolchain` overrides the default toolchain. We track what the original default
13+
# is and restore it afterwards.
14+
- name: Save original toolchain
15+
id: original-toolchain
16+
shell: bash
17+
# This may fail if Rustup is not installed, in which case we continue anyways.
18+
continue-on-error: true
19+
run: |
20+
# This prints what toolchain is installed, such as "stable-aarch64-apple-darwin (default)".
21+
DEFAULT="$(rustup default)"
22+
23+
# We use `%` to strip "(default)" from the end of the output.
24+
echo "original-toolchain=${DEFAULT%(default)}" >> "${GITHUB_OUTPUT}"
25+
1526
- name: Install Rust toolchain and components
1627
uses: dtolnay/rust-toolchain@master
1728
with:
@@ -29,3 +40,12 @@ runs:
2940
--branch main \
3041
--locked \
3142
bevy_lint
43+
44+
- name: Restore original toolchain
45+
# If Rustup wasn't installed, causing `original-toolchain` to fail, we don't need to restore
46+
# the original toolchain since there wasn't one in the first place!
47+
if: ${{ steps.original-toolchain.outcome != 'failure' }}
48+
shell: bash
49+
env:
50+
ORIGINAL_TOOLCHAIN: ${{ steps.original-toolchain.outputs.original-toolchain }}
51+
run: rustup default "${ORIGINAL_TOOLCHAIN}"

0 commit comments

Comments
 (0)