name: Build Without Go Proxy

on:
  workflow_call:

jobs:
  build-no-proxy:
    name: Build (${{ matrix.os }}/${{ matrix.arch }})
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
          - os: darwin
            arch: amd64
          - os: darwin
            arch: arm64
          - os: linux
            arch: "386"
          - os: linux
            arch: amd64
          - os: linux
            arch: arm64
          - os: windows
            arch: "386"
          - os: windows
            arch: amd64

    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 }}

      - id: go-cache-paths
        run: |
          echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"

      - name: Go Build Cache
        uses: actions/cache@v5
        with:
          path: ${{ steps.go-cache-paths.outputs.go-build }}
          key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}-${{ matrix.os }}-${{ matrix.arch }}

      - name: Build Terragrunt without Go proxy
        env:
          GOPROXY: direct
          GOOS: ${{ matrix.os }}
          GOARCH: ${{ matrix.arch }}
        run: |
          OUTPUT="bin/terragrunt-${GOOS}-${GOARCH}"
          if [ "${GOOS}" = "windows" ]; then
            OUTPUT="${OUTPUT}.exe"
          fi
          go build -o "${OUTPUT}" \
            -ldflags "-X github.com/gruntwork-io/go-commons/version.Version=${GITHUB_REF_NAME} -extldflags '-static'" \
            .
