spec_updated #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: Spec Check | |
| on: | |
| repository_dispatch: | |
| types: [spec_updated] | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| check-compatibility: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: astral-sh/setup-uv@v4 | |
| with: | |
| enable-cache: true | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.13' | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Download latest OpenAPI spec from monorepo | |
| run: | | |
| gh api repos/devhelmhq/mono/contents/docs/openapi/monitoring-api.json \ | |
| -H "Accept: application/vnd.github.raw+json" \ | |
| > docs/openapi/monitoring-api.json | |
| env: | |
| GH_TOKEN: ${{ secrets.MONOREPO_DISPATCH_TOKEN }} | |
| # Sparse-checkout the shared OpenAPI preprocessor from mono. | |
| # typegen.sh prefers $OPENAPI_TOOLS → local sibling → npx; without this | |
| # step, CI falls through to `npx @devhelm/openapi-tools` which is | |
| # intentionally unpublished (internal-only package). | |
| - name: Checkout @devhelm/openapi-tools from mono | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: devhelmhq/mono | |
| token: ${{ secrets.MONOREPO_DISPATCH_TOKEN }} | |
| path: .mono | |
| sparse-checkout: packages/openapi-tools | |
| sparse-checkout-cone-mode: false | |
| - name: Build @devhelm/openapi-tools | |
| working-directory: .mono/packages/openapi-tools | |
| # mono uses pnpm workspaces; we only need this one package's deps here, | |
| # so install standalone with npm (no lockfile in this subdir). | |
| run: | | |
| npm install --no-package-lock --no-audit --no-fund | |
| npm run build | |
| - run: uv sync | |
| - run: uv run pytest -v | |
| - name: Regenerate types from spec | |
| env: | |
| OPENAPI_TOOLS: node ${{ github.workspace }}/.mono/packages/openapi-tools/dist/cli.js | |
| run: ./scripts/typegen.sh | |
| - name: Check for type changes | |
| id: diff | |
| run: | | |
| if git diff --quiet src/devhelm/_generated.py docs/openapi/; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Open PR with updated types | |
| if: steps.diff.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| branch="chore/update-api-types-$(date +%Y%m%d%H%M%S)" | |
| git checkout -b "$branch" | |
| git add src/devhelm/_generated.py docs/openapi/monitoring-api.json | |
| git commit -m "chore: update generated API types from latest spec" | |
| git push -u origin "$branch" | |
| gh pr create \ | |
| --title "chore: update generated API types" \ | |
| --body "Auto-generated from latest OpenAPI spec in the monorepo." \ | |
| --base main | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Report failure | |
| if: failure() | |
| run: | | |
| gh issue create \ | |
| --title "API spec change broke Python SDK build" \ | |
| --body "The monorepo pushed a spec update that caused CI failures.\n\nWorkflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |