foxtrot 0.1.0

A 3D reference project and tech demo for the Bevy Engine.
name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

env:
  # Use the same Rust toolchain across jobs so they can share a cache.
  toolchain: nightly-2025-04-03

jobs:
  # Run tests.
  test:
    name: Tests
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          components: rustc-codegen-cranelift-preview
          toolchain: ${{ env.toolchain }}

      - name: Set LD_LIBRARY_PATH
        id: ld_library_path
        run: |
          # Setting LD_LIBRARY_PATH is a workaround for <https://github.com/TheBevyFlock/bevy_new_2d/pull/318#issuecomment-2585935350>.
          echo "LD_LIBRARY_PATH=$(rustc --print target-libdir)" >> $GITHUB_ENV

      - name: Populate target directory from cache
        uses: Swatinem/rust-cache@v2
        with:
          save-if: ${{ github.ref == 'refs/heads/main' }}
          cache-directories: ${{ env.LD_LIBRARY_PATH }}

      - name: Install dependencies
        run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev

      - name: Active CI cargo config
        run: mv .cargo/config_ci.toml .cargo/config.toml

      - name: Install cargo binstall
        uses: cargo-bins/cargo-binstall@main

      - name: Install Wild
        run: cargo binstall wild-linker --locked --force

      - name: Install nextest
        run: cargo binstall cargo-nextest --locked --force

      - name: Run tests
        run: cargo nextest run --locked --workspace --all-targets --no-fail-fast --no-tests warn

      # Running doc tests separately is a workaround for <https://github.com/rust-lang/cargo/issues/6669>.
      - name: Run doctests
        run: cargo test --locked --workspace --doc
        # Failing until we have a `lib.rs` again
        continue-on-error: true

  # Check that the game builds for web.
  build-web:
    name: Check build for web
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          targets: wasm32-unknown-unknown
          toolchain: ${{ env.toolchain }}

      - name: Active CI cargo config
        run: mv .cargo/config_ci.toml .cargo/config.toml

      - name: Install cargo binstall
        uses: cargo-bins/cargo-binstall@main

      - name: Install Wild
        run: cargo binstall wild-linker --locked --force

      - name: Install dependencies
        run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev

      - name: Populate target directory from cache
        uses: Swatinem/rust-cache@v2
        with:
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Check build for web
        run: cargo check --config 'profile.web.inherits="dev"' --features dev --no-default-features --profile web --target wasm32-unknown-unknown

  # Run clippy lints.
  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          components: clippy, rustc-codegen-cranelift-preview
          toolchain: ${{ env.toolchain }}

      - name: Active CI cargo config
        run: mv .cargo/config_ci.toml .cargo/config.toml

      - name: Install cargo binstall
        uses: cargo-bins/cargo-binstall@main

      - name: Install Wild
        run: cargo binstall wild-linker --locked --force

      - name: Install dependencies
        run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev

      - name: Populate target directory from cache
        uses: Swatinem/rust-cache@v2
        with:
          save-if: false
          shared-key: lints

      - name: Run clippy lints
        run: cargo clippy --locked --workspace --all-targets --all-features -- --deny warnings

  # Check formatting.
  format:
    name: Format
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          components: rustfmt
          toolchain: ${{ env.toolchain }}

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

  # Check documentation.
  doc:
    name: Docs
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          components: rustc-codegen-cranelift-preview
          toolchain: ${{ env.toolchain }}

      - name: Active CI cargo config
        run: mv .cargo/config_ci.toml .cargo/config.toml

      - name: Install cargo binstall
        uses: cargo-bins/cargo-binstall@main

      - name: Install Wild
        run: cargo binstall wild-linker --locked --force

      - name: Install dependencies
        run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev

      - name: Populate target directory from cache
        uses: Swatinem/rust-cache@v2
        with:
          save-if: false
          shared-key: lints

      - name: Check documentation
        run: cargo doc --locked --workspace --all-features --document-private-items --no-deps

  # Run Bevy lints.
  bevy-lint:
    name: Bevy linter
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install dependencies
        run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev

      - name: Populate target directory from cache
        uses: Swatinem/rust-cache@v2
        with:
          save-if: ${{ github.ref == 'refs/heads/main' }}
          shared-key: lints

      - name: Install Bevy linter
        uses: TheBevyFlock/bevy_cli/bevy_lint@lint-v0.3.0

      - name: Add cranelift to rustc
        run: rustup component add rustc-codegen-cranelift-preview --toolchain ${{ env.toolchain }}

      - name: Active CI cargo config
        run: mv .cargo/config_ci.toml .cargo/config.toml

      - name: Install cargo binstall
        uses: cargo-bins/cargo-binstall@main

      - name: Install Wild
        run: cargo binstall wild-linker --locked --force

      - name: Run Bevy linter
        run: bevy_lint --locked --workspace --all-targets --all-features