name: Build

on:
  workflow_dispatch:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: '-Dwarnings'

jobs:
  rustfmt:
    runs-on: ubuntu-latest
    name: 'Formatting'
    steps:
      - uses: actions/checkout@v4

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


  clippy-base:
    runs-on: ubuntu-latest
    name: 'Clippy (Base features)'
    steps:
      - uses: actions/checkout@v4

      - uses: Swatinem/rust-cache@v2
        name: Cache dependencies

      - name: Install build deps
        run: ./.github/scripts/ubuntu_setup.sh

      - name: Clippy
        run: cargo clippy --no-default-features
        env:
          RUSTFLAGS: '-W clippy::unwrap_used'


  clippy-all:
    runs-on: ubuntu-latest
    name: 'Clippy (All features)'
    steps:
      - uses: actions/checkout@v4

      - uses: Swatinem/rust-cache@v2
        name: Cache dependencies

      - name: Install build deps
        run: ./.github/scripts/ubuntu_setup.sh

      - name: Clippy
        run: cargo clippy --all-targets --all-features
        env:
          RUSTFLAGS: '-W clippy::unwrap_used'


  build:
    name: 'Build & Test'
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: Swatinem/rust-cache@v2
        name: Cache dependencies

      - name: Install build deps
        run: ./.github/scripts/ubuntu_setup.sh

      - name: Build
        run: cargo build --all-features --verbose

      - name: Run tests
        uses: actions-rs/cargo@v1
        with:
          command: test
