name: Tests CI

on:
  push:
    branches:
      - master
  pull_request:
    branches: [master]

env:
  CARGO_TERM_COLOR: always
  SCCACHE_GHA_ENABLED: "true"
  SCCACHE_CACHE_SIZE: 2G
  RUSTC_WRAPPER: "sccache"

concurrency:
  group: tests-ci-${{ github.ref }}
  cancel-in-progress: true

jobs:
  tests:
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v6

      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
          components: clippy, rustfmt

      - uses: Swatinem/rust-cache@v2
      - uses: mozilla-actions/sccache-action@v0.0.9

      - name: Install deps before command run
        run: brew install cargo-audit cargo-deny

      - name: Generic clippy
        run: cargo clippy --no-deps -- -D warnings

      - name: Security check
        run: cargo audit

      - name: Generic testing and format check
        run: |
          cargo test --quiet
          cargo fmt --all -- --check

      - run: sccache --show-stats || true
