name: Set up kas golang environment
author: Jeff Kim
description: ' Set up kas golang environment'
inputs:
  version:
    description: 'golang version regular expression form'
    required: true
    default: "1.15.x"
  submodule-option:
    description: 'recursive or false. default is recursive'
    required: false
    default: 'recursive'
  arch:
    description: 'Set Go architecture (e.g., amd64, arm64)'
    required: false
    default: 'amd64'
outputs:
  cache:
    description: 'Indicates whether any cache was hit (Go modules or Go build cache)'
    value: ${{ steps.go-mod-cache.outputs.cache-hit || steps.go-build-cache.outputs.cache-hit }}
runs:
  using: "composite"
  steps:
    - name: prepare golang environment
      uses: actions/setup-go@v5
      with:
        go-version: ${{ inputs.version }}
        architecture: ${{ inputs.arch }}
    # Go 모듈 캐시
    - name: Cache Go modules
      id: go-mod-cache
      uses: actions/cache@v4
      with:
        path: ~/go/pkg/mod
        key: ${{ runner.os }}-go-mod-${{ inputs.arch }}-${{ inputs.version }}-${{ hashFiles('go.sum') }}
        restore-keys: |
          ${{ runner.os }}-go-mod-${{ inputs.arch }}-
          ${{ runner.os }}-go-mod-

    # Go 빌드 캐시
    - name: Cache Go build cache
      id: go-build-cache
      uses: actions/cache@v4
      with:
        path: ~/.cache/go-build
        key: ${{ runner.os }}-go-build-${{ inputs.arch }}-${{ inputs.version }}-${{ hashFiles('go.sum') }}
        restore-keys: |
          ${{ runner.os }}-go-build-${{ inputs.arch }}-
          ${{ runner.os }}-go-build-
