Skip to content

Commit

Permalink
Bug fixing and chores related to linting (#121)
Browse files Browse the repository at this point in the history
This PR tackles a few issues with how `bevy_lint` functions.

First, it closes #117 by passing `--cfg bevy_lint` to `rustc` when
`bevy_lint` is called. This allows code to conditionally configure lints
(e.g. `#[cfg_attr(bevy_lint, allow(bevy::lint))]`).

Secondly, it fixes #118 by specifying the nightly version when calling
`cargo check`. I originally hardcoded this version, but after a comment
from @richchurcher I adjusted it to take the version from
`rust-toolchain.toml`. (It specifically uses a build script to parse
`rust-toolchain.toml` using `toml_edit`, then passes it to the code
using an environmental variable.)

Thirdly, I removed other hard-coded references to the specifically
nightly channel in `README.md` and `ci.yml`. (In CI I specifically used
[Taplo](https://taplo.tamasfe.dev) to parse the version, similar to
[`jq`](https://jqlang.github.io/jq/).)

Finally, I added a bit more metadata to `Cargo.toml` that will be used
by <https://crates.io> once it is published.
  • Loading branch information
BD103 authored Oct 2, 2024
1 parent 5cd2719 commit f586dd5
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 140 deletions.
51 changes: 38 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,36 @@ on:
pull_request:
workflow_dispatch:

env:
# Keep this in sync with `rust-toolchain.toml`.
RUST_TOOLCHAIN: nightly-2024-08-21
RUST_COMPONENTS: rustc-dev, llvm-tools-preview

jobs:
# Find the nightly Rust version and required components from `rust-toolchain.toml` using
# <https://taplo.tamasfe.dev>, so that we install can install them in later jobs.
extract-rust-version:
name: Extract Rust version
runs-on: ubuntu-latest
outputs:
channel: ${{ steps.toolchain.outputs.toolchain }}
components: ${{ steps.toolchain.outputs.components }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Taplo
run: |
curl -fsSL https://github.com/tamasfe/taplo/releases/latest/download/taplo-linux-x86_64.gz \
| gzip -d - | install -m 755 /dev/stdin /usr/local/bin/taplo
- name: Extract toolchain
id: toolchain
run: |
TOOLCHAIN=$(taplo get -f='rust-toolchain.toml' 'toolchain.channel')
COMPONENTS=$(taplo get -f='rust-toolchain.toml' --separator=', ' 'toolchain.components')
echo toolchain=$TOOLCHAIN >> $GITHUB_OUTPUT
echo components=$COMPONENTS >> $GITHUB_OUTPUT
test:
name: Run tests
needs: extract-rust-version
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
Expand All @@ -25,8 +47,8 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: ${{ env.RUST_COMPONENTS }}
toolchain: ${{ needs.extract-rust-version.outputs.channel }}
components: ${{ needs.extract-rust-version.outputs.components }}

- name: Cache build artifacts
uses: Leafwing-Studios/cargo-cache@v2
Expand All @@ -42,6 +64,7 @@ jobs:
clippy:
name: Check with Clippy
needs: extract-rust-version
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -50,8 +73,8 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: '${{ env.RUST_COMPONENTS }}, clippy'
toolchain: ${{ needs.extract-rust-version.outputs.channel }}
components: '${{ needs.extract-rust-version.outputs.components }}, clippy'

- name: Cache build artifacts
uses: Leafwing-Studios/cargo-cache@v2
Expand All @@ -63,6 +86,7 @@ jobs:

rustfmt:
name: Check with rustfmt
needs: extract-rust-version
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -71,14 +95,15 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: '${{ env.RUST_COMPONENTS }}, rustfmt'
toolchain: ${{ needs.extract-rust-version.outputs.channel }}
components: '${{ needs.extract-rust-version.outputs.components }}, rustfmt'

- name: Run rustfmt
run: cargo fmt --all --check

docs:
name: Build docs
needs: extract-rust-version
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -87,8 +112,8 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: ${{ env.RUST_COMPONENTS }}
toolchain: ${{ needs.extract-rust-version.outputs.channel }}
components: ${{ needs.extract-rust-version.outputs.components }}

- name: Cache build artifacts
uses: Leafwing-Studios/cargo-cache@v2
Expand Down
Loading

0 comments on commit f586dd5

Please sign in to comment.