-
Notifications
You must be signed in to change notification settings - Fork 0
205 lines (170 loc) Β· 7.14 KB
/
check.yaml
File metadata and controls
205 lines (170 loc) Β· 7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: Check Updates
on:
schedule:
- cron: '0 06 * * 1-5'
workflow_dispatch: # Allow manual triggering
jobs:
check-version:
runs-on: ubuntu-latest
permissions:
contents: write # Required for creating branches and PRs
pull-requests: write # Required for creating PRs
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0 # Fetch all history
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version-file: '.python-version'
- name: Install dependencies
run: |
pip install requests==2.32.5
- name: Get OpenAPI version and check for existing PRs
id: version_check
run: |
python << 'EOF'
import requests
import json
import subprocess
import sys
import os
def get_openapi_version():
"""Get version from OpenAPI spec"""
try:
response = requests.get('https://docs.reveng.ai/openapi.json', timeout=30)
response.raise_for_status()
openapi_data = response.json()
return openapi_data.get('info', {}).get('version')
except Exception as e:
print(f"Error fetching OpenAPI spec: {e}")
return None
def check_existing_prs():
"""Check if there are existing open PRs from the bot"""
try:
result = subprocess.run([
'gh', 'pr', 'list', '--state', 'open',
'--author', 'app/github-actions', '--json', 'title'
], capture_output=True, text=True, check=True)
prs = json.loads(result.stdout)
for pr in prs:
if 'SDK update' in pr.get('title', '') or 'OpenAPI' in pr.get('title', ''):
return True
return False
except Exception as e:
print(f"Error checking existing PRs: {e}")
return True # Assume PR exists to be safe
# Main logic
print("π Getting OpenAPI version and checking for existing PRs...")
# Get OpenAPI version
openapi_version = get_openapi_version()
if not openapi_version:
print("β Could not retrieve OpenAPI version")
sys.exit(1)
print(f"π OpenAPI version: {openapi_version}")
# Check for existing PRs
if check_existing_prs():
print("π Existing PR found, skipping SDK generation")
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"should_generate=false\n")
else:
print("β
No existing PRs found, proceeding with SDK generation")
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"should_generate=true\n")
f.write(f"openapi_version={openapi_version}\n")
print("β
Check completed")
EOF
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Python SDK
if: steps.version_check.outputs.should_generate == 'true'
uses: openapi-generators/openapitools-generator-action@b729d184e6b3459572c37c0e37f88a832e69b552 # v1
with:
generator: python
generator-tag: 'v7.17.0'
openapi-url: https://docs.reveng.ai/openapi.json
config-file: config.yml
template-dir: templates
command-args: |
--additional-properties=packageVersion=${{ steps.version_check.outputs.openapi_version }}
- name: Check for changes
if: steps.version_check.outputs.should_generate == 'true'
id: check_changes
env:
OPENAPI_VERSION: ${{ steps.version_check.outputs.openapi_version }}
run: |
# Move generated files to the correct locations and clean up
rm -Rf docs && mv python-client/docs .
rm -Rf revengai && mv python-client/revengai .
rm -Rf test && mv python-client/test .
rm -Rf README.md && mv python-client/README.md .
rm -Rf python-client
# Store the SDK version
echo "$OPENAPI_VERSION" > .sdk-version
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Check if there are any changes
if git diff --quiet && git diff --cached --quiet; then
echo "No changes detected in generated SDK"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected in generated SDK"
echo "has_changes=true" >> $GITHUB_OUTPUT
# Show what changed
echo "Files changed:"
git diff --name-only
echo
echo "Summary of changes:"
git diff --stat
fi
- name: Generate a token
if: steps.version_check.outputs.should_generate == 'true' && steps.check_changes.outputs.has_changes == 'true'
id: generate-token
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
with:
app-id: ${{ secrets.REVENG_APP_ID }}
private-key: ${{ secrets.REVENG_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: |
sdk-python
- name: Create Pull Request
if: steps.version_check.outputs.should_generate == 'true' && steps.check_changes.outputs.has_changes == 'true'
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
OPENAPI_VERSION: ${{ steps.version_check.outputs.openapi_version }}
run: |
# Create a new branch
BRANCH_NAME="sdk-update-${OPENAPI_VERSION}"
git checkout -b "$BRANCH_NAME"
# Stage all changes
git add .
# Commit changes
git commit -m "Update SDK to version ${OPENAPI_VERSION}
- Generated from OpenAPI spec version ${OPENAPI_VERSION}
- Auto-generated by GitHub Actions"
# Push the branch
git push -f origin "$BRANCH_NAME"
# Create PR using GitHub CLI
gh pr create \
--title "π€ Update SDK to version ${OPENAPI_VERSION}" \
--body "## π Automated SDK Update
This PR was automatically generated to update the Python SDK to match the latest OpenAPI specification.
### π Version Information
- **OpenAPI Spec Version**: \`${OPENAPI_VERSION}\`
### π§ Changes
- Generated fresh SDK from [OpenAPI specification](https://docs.reveng.ai/openapi.json)
- Updated package version to match OpenAPI spec version
- All changes are auto-generated using openapi-generator
### β
Next Steps
1. Review the generated changes
2. Run tests to ensure compatibility
3. Merge to trigger automatic PyPI publishing
---
π€ *This PR was created automatically by GitHub Actions*" \
--head "$BRANCH_NAME" \
--base main
echo "β
Pull request created successfully"
echo "::notice title=PR Created::Created PR for SDK update to version ${OPENAPI_VERSION}"