Regenerate Client from API Spec #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Regenerate Client from API Spec | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| spec_version: | |
| description: 'API Spec Version' | |
| required: true | |
| type: string | |
| spec_commit: | |
| description: 'Devgraph commit SHA that triggered this' | |
| required: true | |
| type: string | |
| # Optional: Also trigger on schedule to check for missed updates | |
| schedule: | |
| - cron: '0 2 * * *' # Daily at 2am UTC | |
| jobs: | |
| regenerate: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install Poetry | |
| uses: snok/install-poetry@v1 | |
| with: | |
| version: 1.7.1 | |
| virtualenvs-create: true | |
| virtualenvs-in-project: true | |
| - name: Download API spec | |
| run: | | |
| mkdir -p specs | |
| curl -o specs/openapi.yaml \ | |
| https://raw.githubusercontent.com/arctir/devgraph-api/v${{ inputs.spec_version }}/v1/spec.yaml | |
| echo "✓ Downloaded API spec v${{ inputs.spec_version }}" | |
| - name: Generate Python client | |
| run: | | |
| # Install openapi-python-client | |
| pip install openapi-python-client | |
| # Generate client (overwrite existing) | |
| openapi-python-client generate \ | |
| --path specs/openapi.yaml \ | |
| --output-path . \ | |
| --config openapi-generator-config.yaml \ | |
| --overwrite | |
| echo "✓ Client generated" | |
| - name: Update client version | |
| run: | | |
| # Update version in pyproject.toml to match API version | |
| sed -i 's/^version = .*/version = "${{ inputs.spec_version }}"/' pyproject.toml | |
| echo "✓ Updated version to ${{ inputs.spec_version }}" | |
| - name: Install dependencies | |
| run: | | |
| poetry install --no-interaction | |
| - name: Run linting | |
| run: | | |
| poetry run ruff check src/ || true | |
| poetry run mypy src/ || true | |
| - name: Run tests | |
| run: | | |
| poetry run pytest tests/ -v | |
| - name: Commit and push changes | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Check if there are changes to commit | |
| if [[ -n $(git status -s) ]]; then | |
| git add . | |
| git commit -m "$(cat <<'EOF' | |
| Update client for API v${{ inputs.spec_version }} | |
| Auto-generated from devgraph@${{ inputs.spec_commit }} | |
| Spec URL: https://github.com/arctir/devgraph-api/tree/v${{ inputs.spec_version }} | |
| 🤖 Generated with [Claude Code](https://claude.com/claude-code) | |
| Co-Authored-By: Claude <noreply@anthropic.com> | |
| EOF | |
| )" | |
| git push origin main | |
| echo "✓ Changes committed and pushed to main" | |
| # Extract client version from pyproject.toml | |
| CLIENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') | |
| # Create and push tag | |
| git tag -fa "v${CLIENT_VERSION}" -m "Python client v${CLIENT_VERSION} for API v${{ inputs.spec_version }}" | |
| git push origin "v${CLIENT_VERSION}" --force | |
| echo "✓ Tagged as v${CLIENT_VERSION}" | |
| # Build and publish to GitHub Package Registry | |
| poetry build | |
| poetry config repositories.github https://pypi.pkg.github.com/arctir | |
| poetry publish -r github -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} | |
| echo "✓ Published to GitHub Package Registry" | |
| else | |
| echo "No changes to commit" | |
| fi | |
| - name: Create summary | |
| if: always() | |
| run: | | |
| echo "## 🐍 Python Client Regenerated" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **API Version**: \`${{ inputs.spec_version }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Source Commit**: [${{ inputs.spec_commit }}](https://github.com/arctir/devgraph/commit/${{ inputs.spec_commit }})" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Spec URL**: https://github.com/arctir/devgraph-api/tree/v${{ inputs.spec_version }}" >> $GITHUB_STEP_SUMMARY |