# Based on crossterm repository
name: message-io ci

on:
  # Build master branch only
  push:
    branches:
      - master

  # Build pull requests targeting master branch only
  pull_request:
    branches:
      - master

jobs:
  test:
    name: ${{ matrix.rust }} on ${{ matrix.os }}-${{matrix.platform}}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-2019, macOS-latest]
        rust: [stable, nightly]
        include:
          - rust: stable
            can-fail: false
          - rust: nightly
            can-fail: false
    steps:
    - name: Checkout Repository
      uses: actions/checkout@v1
      with:
        fetch-depth: 1
    - name: Install Rust
      uses: hecrj/setup-rust-action@master
      with:
        rust-version: ${{ matrix.rust }}
        components: rustfmt,clippy
    - name: Toolchain Information
      run: |
        rustc --version
        rustfmt --version
        rustup --version
        cargo --version
    - name: Check Formatting
      if: matrix.rust == 'nightly'
      run: cargo fmt --all -- --check
      continue-on-error: ${{ matrix.can-fail }}
    - name: Clippy
      run: cargo clippy -- -D clippy::all
      continue-on-error: ${{ matrix.can-fail }}
    - name: Check build
      run: cargo build
      continue-on-error: ${{ matrix.can-fail }}
    - name: Check test and examples
      run: cargo test -- --nocapture
      continue-on-error: ${{ matrix.can-fail }}
    - name: Check benchmarks (only compilation)
      run: cargo bench --no-run
      continue-on-error: ${{ matrix.can-fail }}
    - name: Test Packaging
      if: matrix.rust == 'stable'
      run: cargo package
      continue-on-error: ${{ matrix.can-fail }}
  test-cross:
    # websocket requires openssl that complicates cross compilation
    name: Build
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - i686-unknown-linux-gnu
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: ${{ matrix.target }}
          override: true
      - uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: build
      - uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: test
      - uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: bench
          args: --no-run