Skip to content

feat: add minimal database setup with SQLite and PostgreSQL support a… #13

feat: add minimal database setup with SQLite and PostgreSQL support a…

feat: add minimal database setup with SQLite and PostgreSQL support a… #13

Workflow file for this run

name: Generate OpenAPI Spec and Diff
on:
push:
branches:
- "main"
paths:
- "src/api/**"
- "src/schemas.py"
- "src/models.py"
- ".github/workflows/openapi-spec.yml"
pull_request:
types: [ labeled ]
jobs:
generate-openapi:
permissions:
contents: read
pull-requests: write
# run the job only if the label is `openapi-spec` and would skip if the label is anything else.
if: ${{ github.event.label.name == 'openapi-spec' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: "0.8.17"
enable-cache: true
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10.6'
- name: Install the project
run: uv sync --locked --dev
- name: Setup ENV file
run: cp .env.example .env
shell: bash
- name: Export environment variables
run: |
set -a
source .env
set +a
env | grep -v '^_' >> $GITHUB_ENV
- name: Generate OpenAPI spec
run: |
PYTHONPATH=src uv run python scripts/generate_openapi.py
- name: Upload OpenAPI spec as artifact
uses: actions/upload-artifact@v4
with:
name: openapi-spec
path: openapi.json
- name: Comment PR with spec
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const spec = fs.readFileSync('openapi.json', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## 📋 OpenAPI Specification\n\n<details>\n<summary>Click to expand</summary>\n\n\`\`\`json\n${spec}\n\`\`\`\n\n</details>`
});
- name: Generate base spec
run: |
git fetch origin ${{ github.base_ref }}
git checkout origin/${{ github.base_ref }}
PYTHONPATH=src uv run python scripts/generate_openapi.py
mv openapi.json openapi-base.json
- name: Generate PR spec
run: |
git fetch
git checkout ${{ github.head_ref }}
PYTHONPATH=src uv run python scripts/generate_openapi.py
- name: Generate diff
run: |
diff -u openapi-base.json openapi.json > openapi-diff.txt || true
- name: Comment PR with diff
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const diff = fs.readFileSync('openapi-diff.txt', 'utf8');
const body = diff.trim()
? `## 📊 OpenAPI Spec Changes\n\n\`\`\`diff\n${diff}\n\`\`\``
: `## 📊 OpenAPI Spec Changes\n\nNo changes detected in the OpenAPI specification.`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});