Update OpenAPI Specification #337
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: Update OpenAPI Specification | |
| on: | |
| schedule: | |
| # Run daily at 2 AM UTC to check for updates | |
| - cron: "0 2 * * *" | |
| workflow_dispatch: | |
| # Allow manual trigger | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update-openapi-spec: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 | |
| with: | |
| python-version: "3.10" | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 | |
| - name: Install dependencies | |
| run: uv sync | |
| - name: Check current OpenAPI spec info | |
| id: current-spec | |
| run: | | |
| if [ -f "resources/openapi-spec.json" ]; then | |
| CURRENT_VERSION=$(jq -r '.info.version // "unknown"' resources/openapi-spec.json) | |
| CURRENT_PATHS=$(jq '.paths | length' resources/openapi-spec.json) | |
| echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo "current-paths=$CURRENT_PATHS" >> $GITHUB_OUTPUT | |
| echo "Current spec version: $CURRENT_VERSION, paths: $CURRENT_PATHS" | |
| else | |
| echo "current-version=none" >> $GITHUB_OUTPUT | |
| echo "current-paths=0" >> $GITHUB_OUTPUT | |
| echo "No existing OpenAPI spec found" | |
| fi | |
| - name: Update OpenAPI specification | |
| id: update-spec | |
| run: | | |
| echo "Updating OpenAPI specification..." | |
| uv run python scripts/update_openapi_spec.py | |
| # Check if OpenAPI spec was changed | |
| if git diff --quiet resources/openapi-spec.json; then | |
| echo "has-changes=false" >> $GITHUB_OUTPUT | |
| echo "No changes detected in OpenAPI specification" | |
| else | |
| echo "has-changes=true" >> $GITHUB_OUTPUT | |
| echo "Changes detected in OpenAPI specification" | |
| # Get new spec info | |
| NEW_VERSION=$(jq -r '.info.version // "unknown"' resources/openapi-spec.json) | |
| NEW_PATHS=$(jq '.paths | length' resources/openapi-spec.json) | |
| echo "new-version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "new-paths=$NEW_PATHS" >> $GITHUB_OUTPUT | |
| echo "New spec version: $NEW_VERSION, paths: $NEW_PATHS" | |
| # Compute content hash for deduplication | |
| SPEC_HASH=$(sha256sum resources/openapi-spec.json | cut -d' ' -f1) | |
| echo "spec-sha256=$SPEC_HASH" >> $GITHUB_OUTPUT | |
| echo "Spec content hash: $SPEC_HASH" | |
| fi | |
| - name: Determine branch name | |
| id: branch-info | |
| if: steps.update-spec.outputs.has-changes == 'true' | |
| run: | | |
| SPEC_HASH="${{ steps.update-spec.outputs.spec-sha256 }}" | |
| if [ -z "$SPEC_HASH" ] || [ "$SPEC_HASH" = "unknown" ]; then | |
| SPEC_HASH=$(sha256sum resources/openapi-spec.json | cut -d' ' -f1) | |
| fi | |
| BRANCH="update-openapi-spec-${SPEC_HASH:0:12}" | |
| echo "branch=$BRANCH" >> $GITHUB_OUTPUT | |
| echo "Using branch $BRANCH for this update" | |
| - name: Check for existing PR | |
| id: existing-pr | |
| if: steps.update-spec.outputs.has-changes == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| BRANCH="${{ steps.branch-info.outputs.branch }}" | |
| if [ -z "$BRANCH" ]; then | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| PR_COUNT=$(gh pr list --state open --head "$BRANCH" --repo "$GITHUB_REPOSITORY" --json number --jq 'length') | |
| if [ "$PR_COUNT" -gt 0 ]; then | |
| echo "An open PR already exists for $BRANCH (count: $PR_COUNT)" | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Update search database | |
| if: steps.update-spec.outputs.has-changes == 'true' | |
| run: | | |
| echo "Updating search database with new OpenAPI specification..." | |
| uv run python scripts/create_search_database.py | |
| # Check if database was created/updated | |
| if [ -f "resources/authlete_apis.duckdb" ]; then | |
| DB_SIZE=$(wc -c < "resources/authlete_apis.duckdb") | |
| echo "✅ Search database updated successfully (size: $DB_SIZE bytes)" | |
| # Get API count from database | |
| API_COUNT=$(uv run python -c "import duckdb; \ | |
| conn = duckdb.connect('resources/authlete_apis.duckdb'); \ | |
| result = conn.execute('SELECT COUNT(*) FROM api_endpoints').fetchone(); \ | |
| print(result[0]); \ | |
| conn.close()" 2>/dev/null || echo "0") | |
| echo "📊 APIs indexed in search database: $API_COUNT" | |
| else | |
| echo "❌ Failed to create search database" | |
| exit 1 | |
| fi | |
| - name: Create Pull Request | |
| if: steps.update-spec.outputs.has-changes == 'true' && steps.existing-pr.outputs.exists != 'true' | |
| uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: | | |
| chore: update OpenAPI specification and search database | |
| - Updated from Authlete docs (https://docs.authlete.com/en/shared/3.0.0/spec) | |
| - Version: ${{ steps.current-spec.outputs.current-version }} → ${{ steps.update-spec.outputs.new-version }} | |
| - Paths: ${{ steps.current-spec.outputs.current-paths }} → ${{ steps.update-spec.outputs.new-paths }} | |
| - Regenerated DuckDB search database for API search functionality | |
| - Content hash: ${{ steps.update-spec.outputs.spec-sha256 }} | |
| Auto-generated by update-openapi-spec workflow | |
| branch: ${{ steps.branch-info.outputs.branch }} | |
| delete-branch: true | |
| title: "chore: update OpenAPI specification to v${{ steps.update-spec.outputs.new-version }}" | |
| body: | | |
| ## OpenAPI Specification Update | |
| This PR updates the OpenAPI specification from the latest Authlete documentation. | |
| **Changes:** | |
| - **Version:** `${{ steps.current-spec.outputs.current-version }}` → \ | |
| `${{ steps.update-spec.outputs.new-version }}` | |
| - **API Endpoints:** `${{ steps.current-spec.outputs.current-paths }}` → \ | |
| `${{ steps.update-spec.outputs.new-paths }}` | |
| - **Source:** https://raw.githubusercontent.com/authlete/openapi/refs/heads/main/spec_next.yaml | |
| **Files Updated:** | |
| - `resources/openapi-spec.json` - OpenAPI specification | |
| - `resources/authlete_apis.duckdb` - Search database for API search functionality | |
| **Verification:** | |
| - [ ] OpenAPI spec is valid JSON | |
| - [ ] Spec contains expected Authlete API endpoints | |
| - [ ] Search database was successfully generated | |
| - [ ] API search functionality works with updated database | |
| - [ ] No breaking changes in existing endpoint definitions | |
| --- | |
| 🤖 This PR was automatically created by the `update-openapi-spec` GitHub Action. | |
| **Review Guidelines:** | |
| 1. Verify the changes are legitimate updates from Authlete | |
| 2. Check that no critical API definitions have been removed | |
| 3. Ensure the new version is correctly parsed | |
| 4. Consider updating any dependent code or documentation | |
| labels: | | |
| dependencies | |
| automation | |
| documentation | |
| reviewers: | | |
| watahani | |
| - name: Summary | |
| run: | | |
| if [ "${{ steps.update-spec.outputs.has-changes }}" = "true" ]; then | |
| if [ "${{ steps.existing-pr.outputs.exists }}" = "true" ]; then | |
| echo "ℹ️ OpenAPI spec update matches an existing open PR." | |
| echo "🔁 Reusing branch ${{ steps.branch-info.outputs.branch }}" | |
| else | |
| echo "✅ OpenAPI spec and search database updated successfully" | |
| echo "📊 Version: ${{ steps.current-spec.outputs.current-version }} → \ | |
| ${{ steps.update-spec.outputs.new-version }}" | |
| echo "🔧 Paths: ${{ steps.current-spec.outputs.current-paths }} → \ | |
| ${{ steps.update-spec.outputs.new-paths }}" | |
| echo "🗃️ Search database regenerated for Python API search MCP server" | |
| echo "📋 PR created with both OpenAPI spec and DuckDB database updates" | |
| fi | |
| else | |
| echo "ℹ️ OpenAPI spec is already up to date - no database update needed" | |
| fi |