Replace dtolnay/rust-toolchain with manual rustup#2340
Replace dtolnay/rust-toolchain with manual rustup#2340Eliah Kagan (EliahKagan) merged 1 commit intoGitoxideLabs:mainfrom
dtolnay/rust-toolchain with manual rustup#2340Conversation
Previously, we used manual `rustup` commands in some CI jobs, but the `dtolnay/rust-toolchain` action in most. That action handles various conditions nicely, and is also very convenient. One of the conditions it handles, on some operating systems, is even to install `rustup` itself, if absent. However, we don't seem to need any of its additional functionality now or in the immediately foreseeable future. Furthermore, as tracked at dtolnay/rust-toolchain#160, it doesn't have any specific version tags for its own versions, nor any tags at all for Rust versions (instead, Rust versions are specified either in `with` keys, or by specifying a *branch* of the action named as the version). This makes it so that it can't be pinned to a version in such a way that Dependabot (or similar tools like Renovatebot) can update it. That means if we want recent toolchains, we would either have to manually (or through some ad-hoc automated method) update it regularly, or continue to specify `@master` and `@stable` as we had been doing. The latter is incompatible with the Dependabot `cooldown` period set up recently to provide partial defense against supply chain attacks. `dtolnay/rust-toolchain` is overall high quality, and replacing it with a less used action would not necessarily confer a net gain in security. At least one other action is also actively maintained and may be mostly suitable, `actions-rust-lang/setup-rust-toolchain`, though it is less widely used. However, it wouldn't be easy to use that action correctly here, because on macOS it installs a newer version of `bash` via `brew`, placing it ahead of the very old `bash` 3 that ships with macOS. (Per actions-rust-lang/setup-rust-toolchain#10, it does this because its own script steps rely on some newer `bash` features.) It's important that the shell scripts in this repository, such as the fixture scripts run via `gix-testtools`, be run in `bash` 3 on macOS. Otherwise, we might break compatibility with most macOS systems, where often no newer `bash` has been installed. Thus, `actions-rust-lang/setup-rust-toolchain` won't work here as a drop-in replacement. Fortunately, because all the jobs using `dtolnay/rust-toolchain` run in environments that have a working `rustup` command, which is able to install the desired versions, it's enough to replace each use of that action with a small number of `rustup` commands (and adjust how data used to parameterize it is passed around, in a few cases). This makes that change. Because `dtolnay/rust-toolchain` is now no longer used, this change should resolve all non-suppressed Zizmor alerts, as well as most CodeQL alerts.
dc980b2 to
dec9954
Compare
Eliah Kagan (EliahKagan)
left a comment
There was a problem hiding this comment.
The expected code scanning alerts, from both CodeQL and Zizmor, were created and are visible in the Security tab, as intended in #2337. That's the main thing I wanted to check before merging this (which is expected to close most of the alerts, since it fixes the condition it describes).
The failure here that I mentioned in #2339 (review) looks like it's an occasional network error and not due to any changes here.
Therefore, I think this is ready to merge once its tests pass.
dtolnay/rust-toolchain with manual rustup commandsdtolnay/rust-toolchain with manual rustup
There was a problem hiding this comment.
Pull request overview
This PR replaces all uses of the dtolnay/rust-toolchain GitHub Action with manual rustup commands to address security concerns. The changes maintain functional equivalence while eliminating dependencies on third-party actions for Rust toolchain installation.
- Converts all toolchain installations to use
rustup update,rustup default, andrustup target addcommands - Moves environment variables to appropriate scopes (job-level or step-level) to support the manual installation approach
- Adds explicit
shell: bashspecifications where needed for cross-platform compatibility
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
.github/workflows/release.yml |
Replaces two instances of dtolnay/rust-toolchain with manual rustup commands; moves environment variables from step-level to job-level in the installation job for proper scoping |
.github/workflows/ci.yml |
Replaces six instances of dtolnay/rust-toolchain with manual rustup commands; adds shell: bash where needed for Windows/multi-OS jobs; converts component installation from action parameters to rustup component add |
These are actually just to be able to run a script step of multiple commands that stops and reports failure on the first failing command. Maybe this reason for using step-level |
If Copilot doesn't know that even, then I think it's very non-obvious. Even reading this I can't imagine why it has this behaviour except that it's something they explicitly put in to make using scripts easier, while having to keep the default behaviour backwards-compatible to not fail fast. |
I can put comments on every step-level I think we should also somehow make clearer (at least to humans reading the workflow file) why we're using different shells in the first place in some jobs, even when setting
I realized I forgot to reply to something earlier about this. I've done so now; see #1363 (comment). In short, PowerShell doesn't quite have this feature, and also it makes different judgments from POSIX-compatble shells about what constitutes an error. But it almost has it, such that the default behavior on CI for PowerShell should maybe be different from what it is currently. The situation is:
The different |
|
Thanks a lot for sharing, I learned a lot! |
- Add missing comments on step-level `shell: bash` that were introduced without them in GitoxideLabs#2340. - Add a conceptual comment where step-level `shell: bash` is intentionally omitted for the main nextest step of the `test-fast` jobs. These changes are as discussed in GitoxideLabs#2340 comments, in particular: GitoxideLabs#2340 (comment)
This builds on #2337 by replacing all uses of
dtolnay/rust-toolchainwithrustupcommands, as described in the "Plan" section there. See the commit message here (dc980b2) for considerable details including background, rationale, and why an alternative action was not as good of a choice.I first attempted to do this change (within my fork) via a Copilot PR. An error occurred, but the generated prompt in EliahKagan#141 (if one expands the details) is potentially a useful alternative summary. The diff here is the same as what Copilot would've done.
Analogous to that release test of changes to
release.ymlin #2337, a release test achieved by cherry-picking the commit used there onto this branch was done in this release test. (That was before rebasing this, but the rebase was just to bring this ahead of the merge commit--it didn't change the contents ofrelease.ymlor anything else.) Based on that, this seems not to breakrelease.yml(so it should work again once some production-suitable fix/workaround for #2338 is devised).However, this PR remains a draft until I check that the expected security scanning alerts, for both CodeQL and Zizmor, have appeared in the Security tab due to #2337. (Most of them should then go away as a result of this PR.)