github.com/oam-dev/kubevela@v1.9.11/hack/sdk/sync.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2022 The KubeVela Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -o errexit 18 19 # This script helps to sync SDK to other repos. 20 21 VELA_GO_SDK=kubevela-contrib/kubevela-go-sdk 22 23 if [[ -n "$SSH_DEPLOY_KEY" ]]; then 24 mkdir -p ~/.ssh 25 echo "$SSH_DEPLOY_KEY" >~/.ssh/id_rsa 26 chmod 600 ~/.ssh/id_rsa 27 fi 28 29 cd .. 30 31 config() { 32 git config --global user.email "kubevela.bot@aliyun.com" 33 git config --global user.name "kubevela-bot" 34 } 35 36 cloneAndClearCoreAPI() { 37 echo "git clone" 38 39 if [[ -n "$SSH_DEPLOY_KEY" ]]; then 40 git clone --single-branch --depth 1 git@github.com:$VELA_GO_SDK.git kubevela-go-sdk 41 else 42 git clone --single-branch --depth 1 https://github.com/$VELA_GO_SDK.git kubevela-go-sdk 43 fi 44 45 echo "Clear kubevela-go-sdk pkg/apis/common, pkg/apis/component, pkg/apis/policy, pkg/apis/trait, pkg/apis/workflow-step, pkg/apis/utils, pkg/apis/types.go " 46 rm -rf kubevela-go-sdk/pkg/apis/common 47 rm -rf kubevela-go-sdk/pkg/apis/component 48 rm -rf kubevela-go-sdk/pkg/apis/policy 49 rm -rf kubevela-go-sdk/pkg/apis/trait 50 rm -rf kubevela-go-sdk/pkg/apis/workflow-step 51 rm -rf kubevela-go-sdk/pkg/apis/utils 52 } 53 54 updateRepo() { 55 cd kubevela 56 bin/vela def gen-api -f vela-templates/definitions/internal/ -o ../kubevela-go-sdk --package=github.com/$VELA_GO_SDK --init 57 } 58 59 syncRepo() { 60 cd ../kubevela-go-sdk 61 go mod tidy 62 echo "Push to $VELA_GO_SDK" 63 if git diff --quiet; then 64 echo "no changes, skip pushing commit" 65 else 66 git add . 67 git commit -m "Generated from kubevela-$VERSION from commit $COMMIT_ID" 68 git push origin main 69 fi 70 71 # push new tag anyway 72 # Only tags if VERSION starts with refs/tags/, remove the prefix and push it 73 if [[ "$VERSION" == refs/tags/* ]]; then 74 VERSION=${VERSION#refs/tags/} 75 else 76 echo "VERSION $VERSION is not a tag, skip pushing tag" 77 return 78 fi 79 80 echo "push tag $VERSION" 81 git tag "$VERSION" 82 git push origin "$VERSION" 83 } 84 85 main() { 86 config 87 cloneAndClearCoreAPI 88 updateRepo 89 syncRepo 90 } 91 92 main