name: Tests

on:
  push:
    branches:
      - master
  pull_request:
  workflow_dispatch:
  schedule:
    - cron: "5 1 * * *"

jobs:
  test:
    name: Test and lint
    strategy:
      fail-fast: false
      matrix:
        go: [ '1.18', '1.17' ]
        os: [ 'windows-latest', 'ubuntu-latest', 'macOS-latest' ]
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-go@v3
        with:
          go-version: ${{ matrix.go }}

      - name: Run go fmt (Go ${{ matrix.go }})
        if: runner.os != 'Windows'
        run: diff -u <(echo -n) <(gofmt -d -s .)

      - name: Run go vet
        run: make vet

      - name: Run staticcheck (Go ${{ matrix.go }})
        uses: dominikh/staticcheck-action@v1.2.0
        with:
          version: "2022.1"
          install-go: false
          cache-key: ${{ matrix.go }}

      - name: Run Unit tests (Go ${{ matrix.go }})
        run: make test
