11name : Auto-Update SDK
22
3- # on:
4- # schedule:
5- # - cron: "0 0 * * 1" # Runs every Monday at midnight
6- # workflow_dispatch: # Allows manual triggering of the workflow
7-
8- on : [push, pull_request]
3+ on :
4+ schedule :
5+ - cron : " 0 0 * * 1" # Runs every Monday at midnight
6+ workflow_dispatch : # Allows manual triggering of the workflow
97
108jobs :
119 update-sdk :
1210 runs-on : ubuntu-latest
11+ strategy :
12+ matrix :
13+ python-version : ["3.12"]
1314 steps :
14- - name : Checkout repository
15+ - uses : actions/checkout@v3
16+ - name : Set up Python ${{ matrix.python-version }}
17+ uses : actions/setup-python@v5
18+ with :
19+ python-version : ${{ matrix.python-version }}
20+ - name : Set up Node.js
21+ uses : actions/setup-node@v3
22+ with :
23+ node-version : ' 18'
24+ - name : Install OpenAPI Generator CLI
25+ run : npm install @openapitools/openapi-generator-cli -g
26+ - name : Install dependencies
1527 run : |
16- git clone https://github.com/${{ github.repository }} repo
17- cd repo
18- git config --global user.name "github-actions[bot]"
19- git config --global user.email "github-actions[bot]@users.noreply.github.com"
28+ python -m pip install --upgrade pip
29+ pip install -r requirements.txt
2030 - name : Pull and generate SDK
21- run : |
22- cd repo
23- make gen-openapi-remote
31+ run : make gen-openapi-remote-for-ci
2432 - name : Check for changes
33+ id : check_changes
2534 run : |
26- cd repo
2735 if git diff --quiet; then
2836 echo "changes=false" >> $GITHUB_ENV
2937 else
3038 echo "changes=true" >> $GITHUB_ENV
3139 fi
40+ - name : Set up Git
41+ if : env.changes == 'true'
42+ run : |
43+ git config user.name "github-actions[bot]"
44+ git config user.email "github-actions[bot]@users.noreply.github.com"
3245 - name : Commit changes
3346 if : env.changes == 'true'
3447 run : |
35- cd repo
36- git checkout -b auto-update-sdk || git checkout auto-update-sdk
48+ BRANCH_NAME="auto-update-sdk-$(date +'%Y-%m-%d-%H-%M-%S')"
49+ echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
50+ git checkout -b $BRANCH_NAME || git checkout $BRANCH_NAME
3751 git add .
3852 git commit -m "Auto-update SDK on $(date +'%Y-%m-%d')"
3953 - name : Push changes
4054 if : env.changes == 'true'
4155 env :
4256 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
57+ run : git push --force --set-upstream origin $BRANCH_NAME
58+ - name : Install GitHub CLI
59+ if : env.changes == 'true'
4360 run : |
44- cd repo
45- git push --force --set-upstream origin auto-update-sdk
46- - name : Create a pull request
61+ sudo apt-get update
62+ sudo apt-get install -y gh
63+ - name : Check for existing pull request
4764 if : env.changes == 'true'
65+ env :
66+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
67+ id : check_pr
68+ run : |
69+ PR_EXISTS=$(gh pr list --search "Auto-update SDK" --base main --state open --json number -q '.[0].number')
70+ if [[ -n "$PR_EXISTS" ]]; then
71+ echo "pr_exists=true" >> $GITHUB_ENV
72+ echo "PR_NUMBER=$PR_EXISTS" >> $GITHUB_ENV
73+ else
74+ echo "pr_exists=false" >> $GITHUB_ENV
75+ fi
76+ - name : Create a pull request
77+ if : env.changes == 'true' && env.pr_exists == 'false'
4878 env :
4979 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5080 run : |
5181 PR_TITLE="Auto-update SDK on $(date +'%Y-%m-%d')"
52- PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK."
53- curl -H "Authorization: token $GITHUB_TOKEN" \
54- -X POST \
55- -H "Content-Type: application/json" \
56- -d @- \
57- https://api.github.com/repos/${{ github.repository }}/pulls <<EOF
58- {
59- "title": "$PR_TITLE",
60- "body": "$PR_BODY",
61- "head": "auto-update-sdk",
62- "base": "main"
63- }
64- EOF
82+ PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK with the latest remote OpenAPI specification."
83+ gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head $BRANCH_NAME --base main
84+ - name : Update existing pull request
85+ if : env.changes == 'true' && env.pr_exists == 'true'
86+ env :
87+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
88+ run : |
89+ echo "An existing pull request titled 'Auto-update SDK' is already open. Updating it with the latest changes."
90+ git push --set-upstream origin $BRANCH_NAME --force
91+ gh pr comment $PR_NUMBER --body "This pull request has been updated with the latest changes from the automated SDK update process on $(date +'%Y-%m-%d %H:%M:%S')."
92+
0 commit comments