name: Go tests

on:
  push:
  pull_request:
  schedule:
    - cron: "22 10 * * *"
  workflow_dispatch:

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        go:
          - { go-version: stable }
          - { go-version-file: go.mod }
        deps:
          - locked
          - latest
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: actions/setup-go@v6
        with:
          go-version: ${{ matrix.go.go-version }}
          go-version-file: ${{ matrix.go.go-version-file }}
      - run: |
          if [ "${{ matrix.deps }}" = "latest" ]; then
            # globalping-cli v1.5.2 removed github.com/jsdelivr/globalping-cli/globalping,
            # which doggo imports. Keep the rest of the dependency freshness check
            # while holding that module at the last compatible release.
            if ! go get -u -t ./... 2>go-get.err; then
              cat go-get.err
              grep -q "github.com/jsdelivr/globalping-cli/globalping" go-get.err
            fi
            go get github.com/jsdelivr/globalping-cli@v1.5.1
          fi
          go test -v ./...
