Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

feat: sync api #65

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/sync-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: sync-api
on:
push:
paths:
- 'pkg/yurtappmanager/apis/**'
- 'pkg/yurtappmanager/client/**'
tags:
- "v*"

jobs:
sync-core-api:
runs-on: ubuntu-20.04
steps:
- name: Set up Go 1.16
uses: actions/setup-go@v1
env:
GO_VERSION: '1.16'
GOLANGCI_VERSION: 'v1.38'
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/}
echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}

- name: Sync to yurt-app-manager-api Repo
env:
SSH_DEPLOY_KEY: ${{ secrets.OPENYURT_API_DEPLOY }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
TAG: ${{ steps.get_version.outputs.TAG }}
COMMIT_ID: ${{ github.sha }}
run: |
bash ./hack/lib/sync.sh
67 changes: 67 additions & 0 deletions hack/lib/sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash -l
# Copyright 2020 The OpenYurt 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 -e

if [[ -n "$SSH_DEPLOY_KEY" ]]
then
mkdir -p ~/.ssh
echo "$SSH_DEPLOY_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
fi

echo "git clone"
cd ..
git config --global user.email "openyurt-bot@openyurt.io"
git config --global user.name "openyurt-bot"
git clone --single-branch --depth 1 git@github.com:openyurtio/yurt-app-manager-api.git yurt-app-manager-api

echo "clear yurt-app-manager-api api/"
rm -r yurt-app-manager-api/pkg/yurtappmanager/apis/*

echo "clear yurt-app-manager-api client/"
rm -r yurt-app-manager-api/pkg/yurtappmanager/client/*

echo "update yurt-app-manager-api api/"
cp -R yurt-app-manager/pkg/yurtappmanager/apis/* yurt-app-manager-api/pkg/yurtappmanager/apis/

echo "update yurt-app-manager-api client/"
cp -R yurt-app-manager/pkg/yurtappmanager/client/* yurt-app-manager-api/pkg/yurtappmanager/client/

echo "change import path"
find ./yurt-app-manager-api -type f -name "*.go" -print0 | xargs -0 sed -i 's|github.com/openyurtio/yurt-app-manager/|github.com/openyurtio/yurt-app-manager-api/|g' ./yurt-app-manager-api/pkg/yurtappmanager/apis/addtoscheme_apps_v1alpha1.go

echo "test api"
cd yurt-app-manager-api
go mod tidy

echo "push to yurt-app-manager-api"
echo "version: $VERSION, commit: $COMMIT_ID, tag: $TAG"

if git diff --quiet
then
echo "nothing need to push, finished!"
else
git add .
git commit -m "align with yurt-app-manager-$VERSION from commit $COMMIT_ID"
git tag "$VERSION"
git push origin main
fi

if [[ $TAG == v* ]] ;
then
echo "push tag: TAG"
git push origin "$TAG"
fi