name: Go

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  test:
    name: Test Go
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2
        with:
          submodules: recursive

      - name: Install protoc
        uses: arduino/setup-protoc@HEAD
        with:
          version: "3.14"
          repo-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: ^1

      - name: Install Go tools
        run: make tools

      - name: Regenerate protos
        run: make protos

      - name: Vet Go code
        run: make vet

      - name: Run Go tests
        run: make test

      - name: Verify repo is unchanged
        run: git diff --exit-code HEAD
