name: Go

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:

  # Test the latest go version
  # and upload the test coverage.
  test_latest:
    name: Go latest stable

    runs-on: ubuntu-latest
    steps:
      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version: 'stable'
          check-latest: true

      - name: Checkout code
        uses: actions/checkout@v4

      - name: Build
        run: go build -v .

      - name: Test
        run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic
     
      # - uses: codecov/codecov-action@v4
      #   with:
      #     files: ./coverage.txt
      #     token: ${{ secrets.CODECOV_TOKEN }}

  # Test the latest two golang version
  # on different operating systems.
  test_versions:
    strategy:
      matrix:
        go: ['1.25', '1.26']
        os: [ubuntu-latest, macos-latest, windows-latest]
    name: Go ${{ matrix.go }} on ${{ matrix.os }}

    runs-on: ${{ matrix.os }}
    steps:
      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version: ${{ matrix.go }}

      - name: Checkout code
        uses: actions/checkout@v4

      - name: Test
        run: go test ./... -v -race -cover
