name: sync-api
on:
  push:
    paths:
      - 'apis/**'
      - 'pkg/oam/**'
    tags:
      - "v*"

jobs:
  sync-core-api:
    runs-on: ubuntu-20.04
    steps:
      - name: Set up Go 1.17
        uses: actions/setup-go@v1
        env:
          GO_VERSION: '1.19'
          GOLANGCI_VERSION: 'v1.49'
        with:
          go-version: ${{ env.GO_VERSION }}
        id: go

      - name: Check out code into the Go module directory
        uses: actions/checkout@v2

      - name: Get the version
        id: get_version
        run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}

      - name: Sync to kubevela-core-api Repo
        env:
          SSH_DEPLOY_KEY: ${{ secrets.VELA_API_DEPLOY }}
          VERSION: ${{ steps.get_version.outputs.VERSION }}
          COMMIT_ID: ${{ github.sha }}
        run: |
          bash ./hack/apis/clientgen.sh
          bash ./hack/apis/sync.sh
