-
Notifications
You must be signed in to change notification settings - Fork 2
94 lines (76 loc) · 3.13 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
89
90
91
92
93
94
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"
jobs:
check-swagger:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- 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/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
cd .generator
poetry install
poetry run python -m generator ./schemas/* -o ../api
cd ../api
goimports -w .
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git commit -a -m "chore: auto update clinent api"
fi
echo file_changes=$FILE_CHANGES >> $GITHUB_OUTPUT
RELEASE_COMMIT="$(git rev-parse HEAD)"
echo 'RELEASE_COMMIT='${RELEASE_COMMIT} >> $GITHUB_ENV
- name: push changes to new branch
if: ${{ github.ref_name == 'main' && steps.update_client_api.outputs.file_changes }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ env.GITHUB_TOKEN }}
branch: support/auto-update-client-api-${{ env.RELEASE_COMMIT }}
- name: auto create pr head new branch
if: ${{ github.ref_name == 'main' && steps.update_client_api.outputs.file_changes }}
run: |
gh pr create --head "support/auto-update-client-api-${{ env.RELEASE_COMMIT }}" --title "chore: auto update clinent api" --body ""
- name: push changes
uses: ad-m/github-push-action@master
if: ${{ github.ref_name != 'main' && steps.update_client_api.outputs.file_changes }}
with:
github_token: ${{ env.GITHUB_TOKEN }}
branch: ${{ github.ref_name }}