name: CI

on:
  push:
    branches: ['master', 'auto']
  pull_request:

jobs:
  Test:
    strategy:
      matrix:
        os: [ubuntu-latest]
        rust: [1.36.0, stable, beta, nightly]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          override: true
          profile: minimal
      - name: Unpin dependencies except on MSRV
        if: matrix.rust != '1.36.0'
        run: cargo update
      - uses: actions-rs/cargo@v1
        with:
          command: build
          args: --all-targets
      - uses: actions-rs/cargo@v1
        with:
          command: test
      - uses: actions-rs/cargo@v1
        with:
          command: test
          args: --features "serde"
      - uses: actions-rs/cargo@v1
        with:
          command: test
          args: --no-default-features
      - uses: actions-rs/cargo@v1
        with:
          command: test
          args: --no-default-features --features=hardcoded-data
  Fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          components: rustfmt
      - uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --check

  build_result:
    name: homu build finished
    runs-on: ubuntu-latest
    needs:
      - "Test"
      - "Fmt"
    steps:
      - name: Mark the job as successful
        run: exit 0
        if: success()
      - name: Mark the job as unsuccessful
        run: exit 1
        if: "!success()"
