name: tigron

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

env:
  GO_VERSION: "1.25"
  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@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2
        with:
          fetch-depth: 100
      - if: ${{ matrix.canary }}
        name: "Init (canary): retrieve GO_VERSION"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        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@4b73464bb391d4059bd26b0524d20df3927bd417  # v6.3.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 != '' && matrix.goos == '' }}
        name: "lint"
        env:
          NO_COLOR: true
        run: |
          if [ "$RUNNER_OS" == Linux ]; then
            echo "::group:: lint"
            cd mod/tigron
            export LINT_COMMIT_RANGE="$(jq -r '.after + "..HEAD"' ${GITHUB_EVENT_PATH})"
            make lint
            echo "::endgroup::"
          else
            echo "Lint is disabled on $RUNNER_OS"
          fi
      - 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::"
