@@ -14,31 +14,31 @@ jobs:
1414
1515 steps :
1616 # Step 1: Initialize Log File
17- - name : Initialize Log File
17+ - name : 📝 Initialize Log File
1818 run : |
1919 mkdir -p logs
2020 echo "" > logs/log
2121
2222 # Step 2: Checkout the code
23- - name : Checkout repository
23+ - name : 📥 Checkout repository
2424 uses : actions/checkout@v4
2525 with :
2626 ref : trunk
2727
2828 # Step 3: Set up Python environment
29- - name : Set up Python
29+ - name : 🐍 Set up Python
3030 uses : actions/setup-python@v5
3131 with :
3232 python-version : " 3.12"
3333
3434 # Step 4: Set up Node.js
35- - name : Set up Node.js
35+ - name : 🟢 Set up Node.js
3636 uses : actions/setup-node@v4
3737 with :
3838 node-version : " 22"
3939
4040 # Step 5: Install dependencies
41- - name : Install Dependencies
41+ - name : 📦 Install Dependencies
4242 run : |
4343 python -m pip install --upgrade pip
4444 pip install openapi-python-client yq
@@ -47,20 +47,20 @@ jobs:
4747 openapi-python-client --version >> logs/log 2>&1
4848
4949 # Step 6: Download OpenAPI Specification
50- - name : Download OpenAPI Specification
50+ - name : ⬇️ Download OpenAPI Specification
5151 run : |
5252 echo "Downloading OpenAPI specification..."
5353 mkdir -p openapi_specification
5454 curl -s ${{ env.OPENAPI_SPEC_URL }} > ./openapi_specification/openapi.json
5555
5656 # Step 7: Format OpenAPI Specification
57- - name : Format OpenAPI Specification
57+ - name : 🔧 Format OpenAPI Specification
5858 run : |
5959 echo "Formatting OpenAPI specification..."
6060 npx prettier --write ./openapi_specification/openapi.json
6161
6262 # Step 8: Get API Version
63- - name : Get API Version
63+ - name : 🔢 Get API Version
6464 run : |
6565 if yq -e '.package_version_override' config.yaml > /dev/null; then
6666 VERSION=$(yq -r '.package_version_override' config.yaml)
8181 echo "$VERSION" > openapi_specification/version
8282 echo "VERSION=$VERSION" >> $GITHUB_ENV
8383
84- # Step 9: Generate Python Client
85- - name : Generate Python Client
84+ # Step 9: Check for existing PR
85+ - name : 🔍 Check for existing PR
8686 if : env.version_changed == 'true'
87+ run : |
88+ PR_EXISTS=$(gh pr list --repo ${{ github.repository }} --base trunk --head "update-python-client-${{ env.VERSION }}" --json number --jq 'length')
89+ if [ "$PR_EXISTS" -gt 0 ]; then
90+ echo "A pull request for version ${{ env.VERSION }} already exists. Skipping update."
91+ echo "pr_exists=true" >> $GITHUB_ENV
92+ else
93+ echo "No pull request found for version ${{ env.VERSION }}. Proceeding with update."
94+ echo "pr_exists=false" >> $GITHUB_ENV
95+ fi
96+ env :
97+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
98+
99+ # Step 10: Generate Python Client
100+ - name : ⚙️ Generate Python Client
101+ if : env.version_changed == 'true' && env.pr_exists == 'false'
87102 run : |
88103 echo "Generating API client..." >> logs/log
89104 openapi-python-client generate \
93108 --config config.yaml >> logs/log 2>&1
94109 cat logs/log
95110
96- # Step 10 : Check for Changes
97- - name : Check for Changes
98- if : env.version_changed == 'true'
111+ # Step 11 : Check for Changes
112+ - name : 👀 Check for Changes
113+ if : env.version_changed == 'true' && env.pr_exists == 'false'
99114 id : git_diff
100115 run : |
101116 git add .
@@ -105,16 +120,16 @@ jobs:
105120 echo "changes_detected=true" >> $GITHUB_OUTPUT
106121 fi
107122
108- # Step 11 : Configure Git
109- - name : Configure Git
110- if : steps.git_diff.outputs.changes_detected == 'true'
123+ # Step 12 : Configure Git
124+ - name : 🔨 Configure Git
125+ if : env.version_changed == 'true' && env.pr_exists == 'false' && steps.git_diff.outputs.changes_detected == 'true'
111126 run : |
112127 git config --global user.name "github-actions[bot]"
113128 git config --global user.email "github-actions[bot]@users.noreply.github.com"
114129
115- # Step 12 : Create Pull Request
116- - name : Create Pull Request
117- if : steps.git_diff.outputs.changes_detected == 'true'
130+ # Step 13 : Create Pull Request
131+ - name : 🚀 Create Pull Request
132+ if : env.version_changed == 'true' && env.pr_exists == 'false' && steps.git_diff.outputs.changes_detected == 'true'
118133 uses : peter-evans/create-pull-request@v7
119134 with :
120135 token : ${{ secrets.PULL_REQUEST_TOKEN }}
0 commit comments