Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ci): split migration and OpenAPI checks (#58015)

Raúl Negrón-Otero3332a29e10f0
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
index 734854e034cd..b48425b5a9e5 100644
--- a/.github/workflows/ci-backend.yml
+++ b/.github/workflows/ci-backend.yml
@@ -71,6 +71,7 @@ jobs:
backend_files: ${{ steps.filter.outputs.backend_files }}
migrations: ${{ steps.filter.outputs.migrations || 'true' }}
migrations_files: ${{ steps.filter.outputs.migrations_files }}
+ persons-SQL: ${{ steps.filter.outputs['persons-SQL'] || 'true' }}
tasks_temporal: ${{ steps.filter.outputs.tasks_temporal || 'true' }}
openapi_types: ${{ steps.filter.outputs.openapi_types || 'true' }}
legacy: ${{ steps.filter.outputs.legacy || 'true' }}
@@ -191,6 +192,7 @@ jobs:
- 'posthog/migrations/*.py'
- 'products/*/backend/migrations/*.py'
- 'products/*/migrations/*.py' # Legacy structure
+ persons-SQL:
- 'rust/persons_migrations/*.sql'
- 'rust/bin/migrate-persons'
tasks_temporal:
@@ -559,13 +561,13 @@ jobs:
- name: Check product facade enforcement (import-linter)
run: lint-imports
- # Migration validation and OpenAPI type generation.
+ # Migration validation.
# This job needs Docker + DB — it checks out master first to run baseline
- # migrations, then checks out the PR branch. All steps after the PR checkout
- # require Django + DB. Lightweight checks belong in repo-checks above.
+ # migrations, then checks out the PR branch. OpenAPI type generation belongs
+ # in check-openapi-types below.
check-migrations:
needs: [changes]
- if: needs.changes.outputs.backend == 'true' || needs.changes.outputs.openapi_types == 'true'
+ if: needs.changes.outputs.backend == 'true' || needs.changes.outputs.migrations == 'true' || needs.changes.outputs['persons-SQL'] == 'true'
timeout-minutes: 20
# checks: write is needed so the "Publish Migration risk check" step
# can POST to /repos/.../check-runs. Workflow-level perms only grant
@@ -575,7 +577,7 @@ jobs:
pull-requests: write
checks: write
- name: Validate migrations and OpenAPI types
+ name: Validate migrations
runs-on: depot-ubuntu-latest
steps:
@@ -591,9 +593,8 @@ jobs:
- name: Stop/Start stack with Docker Compose
env:
COMPOSE_FILE: docker-compose.dev.yml:docker-compose.profiles.yml
- COMPOSE_PROFILES: temporal,azure
run: |
- bin/ci-wait-for-docker launch --background --down
+ bin/ci-wait-for-docker launch --background --down db redis7 clickhouse
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
@@ -630,15 +631,6 @@ jobs:
- name: Install sqlx-cli
uses: ./.github/actions/setup-sqlx-cli
- - name: Preserve CI Docker helper during rollout
- run: |
- # Temporary during rollout: this job checks out `master`,
- # which does not include the latest Docker wait helpers yet.
- cp bin/ci-wait-for-docker /tmp/ci-wait-for-docker
- chmod +x /tmp/ci-wait-for-docker
- cp bin/wait-for-docker /tmp/wait-for-docker
- chmod +x /tmp/wait-for-docker
-
# First running migrations from master, to simulate the real-world scenario
- name: Checkout master
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -646,15 +638,6 @@ jobs:
ref: master
clean: false
- - name: Restore CI Docker helper during rollout
- run: |
- # Temporary during rollout: restore the helpers after the
- # checkout to `master` removes them from the workspace.
- cp /tmp/ci-wait-for-docker bin/ci-wait-for-docker
- chmod +x bin/ci-wait-for-docker
- cp /tmp/wait-for-docker bin/wait-for-docker
- chmod +x bin/wait-for-docker
-
- name: Install python dependencies for master
run: |
UV_PROJECT_ENVIRONMENT=.venv-master uv sync --frozen --dev
@@ -662,8 +645,7 @@ jobs:
- name: Wait for Docker services
env:
COMPOSE_FILE: docker-compose.dev.yml:docker-compose.profiles.yml
- COMPOSE_PROFILES: temporal,azure
- run: bin/ci-wait-for-docker wait
+ run: bin/ci-wait-for-docker wait --only db redis7 clickhouse
- name: Run migrations up to master
run: |
@@ -675,29 +657,15 @@ jobs:
# DATABASE_URL="postgres://posthog:posthog@localhost:5432/posthog_persons" \
# sqlx migrate run --source rust/persons_migrations/
- # Get app token early so it can be passed to checkout below.
- # This sets the git extraheader to the app token instead of GITHUB_TOKEN,
- # which is required for the OpenAPI type commit push to trigger CI.
- - name: Get app token for OpenAPI type commits
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog'
- id: openapi-app-token
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
- with:
- client-id: ${{ secrets.GH_APP_POSTHOG_TESTS_APP_ID }}
- private-key: ${{ secrets.GH_APP_POSTHOG_TESTS_PRIVATE_KEY }}
-
# Now we can consider this PR's migrations
- name: Checkout this PR
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# For same-repo PRs, checkout the actual branch (not the merge commit)
- # so OpenAPI type generation can be committed directly. Fork PRs fall
- # back to the default merge commit (auto-commit bails out for forks).
+ # so origin/master..HEAD reflects PR files. Fork PRs fall back
+ # to the default merge commit.
ref: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') && github.event.pull_request.head.ref || github.ref }}
clean: false
- # Use app token so the git extraheader is set correctly for the OpenAPI
- # type commit push later — GITHUB_TOKEN pushes don't trigger CI.
- token: ${{ steps.openapi-app-token.outputs.token || github.token }}
- name: Install python dependencies for this PR
run: |
@@ -1151,6 +1119,61 @@ jobs:
});
}
+ check-openapi-types:
+ needs: [changes]
+ if: needs.changes.outputs.backend == 'true' || needs.changes.outputs.openapi_types == 'true'
+ timeout-minutes: 20
+ permissions:
+ contents: read
+
+ name: Validate OpenAPI types
+ runs-on: depot-ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ # For same-repo PRs, checkout the actual branch (not the merge commit)
+ # so generated OpenAPI types can be committed directly. Fork PRs fall
+ # back to the default merge commit (auto-commit bails out for forks).
+ ref: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') && github.event.pull_request.head.ref || github.ref }}
+ clean: false
+
+ - name: Clean up data directories with container permissions
+ run: |
+ # Use docker to clean up files created by containers
+ [ -d "data" ] && docker run --rm -v "$(pwd)/data:/data" alpine sh -c "rm -rf /data/seaweedfs /data/minio" || true
+ continue-on-error: true
+
+ - name: Stop/Start stack with Docker Compose
+ env:
+ COMPOSE_FILE: docker-compose.dev.yml:docker-compose.profiles.yml
+ run: |
+ bin/ci-wait-for-docker launch --background --down db clickhouse
+
+ - name: Set up Python
+ uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
+ with:
+ python-version: 3.12.12
+
+ - name: Install uv
+ id: setup-uv
+ uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
+ with:
+ version: '0.10.2' # pinned: unpinned setup-uv calls GH API on every job, exhausts rate limit
+ enable-cache: true
+ cache-dependency-glob: uv.lock
+ save-cache: ${{ github.ref == 'refs/heads/master' }}
+
+ - name: Install SAML (python3-saml) dependencies
+ if: steps.setup-uv.outputs.cache-hit != 'true'
+ run: |
+ sudo apt-get update
+ sudo apt-get install libxml2-dev libxmlsec1-dev libxmlsec1-openssl
+
+ - name: Install python dependencies
+ run: |
+ UV_PROJECT_ENVIRONMENT=$pythonLocation uv sync --frozen --dev
+
- name: Install pnpm
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
@@ -1173,6 +1196,11 @@ jobs:
npm_config_fetch_retry_maxtimeout: 60000
run: pnpm --filter=@posthog/root --filter=@posthog/frontend... --filter=@posthog/mcp... install --frozen-lockfile
+ - name: Wait for Docker services
+ env:
+ COMPOSE_FILE: docker-compose.dev.yml:docker-compose.profiles.yml
+ run: bin/ci-wait-for-docker wait --only db clickhouse
+
- name: Add OpenAPI Problem Matcher
run: echo "::add-matcher::.github/openapi-problem-matcher.json"
@@ -1183,8 +1211,6 @@ jobs:
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
BRANCH: ${{ github.event.pull_request.head.ref }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
- PR_NUMBER: ${{ github.event.pull_request.number }}
- GH_TOKEN: ${{ steps.openapi-app-token.outputs.token }}
run: |
if ! ./bin/hogli build:openapi; then
echo ""
@@ -1250,11 +1276,23 @@ jobs:
exit 1
fi
- # Disable auto-merge before pushing to prevent unreviewed code from merging
- gh pr merge --disable-auto "$PR_NUMBER" || echo "Auto-merge was not enabled"
-
echo "needs-commit=true" >> $GITHUB_OUTPUT
+ - name: Get app token for OpenAPI type commits
+ if: steps.openapi-check.outputs.needs-commit == 'true'
+ id: openapi-app-token
+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
+ with:
+ client-id: ${{ secrets.GH_APP_POSTHOG_TESTS_APP_ID }}
+ private-key: ${{ secrets.GH_APP_POSTHOG_TESTS_PRIVATE_KEY }}
+
+ - name: Disable auto-merge before OpenAPI type commit
+ if: steps.openapi-check.outputs.needs-commit == 'true'
+ env:
+ GH_TOKEN: ${{ steps.openapi-app-token.outputs.token }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ run: gh pr merge --disable-auto "$PR_NUMBER" || echo "Auto-merge was not enabled"
+
- name: Commit OpenAPI types via GitHub API (signed)
if: steps.openapi-check.outputs.needs-commit == 'true'
uses: planetscale/ghcommit-action@25309d8005ac7c3bcd61d3fe19b69e0fe47dbdde # v0.2.20
@@ -1894,7 +1932,17 @@ jobs:
# Job just to collate the status of the matrix jobs for requiring passing status
# Must depend on handle-snapshots to prevent auto-merge before commits complete
django_tests:
- needs: [django, check-migrations, async-migrations, turbo-discover, turbo-tests, handle-snapshots, repo-checks]
+ needs:
+ [
+ django,
+ check-migrations,
+ check-openapi-types,
+ async-migrations,
+ turbo-discover,
+ turbo-tests,
+ handle-snapshots,
+ repo-checks,
+ ]
name: Django Tests Pass
runs-on: ubuntu-latest
timeout-minutes: 5
@@ -1915,6 +1963,12 @@ jobs:
exit 1
fi
+ # Check OpenAPI type validation - must pass for Django Tests to be green
+ if [[ "${{ needs.check-openapi-types.result }}" != "success" && "${{ needs.check-openapi-types.result }}" != "skipped" ]]; then
+ echo "OpenAPI type checks failed."
+ exit 1
+ fi
+
# Check async migrations - must pass for Django Tests to be green
if [[ "${{ needs.async-migrations.result }}" != "success" && "${{ needs.async-migrations.result }}" != "skipped" ]]; then
echo "Async migrations tests failed."