name: CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
    types: [opened, reopened, synchronize]
concurrency:
  group: ci-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
  cancel-in-progress: true
jobs:
  ci:
    name: CI
    needs: [test, lint, coverage]
    runs-on: ubuntu-latest
    steps:
      - name: Done
        run: exit 0
  test:
    name: Tests
    strategy:
      fail-fast: false
      matrix:
        rust:
          - 1.54.0
          - stable
          - beta
        os:
          - ubuntu-latest
    runs-on: ${{ matrix.os }}
    steps:
      - name: Install rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true
      - name: Checkout
        uses: actions/checkout@v2
      - name: Install linker
        run: |
          sudo apt-get update
          sudo apt-get install gcc-multilib
      - name: Test all
        uses: actions-rs/cargo@v1
        with:
          command: test
      - name: Check debug
        uses: actions-rs/cargo@v1
        with:
          command: check
  lint:
    name: Linting
    runs-on: ubuntu-latest
    steps:
      - name: Install rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
          components: rustfmt, clippy
      - name: Checkout
        uses: actions/checkout@v2
      - name: Clippy
        uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: -- -D warnings
      - name: Format check
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: -- --check
  coverage:
    name: Coverage
    continue-on-error: true
    runs-on: ubuntu-latest
    steps:
      - name: Install rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          components: llvm-tools-preview
          override: true
      - name: Checkout
        uses: actions/checkout@v2
      - name: Install llvm-cov
        uses: actions-rs/install@v0.1
        with:
          crate: cargo-llvm-cov
          version: 0.1.0-alpha.4
          use-tool-cache: true
      - name: Coverage
        uses: actions-rs/cargo@v1
        with:
          command: llvm-cov
          args: --doctests --lcov --output-path lcov.info
      - name: Coveralls
        uses: coverallsapp/github-action@master
        with:
          path-to-lcov: lcov.info
          github-token: ${{ secrets.github_token }}
