Skip to content

Auto Update Client API #254

Auto Update Client API

Auto Update Client API #254

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 }}