github.com/oam-dev/kubevela@v1.9.11/hack/apis/sync.sh (about) 1 #!/bin/bash -l 2 # 3 # Copyright 2021. 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 18 set -e 19 20 if [[ -n "$SSH_DEPLOY_KEY" ]] 21 then 22 mkdir -p ~/.ssh 23 echo "$SSH_DEPLOY_KEY" > ~/.ssh/id_rsa 24 chmod 600 ~/.ssh/id_rsa 25 fi 26 27 cd .. 28 29 git config --global user.email "kubevela.bot@aliyun.com" 30 git config --global user.name "kubevela-bot" 31 32 clearRepo() { 33 echo "git clone" 34 35 if [[ -n "$SSH_DEPLOY_KEY" ]] 36 then 37 git clone --single-branch --depth 1 git@github.com:oam-dev/kubevela-core-api.git kubevela-core-api 38 else 39 git clone --single-branch --depth 1 https://github.com/kubevela/kubevela-core-api.git kubevela-core-api 40 fi 41 42 echo "clear kubevela-core-api apis/" 43 rm -r kubevela-core-api/apis 44 45 echo "clear kubevela-core-api pkg/oam" 46 rm -r kubevela-core-api/pkg/oam/* 47 48 echo "clear kubevela-core-api pkg/utils/errors" 49 rm -rf kubevela-core-api/pkg/utils/errors/* 50 51 echo "clear kubevela-core-api pkg/generated/client" 52 if [[ -d "kubevela-core-api/pkg/generated/client/" ]] 53 then 54 rm -r kubevela-core-api/pkg/generated/client/* 55 else 56 mkdir -p kubevela-core-api/pkg/generated/client/ 57 fi 58 } 59 60 updateRepo() { 61 echo "update kubevela-core-api apis/" 62 cp -R kubevela/apis kubevela-core-api/apis 63 64 echo "update kubevela-core-api pkg/oam" 65 cp -R kubevela/pkg/oam/* kubevela-core-api/pkg/oam/ 66 67 echo "update kubevela-core-api pkg/utils/errors" 68 mkdir -p kubevela-core-api/pkg/utils/errors 69 cp -R kubevela/pkg/utils/errors/* kubevela-core-api/pkg/utils/errors/ 70 71 echo "update kubevela-core-api pkg/generated/client" 72 cp -R kubevela/pkg/generated/client/* kubevela-core-api/pkg/generated/client/ 73 74 echo "change import path" 75 find ./kubevela-core-api -type f -name "*.go" -print0 | xargs -0 sed -i 's|github.com/oam-dev/kubevela/|github.com/oam-dev/kubevela-core-api/|g' 76 } 77 78 testApi() { 79 cd kubevela-core-api 80 echo "test api" 81 go mod tidy 82 go build test/main.go 83 } 84 85 syncRepo() { 86 testApi 87 echo "push to kubevela-core-api" 88 if git diff --quiet 89 then 90 echo "no changes, skip pushing commit" 91 else 92 git add . 93 git commit -m "align with kubevela-$VERSION from commit $COMMIT_ID" 94 git push origin main 95 fi 96 97 # push new tag anyway 98 # Only tags if VERSION starts with refs/tags/, remove the prefix and push it 99 if [[ "$VERSION" == refs/tags/* ]]; then 100 VERSION=${VERSION#refs/tags/} 101 else 102 echo "VERSION $VERSION is not a tag, skip pushing tag" 103 return 104 fi 105 106 echo "push tag $VERSION" 107 git tag "$VERSION" 108 git push origin "$VERSION" 109 } 110 111 main() { 112 clearRepo 113 updateRepo 114 115 if [[ "$1" == "sync" ]] 116 then 117 syncRepo 118 fi 119 if [[ "$1" == "test" ]] 120 then 121 testApi 122 fi 123 } 124 125 main $1