name: tigron

on:
  push:
    branches:
      - main
      - 'release/**'
  pull_request:
    paths: 'mod/tigron/**'

env:
  GO_VERSION: "1.24"
  GOTOOLCHAIN: local

jobs:
  lint:
    timeout-minutes: 15
    name: "${{ matrix.goos }} ${{ matrix.runner }} | go ${{ matrix.canary }}"
    runs-on: ${{ matrix.runner }}
    defaults:
      run:
        shell: bash
    strategy:
      matrix:
        include:
          - runner: ubuntu-24.04
          - runner: macos-15
          - runner: windows-2022
          - runner: ubuntu-24.04
            goos: freebsd
          - runner: ubuntu-24.04
            canary: go-canary
    steps:
      - name: "Checkout project"
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683  # v4.2.2
        with:
          fetch-depth: 100
      - if: ${{ matrix.canary }}
        name: "Init (canary): retrieve GO_VERSION"
        run: |
          latest_go="$(. ./hack/provisioning/version/fetch.sh; go::canary::for::go-setup)"
          printf "GO_VERSION=%s\n" "$latest_go" >> "$GITHUB_ENV"
          [ "$latest_go" != "" ] || \
            echo "::warning title=No canary go::There is currently no canary go version to test. Steps will not run."
      - if: ${{ env.GO_VERSION != '' }}
        name: "Install go"
        uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5  # v5.5.0
        with:
          go-version: ${{ env.GO_VERSION }}
          check-latest: true
      - if: ${{ env.GO_VERSION != '' }}
        name: "Install tools"
        run: |
          cd mod/tigron
          echo "::group:: make install-dev-tools"
          make install-dev-tools
          if [ "$RUNNER_OS" == macOS ]; then
            brew install yamllint shellcheck
          fi
          echo "::endgroup::"
      - if: ${{ env.GO_VERSION != '' && env.RUNNER_OS == 'Linux' && matrix.goos == '' }}
        name: "lint"
        env:
          NO_COLOR: true
        run: |
          echo "::group:: lint"
          cd mod/tigron
          export LINT_COMMIT_RANGE="$(jq -r '.after + "..HEAD"' ${GITHUB_EVENT_PATH})"
          make lint
          echo "::endgroup::"
      - if: ${{ env.GO_VERSION != '' }}
        name: "test-unit"
        run: |
          echo "::group:: unit test"
          cd mod/tigron
          make test-unit
          echo "::endgroup::"
      - if: ${{ env.GO_VERSION != '' }}
        name: "test-unit-race"
        run: |
          echo "::group:: race test"
          cd mod/tigron
          make test-unit-race
          echo "::endgroup::"
      - if: ${{ env.GO_VERSION != '' }}
        name: "test-unit-bench"
        run: |
          echo "::group:: bench"
          cd mod/tigron
          make test-unit-bench
          echo "::endgroup::"
