GitHub Raw JSON API

polarsource / polar

10,146 Python

Polar — A billing platform for the intelligence era

polar Specification

Located in .github/workflows/openapi-diff.yml on branch HEAD

Unknown YAML 2.9 KB
Raw YAML Specification
name: OpenAPI Diff

on:
  pull_request:
    types: [opened, synchronize, reopened]
    paths:
      - "server/polar/**"

concurrency:
  group: openapi-diff-${{ github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  openapi-diff:
    name: "OpenAPI Diff"
    runs-on: blacksmith-4vcpu-ubuntu-2404
    permissions:
      contents: read
      pull-requests: write

    env:
      POLAR_EMAIL_RENDERER_BINARY_PATH: "/tmp/email-renderer"
      POLAR_PYDANTIC_AI_GATEWAY_API_KEY: "POLAR_PYDANTIC_AI_GATEWAY_API_KEY"

    steps:
      - name: Checkout PR (head)
        uses: actions/[email protected]
        with:
          path: head

      - name: Checkout base branch
        uses: actions/[email protected]
        with:
          ref: ${{ github.base_ref }}
          path: base

      - name: Install uv
        uses: astral-sh/[email protected]
        with:
          enable-cache: true

      - name: Set up Python
        uses: actions/[email protected]
        with:
          python-version-file: "head/server/pyproject.toml"

      - name: Create mock email renderer binary
        run: |
          touch /tmp/email-renderer

      - name: Install head dependencies
        working-directory: ./head/server
        run: |
          uv sync --frozen
          uv run task generate_dev_jwks

      - name: Install base dependencies
        working-directory: ./base/server
        run: |
          uv sync --frozen
          uv run task generate_dev_jwks

      - name: Generate OpenAPI schema from head
        working-directory: ./head/server
        run: uv run -m scripts.generate_openapi > ${{ github.workspace }}/head.json

      - name: Generate OpenAPI schema from base
        working-directory: ./base/server
        run: uv run -m scripts.generate_openapi > ${{ github.workspace }}/base.json

      - name: Generate OpenAPI diff
        id: diff
        run: |
          if uvx openapi-kit diff ${{ github.workspace }}/base.json ${{ github.workspace }}/head.json --markdown-heading-level 3 > /tmp/diff.md; then
            echo "has_changes=false" >> $GITHUB_OUTPUT
          else
            echo "has_changes=true" >> $GITHUB_OUTPUT
          fi
          echo "content<<EOF" >> $GITHUB_OUTPUT
          cat /tmp/diff.md >> $GITHUB_OUTPUT
          echo "EOF" >> $GITHUB_OUTPUT

      - name: Find existing comment
        uses: peter-evans/find-comment@v4
        id: fc
        with:
          issue-number: ${{ github.event.pull_request.number }}
          body-includes: "<!-- __OPENAPI_DIFF -->"

      - name: Create or update PR comment
        uses: peter-evans/create-or-update-comment@v5
        with:
          comment-id: ${{ steps.fc.outputs.comment-id }}
          issue-number: ${{ github.event.pull_request.number }}
          edit-mode: replace
          body: |
            <!-- __OPENAPI_DIFF -->
            ## OpenAPI Changes

            ${{ steps.diff.outputs.has_changes == 'true' && steps.diff.outputs.content || '_No changes detected in the OpenAPI schema._' }}