name: "Gohai Test"

# Only run the tests if pkg/gohai was changed
on:
  push:
    branches:
      - main
      - "[0-9]+.[0-9]+.x"
    paths:
      - "pkg/gohai/**"
  pull_request:
    paths:
      - "pkg/gohai/**"

permissions: {}

jobs:
  gohai_test:
    strategy:
      matrix:
        # Use oldest and latest available ubuntu, macos and windows
        os:
          [
            ubuntu-20.04,
            ubuntu-latest,
            macos-12,
            macos-latest,
            windows-2019,
            windows-latest,
          ]
        # Run tests with both the agent's version and gohai's pinned version
        go-file: [.go-version, pkg/gohai/go.mod]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
        with:
          persist-credentials: false
      - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
        with:
          go-version-file: ${{ matrix.go-file }}
      - name: Test
        run: cd pkg/gohai && go test -tags=test ./...