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

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

      - name: Setup Env
        uses: ./.github/actions/env-setup

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

      - name: Setup KinD
        uses: ./.github/actions/setup-kind-cluster
        with:
          name: sdk-test

      - 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" ./...
