2020 - name : Set up Node.js
2121 uses : actions/setup-node@v3
2222 with :
23- node-version : ' 18'
23+ node-version : ' 18'
2424 - name : Install OpenAPI Generator CLI
25- run : npm install @openapitools/openapi-generator-cli -g
25+ run : npm install @openapitools/openapi-generator-cli@2.31.1 -g
2626 - name : Install dependencies
2727 run : |
2828 python -m pip install --upgrade pip
@@ -32,11 +32,33 @@ jobs:
3232 - name : Check for changes
3333 id : check_changes
3434 run : |
35- if git diff --quiet; then
35+ git add -A
36+ if git diff --cached --quiet; then
3637 echo "changes=false" >> $GITHUB_ENV
3738 else
3839 echo "changes=true" >> $GITHUB_ENV
3940 fi
41+ - name : Install GitHub CLI
42+ if : env.changes == 'true'
43+ run : |
44+ sudo apt-get update
45+ sudo apt-get install -y gh
46+ - name : Check for existing pull request
47+ if : env.changes == 'true'
48+ env :
49+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
50+ id : check_pr
51+ run : |
52+ PR_EXISTS=$(gh pr list --search "Auto-update SDK" --base main --state open --json number,headRefName -q '.[0].number')
53+ if [[ -n "$PR_EXISTS" ]]; then
54+ echo "pr_exists=true" >> $GITHUB_ENV
55+ echo "PR_NUMBER=$PR_EXISTS" >> $GITHUB_ENV
56+ EXISTING_BRANCH=$(gh pr list --search "Auto-update SDK" --base main --state open --json number,headRefName -q '.[0].headRefName')
57+ echo "BRANCH_NAME=$EXISTING_BRANCH" >> $GITHUB_ENV
58+ else
59+ echo "pr_exists=false" >> $GITHUB_ENV
60+ echo "BRANCH_NAME=auto-update-sdk-$(date +'%Y-%m-%d-%H-%M-%S')" >> $GITHUB_ENV
61+ fi
4062 - name : Set up Git
4163 if : env.changes == 'true'
4264 run : |
@@ -45,34 +67,13 @@ jobs:
4567 - name : Commit changes
4668 if : env.changes == 'true'
4769 run : |
48- BRANCH_NAME="auto-update-sdk-$(date +'%Y-%m-%d-%H-%M-%S')"
49- echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
5070 git checkout -b $BRANCH_NAME || git checkout $BRANCH_NAME
51- git add .
5271 git commit -m "Auto-update SDK on $(date +'%Y-%m-%d')"
5372 - name : Push changes
5473 if : env.changes == 'true'
5574 env :
5675 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5776 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
7677 - name : Create a pull request
7778 if : env.changes == 'true' && env.pr_exists == 'false'
7879 env :
8182 PR_TITLE="Auto-update SDK on $(date +'%Y-%m-%d')"
8283 PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK with the latest remote OpenAPI specification."
8384 gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head $BRANCH_NAME --base main
84- - name : Update existing pull request
85+ - name : Comment on existing pull request
8586 if : env.changes == 'true' && env.pr_exists == 'true'
8687 env :
8788 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
8889 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
9190 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