@@ -15,19 +15,19 @@ jobs:
1515
1616 steps :
1717 - name : Checkout repository
18- uses : actions/checkout@v4
18+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1919 with :
2020 fetch-depth : 0 # Fetch all history
2121 token : ${{ secrets.GITHUB_TOKEN }}
2222
2323 - name : Set up Python
24- uses : actions/setup-python@v4
24+ uses : actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
2525 with :
2626 python-version-file : ' .python-version'
2727
2828 - name : Install dependencies
2929 run : |
30- pip install requests
30+ pip install requests==2.32.5
3131
3232 - name : Get OpenAPI version and check for existing PRs
3333 id : version_check
3838 import subprocess
3939 import sys
4040 import os
41-
41+
4242 def get_openapi_version():
4343 """Get version from OpenAPI spec"""
4444 try:
@@ -49,15 +49,15 @@ jobs:
4949 except Exception as e:
5050 print(f"Error fetching OpenAPI spec: {e}")
5151 return None
52-
52+
5353 def check_existing_prs():
5454 """Check if there are existing open PRs from the bot"""
5555 try:
5656 result = subprocess.run([
57- 'gh', 'pr', 'list', '--state', 'open',
57+ 'gh', 'pr', 'list', '--state', 'open',
5858 '--author', 'app/github-actions', '--json', 'title'
5959 ], capture_output=True, text=True, check=True)
60-
60+
6161 prs = json.loads(result.stdout)
6262 for pr in prs:
6363 if 'SDK update' in pr.get('title', '') or 'OpenAPI' in pr.get('title', ''):
@@ -66,19 +66,19 @@ jobs:
6666 except Exception as e:
6767 print(f"Error checking existing PRs: {e}")
6868 return True # Assume PR exists to be safe
69-
69+
7070 # Main logic
7171 print("🔍 Getting OpenAPI version and checking for existing PRs...")
72-
72+
7373 # Get OpenAPI version
7474 openapi_version = get_openapi_version()
75-
75+
7676 if not openapi_version:
7777 print("❌ Could not retrieve OpenAPI version")
7878 sys.exit(1)
79-
79+
8080 print(f"📋 OpenAPI version: {openapi_version}")
81-
81+
8282 # Check for existing PRs
8383 if check_existing_prs():
8484 print("📋 Existing PR found, skipping SDK generation")
@@ -89,15 +89,15 @@ jobs:
8989 with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
9090 f.write(f"should_generate=true\n")
9191 f.write(f"openapi_version={openapi_version}\n")
92-
92+
9393 print("✅ Check completed")
9494 EOF
9595 env :
9696 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9797
9898 - name : Generate Python SDK
9999 if : steps.version_check.outputs.should_generate == 'true'
100- uses : openapi-generators/openapitools-generator-action@v1
100+ uses : openapi-generators/openapitools-generator-action@b729d184e6b3459572c37c0e37f88a832e69b552 # v1
101101 with :
102102 generator : python
103103 generator-tag : ' v7.17.0'
@@ -110,6 +110,8 @@ jobs:
110110 - name : Check for changes
111111 if : steps.version_check.outputs.should_generate == 'true'
112112 id : check_changes
113+ env :
114+ OPENAPI_VERSION : ${{ steps.version_check.outputs.openapi_version }}
113115 run : |
114116 # Move generated files to the correct locations and clean up
115117 rm -Rf docs && mv python-client/docs .
@@ -119,20 +121,20 @@ jobs:
119121 rm -Rf python-client
120122
121123 # Store the SDK version
122- echo ${{ steps.version_check.outputs.openapi_version }} > .sdk-version
124+ echo "$OPENAPI_VERSION" > .sdk-version
123125
124126 # Configure git
125127 git config user.name "github-actions[bot]"
126128 git config user.email "github-actions[bot]@users.noreply.github.com"
127-
129+
128130 # Check if there are any changes
129131 if git diff --quiet && git diff --cached --quiet; then
130132 echo "No changes detected in generated SDK"
131133 echo "has_changes=false" >> $GITHUB_OUTPUT
132134 else
133135 echo "Changes detected in generated SDK"
134136 echo "has_changes=true" >> $GITHUB_OUTPUT
135-
137+
136138 # Show what changed
137139 echo "Files changed:"
138140 git diff --name-only
@@ -142,43 +144,47 @@ jobs:
142144 fi
143145
144146 - name : Generate a token
147+ if : steps.version_check.outputs.should_generate == 'true' && steps.check_changes.outputs.has_changes == 'true'
145148 id : generate-token
146- uses : actions/create-github-app-token@v2
149+ uses : actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
147150 with :
148- app-id : ${{ vars .REVENG_APP_ID }}
151+ app-id : ${{ secrets .REVENG_APP_ID }}
149152 private-key : ${{ secrets.REVENG_APP_PRIVATE_KEY }}
150153 owner : ${{ github.repository_owner }}
151154 repositories : |
152155 sdk-python
153156
154157 - name : Create Pull Request
155158 if : steps.version_check.outputs.should_generate == 'true' && steps.check_changes.outputs.has_changes == 'true'
159+ env :
160+ GITHUB_TOKEN : ${{ steps.generate-token.outputs.token }}
161+ OPENAPI_VERSION : ${{ steps.version_check.outputs.openapi_version }}
156162 run : |
157163 # Create a new branch
158- BRANCH_NAME="sdk-update-${{ steps.version_check.outputs.openapi_version } }"
164+ BRANCH_NAME="sdk-update-${OPENAPI_VERSION }"
159165 git checkout -b "$BRANCH_NAME"
160-
166+
161167 # Stage all changes
162168 git add .
163-
169+
164170 # Commit changes
165- git commit -m "Update SDK to version ${{ steps.version_check.outputs.openapi_version } }
171+ git commit -m "Update SDK to version ${OPENAPI_VERSION }
166172
167- - Generated from OpenAPI spec version ${{ steps.version_check.outputs.openapi_version } }
173+ - Generated from OpenAPI spec version ${OPENAPI_VERSION }
168174 - Auto-generated by GitHub Actions"
169-
175+
170176 # Push the branch
171177 git push -f origin "$BRANCH_NAME"
172-
178+
173179 # Create PR using GitHub CLI
174180 gh pr create \
175- --title "🤖 Update SDK to version ${{ steps.version_check.outputs.openapi_version } }" \
181+ --title "🤖 Update SDK to version ${OPENAPI_VERSION }" \
176182 --body "## 🔄 Automated SDK Update
177183
178184 This PR was automatically generated to update the Python SDK to match the latest OpenAPI specification.
179185
180186 ### 📊 Version Information
181- - **OpenAPI Spec Version**: \`${{ steps.version_check.outputs.openapi_version } }\`
187+ - **OpenAPI Spec Version**: \`${OPENAPI_VERSION }\`
182188
183189 ### 🔧 Changes
184190 - Generated fresh SDK from [OpenAPI specification](https://api.reveng.ai/openapi.json)
@@ -194,8 +200,6 @@ jobs:
194200 🤖 *This PR was created automatically by GitHub Actions*" \
195201 --head "$BRANCH_NAME" \
196202 --base main
197-
203+
198204 echo "✅ Pull request created successfully"
199- echo "::notice title=PR Created::Created PR for SDK update to version ${{ steps.version_check.outputs.openapi_version }}"
200- env :
201- GITHUB_TOKEN : ${{ steps.generate-token.outputs.token }}
205+ echo "::notice title=PR Created::Created PR for SDK update to version ${OPENAPI_VERSION}"
0 commit comments