name: Go Mod Tidy Check

on:
  workflow_call:

jobs:
  go-mod-tidy-check:
    name: Check go.mod and go.sum are tidy
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Use mise to install dependencies
        uses: jdx/mise-action@v2
        with:
          version: 2025.8.16
          experimental: true
        env:
          # Adding token here to reduce the likelihood of hitting rate limit issues.
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Run go mod tidy
        run: go mod tidy

      - name: Check for changes
        run: |
          if ! git diff --exit-code go.mod go.sum; then
            echo "::error::go.mod or go.sum are not tidy. Please run 'go mod tidy' locally and commit the changes."
            exit 1
          fi
          echo "go.mod and go.sum are tidy"
