name: Go

on:
  pull_request:
    branches:
    - main
  push:
    branches:
    - main

jobs:
  build:
    name: Build Go ${{ matrix.go-version }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        go-version: [1.16.x, 1.17.x]
    steps:
    - name: Set up Go ${{ matrix.go-version }}
      uses: actions/setup-go@v1
      with:
        go-version: ${{ matrix.go-version }}
      id: go

    - name: Check out code into the Go module directory
      uses: actions/checkout@v1

    - name: Build
      env:
        GO111MODULE: on
      run: |
         curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.42.0
         $(go env GOPATH)/bin/golangci-lint run --config ./.golangci.yml
         go vet ./...
  test:
    name: Test Go ${{ matrix.go-version }} on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        go-version: [1.17.x]
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
    - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
      uses: actions/setup-go@v1
      with:
        go-version: ${{ matrix.go-version }}
      id: go

    - name: Check out code into the Go module directory
      uses: actions/checkout@v1

    - name: Test on ${{ matrix.os }}
      env:
        GO111MODULE: on
      run: |
         go test -v ./...
