name: CI
on: [push, pull_request]

jobs:
  test:
    name: Test
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        rust: ["1.63", stable, beta, nightly]
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
    - uses: actions/checkout@master
    - name: Install Rust (rustup)
      run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
      shell: bash

    - run: cargo test

    # Compile it from source (temporarily)
    - name: Make GNU Make from source
      if: ${{ !startsWith(matrix.os, 'windows') }}
      env:
        VERSION: "4.4.1"
      shell: bash
      run: |
        wget -q "https://ftp.gnu.org/gnu/make/make-${VERSION}.tar.gz"
        tar zxf "make-${VERSION}.tar.gz"
        pushd "make-${VERSION}"
        ./configure
        make
        popd
        cp -rp "make-${VERSION}/make" .
    - name: Test against GNU Make from source
      if: ${{ !startsWith(matrix.os, 'windows') }}
      shell: bash
      run:
        MAKE="${PWD}/make" cargo test

  rustfmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Install Rust
      run: rustup update stable && rustup default stable && rustup component add rustfmt
    - run: cargo fmt -- --check

  publish_docs:
    name: Publish Documentation
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: Install Rust
        run: rustup update stable && rustup default stable
      - name: Build documentation
        run: cargo doc --no-deps --all-features
      - name: Publish documentation
        run: |
          cd target/doc
          git init
          git add .
          git -c user.name='ci' -c user.email='ci' commit -m init
          git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages
        if: github.event_name == 'push' && github.event.ref == 'refs/heads/master'
