name: build

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:

  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        go: [ '1.14', '1.13' ]
    name: Build and test on go ${{ matrix.go }}
    steps:

    - name: Set up Go ${{ matrix.go }}
      uses: actions/setup-go@v2
      with:
        go-version: ${{ matrix.go }}
      id: go

    - name: Check out code
      uses: actions/checkout@v2

    - name: Install ninja
      run: |
        mkdir -p ${GITHUB_WORKSPACE}/ninja-bin; cd ${GITHUB_WORKSPACE}/ninja-bin
        wget https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-linux.zip
        unzip ninja-linux.zip
        rm ninja-linux.zip
        echo "${GITHUB_WORKSPACE}/ninja-bin" >> $GITHUB_PATH

    - name: Run gofmt
      run: ./.gofmt.sh

    - name: Test
      run: go test ./...

    - name: Test with race detector
      run: go test -race -short ./...

    - run: ./tests/test.sh
    - run: ./tests/test_tree_tests.sh
    - run: ./tests/test_tree_tests.sh -t
