name: SDK Test

on:
  push:
    tags:
      - v*
  workflow_dispatch: {}
  pull_request:
    paths:
      - "vela-templates/definitions/**"
      - "pkg/definition/gen_sdk/**"
    branches:
      - master
      - release-*

permissions:
  contents: read

env:
  # Common versions
  GO_VERSION: '1.19'
  GOLANGCI_VERSION: 'v1.49'

jobs:
  sdk-tests:
    runs-on: ubuntu-22.04
    steps:
      - name: Check out code into the Go module directory
        uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9

      - name: Setup Go
        uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753
        with:
          go-version: ${{ env.GO_VERSION }}

      - name: Install Go tools
        run: |
          make goimports
          make golangci

      - name: Build CLI
        run: make vela-cli

      - name: Build SDK
        run: bin/vela def gen-api -f vela-templates/definitions/internal/ -o ./kubevela-go-sdk --package=github.com/kubevela-contrib/kubevela-go-sdk --init

      - name: Validate SDK
        run: |
          cd kubevela-go-sdk
          go mod tidy
          golangci-lint run --timeout 5m -e "exported:" -e "dot-imports" ./...
