name: CI

# Define the triggers; usually merges to the repository
# default branch and pull-requests
on:
  push:
    branches:
      - main
  pull_request:
    types:
      - opened
      - reopened
      - synchronize

env:
  CARGO_TERM_COLOR: always

defaults:
  run:
    shell: bash

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v3
      - name: Set up Rust cache
        uses: Swatinem/rust-cache@v2
      - name: Check formatting
        run: cargo fmt --all -- --check
      - name: Run Clippy
        run: cargo clippy --all-features -- -D warnings
      - name: Reject uncommitted changes
        run: git diff --exit-code
      - name: Build documentation
        run: cargo doc --no-deps --document-private-items --all-features --workspace
        env:
          RUSTDOCFLAGS: -D warnings
      - name: Run `cross-compiler`
        run: cargo run --package cross-compiler

  test:
    name: Test
    strategy:
      matrix:
        os:
          - ubuntu-latest
          - macOS-latest
          - windows-latest
    runs-on: ${{matrix.os}}
    steps:
      - name: Check out repository
        uses: actions/checkout@v3
      - name: Set up Rust cache
        uses: Swatinem/rust-cache@v2
      - name: Run `cargo build`
        run: cargo build --all-features
      - name: Run `cargo test`
        run: cargo test --all-features
      - name: Run `export-validator`
        run: cargo run --package export-validator
