@@ -4,61 +4,92 @@ name: Auto-Update SDK
44# schedule:
55# - cron: "0 0 * * 1" # Runs every Monday at midnight
66# workflow_dispatch: # Allows manual triggering of the workflow
7-
8- on : [push, pull_request]
7+ on : [push]
98
109jobs :
1110 update-sdk :
1211 runs-on : ubuntu-latest
12+ strategy :
13+ matrix :
14+ python-version : ["3.12"]
1315 steps :
14- - name : Checkout repository
16+ - uses : actions/checkout@v3
17+ - name : Set up Python ${{ matrix.python-version }}
18+ uses : actions/setup-python@v5
19+ with :
20+ python-version : ${{ matrix.python-version }}
21+ - name : Set up Node.js
22+ uses : actions/setup-node@v3
23+ with :
24+ node-version : ' 18'
25+ - name : Install OpenAPI Generator CLI
26+ run : npm install @openapitools/openapi-generator-cli -g
27+ - name : Install dependencies
1528 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"
29+ python -m pip install --upgrade pip
30+ pip install -r requirements.txt
2031 - name : Pull and generate SDK
21- run : |
22- cd repo
23- make gen-openapi-remote
32+ run : make gen-openapi-remote-for-ci
2433 - name : Check for changes
34+ id : check_changes
2535 run : |
26- cd repo
2736 if git diff --quiet; then
2837 echo "changes=false" >> $GITHUB_ENV
2938 else
3039 echo "changes=true" >> $GITHUB_ENV
3140 fi
41+ - name : Set up Git
42+ if : env.changes == 'true'
43+ run : |
44+ git config user.name "github-actions[bot]"
45+ git config user.email "github-actions[bot]@users.noreply.github.com"
3246 - name : Commit changes
3347 if : env.changes == 'true'
3448 run : |
35- cd repo
36- git checkout -b auto-update-sdk || git checkout auto-update-sdk
49+ BRANCH_NAME="auto-update-sdk-$(date +'%Y-%m-%d-%H-%M-%S')"
50+ echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
51+ git checkout -b $BRANCH_NAME || git checkout $BRANCH_NAME
3752 git add .
3853 git commit -m "Auto-update SDK on $(date +'%Y-%m-%d')"
3954 - name : Push changes
4055 if : env.changes == 'true'
4156 env :
4257 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
58+ run : git push --force --set-upstream origin $BRANCH_NAME
59+ - name : Install GitHub CLI
60+ if : env.changes == 'true'
4361 run : |
44- cd repo
45- git push --force --set-upstream origin auto-update-sdk
46- - name : Create a pull request
62+ sudo apt-get update
63+ sudo apt-get install -y gh
64+ - name : Check for existing pull request
4765 if : env.changes == 'true'
66+ env :
67+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
68+ id : check_pr
69+ run : |
70+ PR_EXISTS=$(gh pr list --search "Auto-update SDK" --base main --state open --json number -q '.[0].number')
71+ if [[ -n "$PR_EXISTS" ]]; then
72+ echo "pr_exists=true" >> $GITHUB_ENV
73+ echo "PR_NUMBER=$PR_EXISTS" >> $GITHUB_ENV
74+ else
75+ echo "pr_exists=false" >> $GITHUB_ENV
76+ fi
77+ - name : Create a pull request
78+ if : env.changes == 'true' && env.pr_exists == 'false'
4879 env :
4980 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5081 run : |
5182 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
83+ PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK with the latest remote OpenAPI specification ."
84+ gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head $BRANCH_NAME --base main
85+ - name : Update existing pull request
86+ if : env.changes == 'true' && env.pr_exists == 'true'
87+ run : |
88+ echo "An existing pull request titled 'Auto-update SDK' is already open. Updating it with the latest changes."
89+
90+ # Push the changes to the existing branch to update the pull request
91+ git push --set-upstream origin $BRANCH_NAME --force
92+
93+ # Add a comment to the existing pull request to notify about the update
94+ 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')."
95+
0 commit comments