Skip to content

Make linter action more ergonomic #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 8, 2025
Merged

Make linter action more ergonomic #501

merged 3 commits into from
Jul 8, 2025

Conversation

BD103
Copy link
Member

@BD103 BD103 commented Jul 1, 2025

Context

The Github Action we provide for the linter isn't great. It works well for installing from a release or from main, but breaks down when installing a specific commit. This is because we currently hardcode values in action.yml:

# This must be kept in sync with `rust-toolchain.toml`.
toolchain: nightly-2025-05-14

# The toolchain must be kept in sync with `rust-toolchain.toml`. The `--branch main` should
# be swapped with `--tag lint-vX.Y.Z` for releases.
rustup run nightly-2025-05-14 cargo install \
--git https://github.com/TheBevyFlock/bevy_cli.git \
--branch main \
--locked \
bevy_lint

This is an extra maintenance burden that we shouldn't have to do! If the user wants to install a specific commit of the linter, it should work as expected instead of installing the main branch:

# Should install this specific commit of the linter, but installs `main` instead.
- name: Install `bevy_lint`
  uses: TheBevyFlock/bevy_cli/bevy_lint@ff8d39a

Solution

Thankfully, the fix is easier than expected. action.yml is a composite action, meaning it's a single YAML file that slings around other actions and shell scripts to do things. The great thing about this is that, when an action runner downloads a composite action, it downloads the entire repository. That means rust-toolchain.toml and the correct source code for bevy_lint already exist, we just have to install them!

This PR does just that. It uses the venerable Taplo to read rust-toolchain.toml and then runs cargo install --path ... to install the linter. The action especially uses the ${{ github.action_path }} variable to locate the bevy_lint folder.

Testing

linter-action.yml is doing a lot of the heavy-lifting here by testing the linter action in CI. I'll also spin up a separate repository to prove it works for others as well!

@BD103 BD103 added A-Build-System Related to CI and GitHub Actions A-Linter Related to the linter and custom lints C-Usability An improvement that makes the API more pleasant D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jul 1, 2025
@BD103 BD103 force-pushed the better-linter-action branch 7 times, most recently from f2721eb to fb9e9b2 Compare July 1, 2025 20:01
@BD103 BD103 changed the title Improve linter action Make linter action more ergonomic Jul 1, 2025
@BD103 BD103 force-pushed the better-linter-action branch from 8a74023 to 342f1fe Compare July 1, 2025 20:16
@BD103 BD103 added S-Needs-Review The PR needs to be reviewed before it can be merged and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jul 1, 2025
@BD103 BD103 marked this pull request as ready for review July 1, 2025 20:16
@BD103 BD103 added D-Straightforward Simple bug fixes and API improvements, docs, test and examples and removed D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Jul 1, 2025
@BD103 BD103 requested a review from TimJentzsch July 1, 2025 20:22
@BD103 BD103 added this to the `bevy_lint` v0.4.0 milestone Jul 3, 2025
Copy link
Collaborator

@TimJentzsch TimJentzsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cant test right now, but the code makes sense!
If it works in a separate repository feel free to merge this :)

--path "${BEVY_LINT_PATH}" \
--locked
env:
RUST_CHANNEL: ${{ steps.toolchain.outputs.channel }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We could remove the env variable here and directly use the step output, right?
No strong preference though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to. While it's not an issue in this specific case, directly inlining templates can lead to code injection vulnerabilities, so I avoid doing so out of habit! (It's the same reason I use "${VAR}" :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that's fine for me :)

@@ -12,20 +12,39 @@ description: |
runs:
using: composite
steps:
# Used to read `rust-toolchain.toml`.
- name: Install Taplo
uses: taiki-e/install-action@v2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we control the toolchain file and it doesn't look too complex, I wonder if we could accomplish the same without installing an additional tool.
That could speed up the CI time.

On the other hand, we'd need to be careful to make it work on all platforms, so it probably makes sense to investigate this in a separate issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a good follow-up. We could probably use grep to capture the toolchain version with a few clever comments, like what Clippy does.

@BD103
Copy link
Member Author

BD103 commented Jul 8, 2025

Tested in BD103/linter-action/test, specifically this run. Merging now!

@BD103 BD103 merged commit f38247d into main Jul 8, 2025
13 checks passed
@BD103 BD103 deleted the better-linter-action branch July 8, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Build-System Related to CI and GitHub Actions A-Linter Related to the linter and custom lints C-Usability An improvement that makes the API more pleasant D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review The PR needs to be reviewed before it can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants