1+ name : Auto-Update SDK
2+
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+ jobs :
9+ update-sdk :
10+ runs-on : ubuntu-latest
11+ strategy :
12+ matrix :
13+ python-version : ["3.12"]
14+ steps :
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
27+ run : |
28+ python -m pip install --upgrade pip
29+ pip install -r requirements.txt
30+ - name : Pull and generate SDK
31+ run : make gen-openapi-remote-for-ci
32+ - name : Check for changes
33+ id : check_changes
34+ run : |
35+ if git diff --quiet; then
36+ echo "changes=false" >> $GITHUB_ENV
37+ else
38+ echo "changes=true" >> $GITHUB_ENV
39+ 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"
45+ - name : Commit changes
46+ if : env.changes == 'true'
47+ run : |
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
51+ git add .
52+ git commit -m "Auto-update SDK on $(date +'%Y-%m-%d')"
53+ - name : Push changes
54+ if : env.changes == 'true'
55+ env :
56+ 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'
60+ run : |
61+ sudo apt-get update
62+ sudo apt-get install -y gh
63+ - name : Check for existing pull request
64+ 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'
78+ env :
79+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
80+ run : |
81+ PR_TITLE="Auto-update SDK on $(date +'%Y-%m-%d')"
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