name: Check Rust

on:
  push:
    branches-ignore:
      - gh-readonly-queue/**
  pull_request:
  merge_group:

jobs:
  rustdoc:
    runs-on: ubuntu-latest
    env:
      CARGO_HTTP_MULTIPLEXING: false
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
    - name: Cache Rust dependencies
      uses: Swatinem/rust-cache@v2
    - name: Run Rustdoc
      run: |
        RUSTDOCFLAGS=-Dwarnings DDNET_TEST_NO_LINK=1 cargo doc

  rustfmt:
    runs-on: ubuntu-latest
    env:
      CARGO_HTTP_MULTIPLEXING: false
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
    - name: Cache Rust dependencies
      uses: Swatinem/rust-cache@v2
      with:
           workspaces: |
               src/mastersrv
               src/masterping
               ./
    - name: Run Rustfmt
      run:
        cargo fmt -- --check

  cargo-deny:
    runs-on: ubuntu-latest
    env:
      CARGO_HTTP_MULTIPLEXING: false
    strategy:
      matrix:
        checks:
          - advisories
          - bans licenses sources
    continue-on-error: ${{ matrix.checks == 'advisories' }}
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
    - name: Cache Rust dependencies
      uses: Swatinem/rust-cache@v2
      with:
          workspaces:  |
              src/mastersrv
              src/masterping
              ./
    - uses: EmbarkStudios/cargo-deny-action@v1
      with:
        command: check ${{ matrix.checks }}
