name: CI

on:
  push:
    branches: [main]
  pull_request:
  workflow_dispatch:
  merge_group:
    types: [checks_requested]

jobs:
  linux-ci:
    name: Linux
    runs-on: ubuntu-latest
    strategy:
      matrix:
        features: ["", "--features serde", "--no-default-features --features libm"]
        version: ["1.56.0", "stable", "beta", "nightly"]
        include:
          - version: stable
            features: --features mint
          - version: stable
            features: --features bytemuck
          - version: stable
            features: --features arbitrary
          - version: nightly
            features: --features unstable
          - version: nightly
            features: --features unstable,serde
        
    steps:
      - uses: actions/checkout@v3

      - name: Install toolchain
        uses: dtolnay/rust-toolchain@v1
        with:
          toolchain: ${{ matrix.version }}

      - name: Cargo build
        run: cargo build ${{ matrix.features }}

      - name: Cargo test
        run: cargo test ${{ matrix.features }}
        env:
          RUST_BACKTRACE: 1

  fmt:
    name: Check code formatting
    runs-on: ubuntu-latest
    steps:
      # GitHub runners already have a usable version of cargo & rustfmt, so an install is not needed
      - uses: actions/checkout@v3
      - run: cargo fmt --check

  build_result:
    name: Result
    runs-on: ubuntu-latest
    needs:
      - "linux-ci"

    steps:
      - name: Mark the job as successful
        run: exit 0
        if: success()
      - name: Mark the job as unsuccessful
        run: exit 1
        if: "!success()"
