name: Rust CI

run-name: Rust CI | ${{ github.event_name }} by ${{ github.actor }} on '${{ github.ref_name }}'

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

jobs:
  discord-ci:
    name: Rust CI
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: .
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cache Cargo Dependencies
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-

      - name: Setup Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
          components: clippy, rustfmt

      - name: Run cargo-deny checks
        uses: EmbarkStudios/cargo-deny-action@v1
        with:
          command: "check bans sources"
          manifest-path: "./Cargo.toml"
          rust-version: "1.88.0"

      - name: Pre-build project
        run: cargo build

      - name: Check formatting
        run: cargo fmt --check

      - name: Lint with Clippy
        run: cargo clippy -- -D warnings

      - name: Run Tests
        run: cargo test
