on: [push, pull_request]

name: ci

jobs:

  check:
    name: check
    runs-on: ubuntu-latest
    continue-on-error: ${{ matrix.experimental }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - rust: stable
            experimental: false
          - rust: nightly
            experimental: true
    steps:
      - name: checkout
        uses: actions/checkout@v2
      - name: install rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true
      - name: cargo check
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --all-features --verbose

  test:
    name: test
    runs-on: ubuntu-latest
    continue-on-error: ${{ matrix.experimental }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - rust: stable
            experimental: false
          - rust: nightly
            experimental: true
    steps:
      - name: checkout
        uses: actions/checkout@v2
      - name: install rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true
      - name: cargo test
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --all-features --verbose

  lint:
    name: lint
    runs-on: ubuntu-latest
    continue-on-error: ${{ matrix.experimental }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - rust: stable
            experimental: false
          - rust: nightly
            experimental: true
    steps:
      - name: checkout
        uses: actions/checkout@v2
      - name: install rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true
          components: rustfmt, clippy
      - name: rustfmt
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check
      - name: clippy
        uses: actions-rs/clippy-check@v1
        with:
          name: ${{ matrix.rust }}
          token: ${{ secrets.GITHUB_TOKEN }}

  coverage:
    name: coverage
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v2
      - name: install rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: nightly
          override: true
          components: llvm-tools-preview
      - name: test
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --lib
        env:
          RUSTFLAGS: "-Zinstrument-coverage"
      - name: install grcov
        uses: actions-rs/install@v0.1
        with:
          crate: grcov
          use-tool-cache: true
      - name: gather
        run: "grcov . --binary-path target/debug/ \
                      --source-dir . \
                      --branch \
                      --ignore-not-existing \
                      --output-type lcov \
                      --output-path coverage.lcov \
                      --prefix-dir /home/user/build/ \
                      --ignore '/*' \
                      --excl-line 'panic!'"
      - name: upload
        uses: codecov/codecov-action@v1
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: coverage.lcov
