name: Linux

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - '*'

jobs:
  build:
    strategy:
      matrix:
        # Oldest we support is 1.18, plus the latest two releases.
        go-version: ['1.18', '1.20', '1.21']
    runs-on: ubuntu-latest

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

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

    - name: Check Go modules
      if: matrix.go-version == '1.21'
      run: |
        go mod tidy
        git diff --exit-code

    - name: Check formatting
      if: matrix.go-version == '1.21'
      run: diff -u <(echo -n) <(gofmt -d .)

    - name: Run tests on linux
      run: go test ./...
