Feat: sync sdk automatically (#5630)

This commit is contained in:
qiaozp
2023-03-09 10:18:08 +08:00
committed by GitHub
parent 79f1d5cb03
commit 07a05c419f
5 changed files with 166 additions and 28 deletions
+8 -6
View File
@@ -19,6 +19,7 @@ permissions:
env:
# Common versions
GO_VERSION: '1.19'
GOLANGCI_VERSION: 'v1.49'
jobs:
sdk-tests:
@@ -32,9 +33,10 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}
- name: Get dependencies
- name: Install Go tools
run: |
go get -v -t -d ./...
make goimports
make golangci
- name: Build CLI
run: make vela-cli
@@ -43,7 +45,7 @@ jobs:
run: bin/vela def gen-api -f vela-templates/definitions/internal/ -o ./kubevela-go-sdk --package=github.com/kubevela-contrib/kubevela-go-sdk
- name: Validate SDK
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # v3.4.0
working-directory: ./kubevela-go-sdk
with:
args: --timeout 5m
run: |
cd kubevela-go-sdk
go mod tidy
golangci-lint run --timeout 5m ./...
+52
View File
@@ -0,0 +1,52 @@
name: Sync SDK
on:
push:
paths:
- vela-templates/definitions/internal/**
- pkg/definition/gen_sdk/**
- .github/workflows/sync-sdk.yaml
tags:
- "v*"
branches:
- master
- release-*
permissions:
contents: read
env:
GO_VERSION: '1.19'
jobs:
sync_sdk:
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568
with:
go-version: ${{ env.GO_VERSION }}
- name: Check out code into the Go module directory
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Install Go tools
run: |
make goimports
- name: Build CLI
run: make vela-cli
- name: Sync SDK to kubevela/kubevela-go-sdk
run: bash ./hack/sdk/sync.sh
env:
SSH_DEPLOY_KEY: ${{ secrets.GO_SDK_DEPLOY_KEY }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
COMMIT_ID: ${{ github.sha }}
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
# Copyright 2022 The KubeVela Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
# This script helps to sync SDK to other repos.
VELA_GO_SDK=kubevela-contrib/kubevela-go-sdk
if [[ -n "$SSH_DEPLOY_KEY" ]]; then
mkdir -p ~/.ssh
echo "$SSH_DEPLOY_KEY" >~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
fi
cd ..
config() {
git config --global user.email "kubevela.bot@aliyun.com"
git config --global user.name "kubevela-bot"
}
cloneAndClearRepo() {
echo "git clone"
if [[ -n "$SSH_DEPLOY_KEY" ]]; then
git clone --single-branch --depth 1 git@github.com:$VELA_GO_SDK.git kubevela-go-sdk
else
git clone --single-branch --depth 1 https://github.com/$VELA_GO_SDK.git kubevela-go-sdk
fi
echo "Clear kubevela-go-sdk pkg/*"
rm -r kubevela-go-sdk/pkg/*
}
updateRepo() {
cd kubevela
bin/vela def gen-api -f vela-templates/definitions/internal/ -o ../kubevela-go-sdk --package=github.com/$VELA_GO_SDK --init
}
syncRepo() {
cd ../kubevela-go-sdk
go mod tidy
echo "Push to $VELA_GO_SDK"
if git diff --quiet; then
echo "Nothing need to push, finished!"
else
git add .
git commit -m "Generated from kubevela-$VERSION from commit $COMMIT_ID"
git tag "$VERSION"
git push origin main
git push origin "$VERSION"
fi
}
main() {
config
cloneAndClearRepo
updateRepo
syncRepo
}
main
+20 -22
View File
@@ -2,50 +2,48 @@
This is a Go SDK for KubeVela generated via vela CLI
## Generating
## Installation
1. Init the SDK project
```shell
vela def gen-api --lang go --output sdk -f /path/to/your/definition/dir --init
```
Recommended way to install this SDK is run command below.
2. Generate any definition
```shell
vela def gen-api --lang go --output sdk -f /another/definition/dir
go get github.com/kubevela-contrib/kubevela-go-sdk
go mod edit -replace=sigs.k8s.io/apiserver-network-proxy/konnectivity-client=sigs.k8s.io/apiserver-network-proxy/konnectivity-client@v0.0.24
```
## Features:
- 🔧Application manipulating
- [x] Add Components/Traits/Workflow Steps/Policies
- [x] Setting Workflow Mode
- [x] Convert to K8s Application Object
- [x] Convert from K8s Application Object
- [x] Get Components/Traits/Workflow Steps/Policies from app
- [ ] Referring to external Workflow object.
- [x] Add Components/Traits/Workflow Steps/Policies
- [x] Set Workflow Mode
- [x] Convert to/from K8s Application Object
- [x] Convert to YAML/JSON
- [x] Get Components/Traits/Workflow Steps/Policies from app
- [x] Validate Application required parameters recursively
- [ ] Referring to external Workflow object.
- 🔍Application client
- [x] Create/Delete/Patch/Update Application
- [x] List/Get Application
- [x] Create/Delete/Patch/Update Application
- [x] List/Get Application
## Example
See [example](example) for more details.
See [example](example) for some basic usage of this SDK.
## Future Work
There is some proper features for this SDK and possible to be added in the future. If you are interested in any of them, please feel free to contact us.
- Part of vela CLI functions
- Application logs/exec/port-forward
- Application resource in tree structure
- VelaQL
- ...
- Application logs/exec/port-forward
- Application resource in tree structure
- VelaQL
- ...
- Standalone workflow functions
- CRUD of workflow
- CRUD of workflow
## Known issues
There are some known issues in this SDK, please be aware of them before using it.
1. `labels` and `annotations` trait is not working as expected.
2. `notification` workflow-step's parameter is not exactly the same as the one in KubeVela.
2. `notification` workflow-step's parameter is not exactly the same as the one in KubeVela.
@@ -19,6 +19,7 @@ package common
import (
"github.com/pkg/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/json"
"sigs.k8s.io/yaml"
. "github.com/kubevela/vela-go-sdk/pkg/apis"
@@ -248,6 +249,15 @@ func (a *ApplicationBuilder) ToYAML() (string, error) {
return string(marshal), nil
}
func (a *ApplicationBuilder) ToJSON() (string, error) {
app := a.Build()
marshal, err := json.Marshal(app)
if err != nil {
return "", err
}
return string(marshal), nil
}
// Validate validates the application name/namespace/component/step/policy.
// For component/step/policy, it will validate if the required fields are set.
func (a *ApplicationBuilder) Validate() error {