Skip to content

Check Updates

Check Updates #14

Workflow file for this run

name: Version Check and SDK Update
on:
schedule:
# Run every hour
- cron: '0 * * * *'
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@v4
with:
fetch-depth: 0 # Fetch all history
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version-file: '.python-version'
- name: Install dependencies
run: |
pip install requests packaging
- name: Check versions and generate SDK if needed
id: version_check
run: |
python << 'EOF'
import requests
import json
import subprocess
import sys
import os
from packaging import version
def get_openapi_version():
"""Get version from OpenAPI spec"""
try:
response = requests.get('https://api.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 get_pypi_version(package_name):
"""Get latest version from PyPI"""
try:
response = requests.get(f'https://pypi.org/pypi/{package_name}/json', timeout=30)
response.raise_for_status()
pypi_data = response.json()
return pypi_data.get('info', {}).get('version')
except Exception as e:
print(f"Error fetching PyPI data: {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("πŸ” Checking versions...")
# Get versions
openapi_version = get_openapi_version()
pypi_version = get_pypi_version('revengai')
if not openapi_version:
print("❌ Could not retrieve OpenAPI version")
sys.exit(1)
if not pypi_version:
print("❌ Could not retrieve PyPI version")
sys.exit(1)
print(f"πŸ“‹ OpenAPI version: {openapi_version}")
print(f"πŸ“¦ PyPI version: {pypi_version}")
# Compare versions
try:
openapi_ver = version.parse(openapi_version)
pypi_ver = version.parse(pypi_version)
if openapi_ver > pypi_ver:
print(f"πŸ†• New version detected! OpenAPI: {openapi_version} > PyPI: {pypi_version}")
# Check for existing PRs
if check_existing_prs():
print("πŸ“‹ Existing PR found, skipping SDK generation")
sys.exit(0)
print("βœ… No existing PRs found, proceeding with SDK generation")
# Set output to trigger 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")
f.write(f"pypi_version={pypi_version}\n")
elif openapi_ver == pypi_ver:
print("βœ… Versions are in sync")
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"should_generate=false\n")
else:
print(f"ℹ️ OpenAPI version ({openapi_version}) is older than PyPI version ({pypi_version})")
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"should_generate=false\n")
except Exception as e:
print(f"Error comparing versions: {e}")
sys.exit(1)
print("βœ… Version 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@v1
with:
generator: python
openapi-file: https://api.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
run: |
# 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: Create Pull Request
if: steps.version_check.outputs.should_generate == 'true' && steps.check_changes.outputs.has_changes == 'true'
run: |
# Create a new branch
BRANCH_NAME="sdk-update-v${{ steps.version_check.outputs.openapi_version }}"
git checkout -b "$BRANCH_NAME"
# Stage all changes
git add .
# Commit changes
git commit -m "Update SDK to version ${{ steps.version_check.outputs.openapi_version }}
- Generated from OpenAPI spec version ${{ steps.version_check.outputs.openapi_version }}
- Previous PyPI version: ${{ steps.version_check.outputs.pypi_version }}
- Auto-generated by GitHub Actions"
# Push the branch
git push origin "$BRANCH_NAME"
# Create PR using GitHub CLI
gh pr create \
--title "πŸ€– Update SDK to version ${{ steps.version_check.outputs.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**: \`${{ steps.version_check.outputs.openapi_version }}\`
- **Current PyPI Version**: \`${{ steps.version_check.outputs.pypi_version }}\`
### πŸ”§ Changes
- Generated fresh SDK from [OpenAPI specification](https://api.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 \
--label "automated" \
--label "sdk-update"
echo "βœ… Pull request created successfully"
echo "::notice title=PR Created::Created PR for SDK update to version ${{ steps.version_check.outputs.openapi_version }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}