name: CI

on:
  pull_request:
  push:
    branches:
      - master

jobs:
  test:
    name: Tests
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        channel:
          - stable
          - nightly
          - 1.63.0 # MSRV of test dependencies
        os:
          - macos-13 # x86 MacOS
          - macos-15 # Arm MacOS
          - windows-2025
          - ubuntu-24.04
        include:
          - channel: beta
            os: ubuntu-24.04

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Update rust
      run: |
        rustup default ${{ matrix.channel }}
        rustup update --no-self-update

    - run: cargo test --all

  msrv:
    name: Check building with the MSRV
    runs-on: ubuntu-24.04
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Update rust
      run: |
        rustup default 1.23.0
        rustup update --no-self-update

    - run: cargo build

  success:
    needs:
      - test
      - msrv
    runs-on: ubuntu-latest
    # GitHub branch protection is exceedingly silly and treats "jobs skipped because a dependency
    # failed" as success. So we have to do some contortions to ensure the job fails if any of its
    # dependencies fails.
    if: always() # make sure this is never "skipped"
    steps:
      # Manually check the status of all dependencies. `if: failure()` does not work.
      - name: check if any dependency failed
        run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
