# tinqs/ci/setup-go — Tinqs Studio CI
# Downloads Go from go.dev and adds it to PATH.
# Works on any Linux (Alpine, Debian, etc.) — just a tarball extract.
# Skips install if the correct version is already present (pre-baked runner image).
# Composite action — runs directly on the host.
# Author: Ozan + Claude Code — 2026-05-22

name: 'Tinqs Setup Go'
description: 'Install Go and configure PATH'

inputs:
  go-version:
    description: 'Go version to install'
    default: '1.26.2'

runs:
  using: 'composite'
  steps:
    - run: |
        GO_VERSION="${{ inputs.go-version }}"

        # Skip if already installed at correct version
        if command -v go &>/dev/null; then
          CURRENT=$(go version | sed 's/.*go//' | cut -d' ' -f1)
          if [ "$CURRENT" = "$GO_VERSION" ]; then
            echo "Go $GO_VERSION already installed"
            go version
            exit 0
          fi
        fi

        echo "Installing Go $GO_VERSION..."
        # Use wget on Alpine (no curl), curl elsewhere
        if command -v curl &>/dev/null; then
          curl -fsSL "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar -C /usr/local -xz
        elif command -v wget &>/dev/null; then
          wget -qO- "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar -C /usr/local -xz
        else
          apk add --no-cache curl && curl -fsSL "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar -C /usr/local -xz
        fi
        echo "/usr/local/go/bin" >> "$GITHUB_PATH"
        export PATH="/usr/local/go/bin:$PATH"
        go version
      shell: bash
