-
Notifications
You must be signed in to change notification settings - Fork 2
88 lines (76 loc) · 2.96 KB
/
auto-update-client-api.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Auto Update Client API
on:
workflow_dispatch:
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
POETRY_VERSION: "1.7.1"
PYTHON_VERSION: "3.11"
GO_VERSION: "1.22"
APECLOUD_COMMIT_URL: "https://github.com/apecloud/apecloud/commit"
jobs:
check-swagger:
runs-on: ubuntu-latest
steps:
- name: Checkout kb-cloud-client-go Code
uses: actions/checkout@v4
with:
repository: apecloud/kb-cloud-client-go
path: ./
token: ${{ env.GITHUB_TOKEN }}
ref: ${{ github.ref_name }}
- name: Setup Poetry
uses: Gr1N/setup-poetry@v8
with:
poetry-version: "${{ env.POETRY_VERSION }}"
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Checkout apecloud Code
uses: actions/checkout@v4
with:
repository: apecloud/apecloud
path: ./apecloud
token: ${{ env.GITHUB_TOKEN }}
ref: ${{ github.ref_name }}
- name: bundle openapi and adminapi
run: |
go install golang.org/x/tools/cmd/goimports@latest
npm install @redocly/cli -g
cd ./apecloud
git fetch --prune --unshallow
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
APECLOUD_COMMIT_SHA=$(git rev-parse HEAD)
echo "APECLOUD_COMMIT_SHA=$APECLOUD_COMMIT_SHA" >> $GITHUB_ENV
cd ./apiserver
redocly bundle ./api/openapi.yaml > ./openapi-bundle-tmp.yaml
redocly bundle ./api/adminapi.yaml > ./adminapi-bundle-tmp.yaml
- name: update openapi and adminapi
id: update_client_api
run: |
COMMIT_SHA="$(git rev-parse HEAD)"
cp -r ./apecloud/apiserver/openapi-bundle-tmp.yaml ./.generator/schemas/openapi.yaml
cp -r ./apecloud/apiserver/adminapi-bundle-tmp.yaml ./.generator/schemas/adminapi.yaml
FILE_CHANGES=`git diff --name-only ${COMMIT_SHA}`
if [[ ! -z "$FILE_CHANGES" ]]; then
echo $FILE_CHANGES
bash ./generate.sh
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add .
git commit -m "chore: auto update client api ${APECLOUD_COMMIT_URL}/${APECLOUD_COMMIT_SHA}"
fi
echo file_changes=$FILE_CHANGES >> $GITHUB_OUTPUT
- name: Push api spec changes to kb-cloud-client-go
uses: ad-m/github-push-action@master
if: ${{ steps.update_client_api.outputs.file_changes }}
with:
repository: apecloud/kb-cloud-client-go
directory: ./
github_token: ${{ env.GITHUB_TOKEN }}
branch: ${{ github.ref_name }}