name: CI
on:
  pull_request:
  push:
    branches:
      - master

env:
  RUST_BACKTRACE: 1

jobs:
  ci-pass:
    name: CI is green
    runs-on: ubuntu-latest
    needs:
      - test
      - simd
      - msrv
      - miri
    steps:
      - run: exit 0

  test:
    name: Test ${{ matrix.rust }} on ${{ matrix.os }}
    strategy:
      matrix:
        rust:
          - stable
          - beta
          - nightly

        os:
          - ubuntu-latest
          - windows-latest
          - macOS-latest

        include:
          - rust: nightly
            benches: true

    runs-on: ${{ matrix.os }}
    env:
      CARGO_CFG_HTTPARSE_DISABLE_SIMD: 1

    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Install Rust (${{ matrix.rust }})
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true

      - name: no_std
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --no-default-features

      - name: Test
        uses: actions-rs/cargo@v1
        with:
          command: test

      - name: Test all benches
        if: matrix.benches
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --benches

  simd:
    name: SIMD ${{ matrix.target_feature }} on ${{ matrix.rust }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - stable
          - beta
          - nightly

        target_feature:
          - "+sse4.2"
          - "+avx2"
          - "+sse4.2,+avx2"

        disable_compiletime:
          - 0
          - 1

    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Install Rust (${{ matrix.rust }})
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true

      - name: Test
        uses: actions-rs/cargo@v1
        with:
          command: test
        env:
          RUSTFLAGS: -C target_feature=${{ matrix.target_feature }}
          CARGO_CFG_HTTPARSE_DISABLE_SIMD_COMPILETIME: ${{ matrix.disable_compiletime }}

  msrv:
    name: msrv
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: 1.36.0
          override: true

      # Only build, dev-dependencies don't compile on 1.10
      - name: Build
        uses: actions-rs/cargo@v1
        with:
          command: build

  miri:
    name: Test with Miri
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: nightly
          components: miri
          override: true

      - name: Test
        run: MIRIFLAGS="-Zmiri-tag-raw-pointers -Zmiri-check-number-validity" cargo miri test
