# Based on https://github.com/actions-rs/meta/blob/master/recipes/msrv.md

on: [push, pull_request]

name: CI

jobs:
  rustfmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: echo "::add-matcher::.github/workflows/rust-problem-matcher.json"
      - run: cargo fmt --all -- --check

  # Run clippy on stable only
  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - run: echo "::add-matcher::.github/workflows/rust-problem-matcher.json"
      - run: cargo clippy --all-features

  test-all:
    name: All Tests
    needs: [clippy, rustfmt]
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - stable
          - 1.64.0
          - beta
          - nightly
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
      - run: echo "::add-matcher::.github/workflows/rust-problem-matcher.json"
      - run: cargo test -q

  test-windows:
    name: Test on Windows
    needs: [clippy, rustfmt]
    runs-on: windows-latest
    strategy:
      matrix:
        rust:
          - stable
          - 1.64.0
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
      - run: echo "::add-matcher::.github/workflows/rust-problem-matcher.json"
      - run: cargo test -q

  test-macos:
    name: Test on MacOS
    needs: [clippy, rustfmt]
    runs-on: macos-latest
    strategy:
      matrix:
        rust:
          - stable
          - 1.64.0
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
      - run: echo "::add-matcher::.github/workflows/rust-problem-matcher.json"
      - run: cargo test -q

  test-lib:
    name: Lib Tests
    needs: [clippy, rustfmt]
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - 1.62.1
          - 1.60.0
          - 1.58.1
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
      - run: echo "::add-matcher::.github/workflows/rust-problem-matcher.json"
      - run: sed -i 's/"rsass-cli",/# \0/' Cargo.toml
      - run: cargo test --package rsass -q

  commandline:
    name: Build cli
    needs: [clippy, rustfmt]
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - stable
          - nightly
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
      - run: echo "::add-matcher::.github/workflows/rust-problem-matcher.json"
      - run: cargo build --package rsass-cli
