trigger:
  batch: "true"
  branches:
    include:
    - master

jobs:

- job: Compile
  strategy:
    maxParallel: 3
    matrix: 
      Windows:
        OS: windows
      OSX:
        OS: darwin
      Linux:
        OS: linux
  steps:
  - template: build/azure-pipelines/go-env.yaml
  - script: "go run -mod=readonly build/build.go -os $(OS)"

- job: "unittests"
  displayName: "Run Unit Tests"
  steps:
  - template: build/azure-pipelines/go-env.yaml
  - script: "go test -mod=readonly ./..."

- job: "modtidy"
  displayName: "Check Go Modules"
  steps:
  - template: build/azure-pipelines/go-env.yaml
  - script: |
      set -e
      go mod tidy
      git status --porcelain
      git diff
      [ ! -n "$(git status --porcelain go.mod go.sum)" ] || { echo "Error: go.mod/go.sum outdated, please run go mod tidy."; false; }

- job: "modvendor"
  displayName: "Check Go Vendor"
  steps:
  - template: build/azure-pipelines/go-env.yaml
  - script: |
      set -e
      go mod vendor
      git status --porcelain
      [ ! -n "$(git status --porcelain vendor)" ] || { echo "Error: Vendor does not match go.mod/go.sum, please run go mod vendor."; false; }

- job: "GoFmt"
  displayName: "Check Go Formatting"
  steps:
  - template: build/azure-pipelines/go-env.yaml
  - script: |
      set -e
      go fmt ./...
      git status --porcelain
      git diff
      [ ! -n "$(git status --porcelain)" ] || { echo "Error: Go files not formatted, please run go fmt ./... ."; false; }

- job: "GoGen"
  displayName: "Check Go Generate"
  steps:
  - template: build/azure-pipelines/go-env.yaml
  - script: |
      set -e
      go generate .
      git status --porcelain
      git diff
      [ ! -n "$(git status --porcelain)" ] || { echo "Error: Generated files not up to date, please run go generate . ."; false; }
