: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(ci): skip unchanged python schema generation (#126832)
posthog[bot]fb73adcc9626
diff --git a/.depot/actions/paths-filter/__tests__/python-schema.test.ts b/.depot/actions/paths-filter/__tests__/python-schema.test.tsnew file mode 100644index 000000000000..d3d23691a50a--- /dev/null+++ b/.depot/actions/paths-filter/__tests__/python-schema.test.ts@@ -0,0 +1,49 @@+import {readFileSync} from 'fs'+import * as path from 'path'+import * as yaml from 'js-yaml'+import {ChangeStatus} from '../src/file'+import {Filter} from '../src/filter'++const workflow = yaml.load(+ readFileSync(path.join(__dirname, '../../../../.github/workflows/ci-python.yml'), 'utf8')+) as {jobs: {changes: {steps: {id?: string; with?: {filters?: string}}[]}}}+const filter = new Filter(workflow.jobs.changes.steps.find(step => step.id === 'filter')!.with!.filters!)++const inputs = [+ 'frontend/src/queries/schema.json',+ 'posthog/schema.py',+ 'posthog/schema_enums.py',+ 'bin/build-schema-python.sh',+ 'bin/patch-schema-array-discriminators.py',+ 'bin/patch-schema-property-filter-discriminator.py',+ 'bin/split-schema-enums.py',+ 'pyproject.toml',+ 'tools/hogli/pyproject.toml',+ 'ruff.toml',+ '.ruff.toml',+ 'posthog/ruff.toml',+ 'posthog/.ruff.toml',+ 'uv.lock',+ '.github/actions/paths-filter/src/filter.ts',+ '.github/workflows/ci-python.yml'+]++test.each([ChangeStatus.Added, ChangeStatus.Modified, ChangeStatus.Deleted])(+ 'Python schema %s inputs reach both the job and generation check',+ status => {+ const files = inputs.map(filename => ({filename, status}))+ const result = filter.match(files)+ expect(result.schema_python).toEqual(files)+ expect(result.python).toEqual(files)+ }+)++test('unrelated Python changes run Python checks without schema generation', () => {+ const files = ['posthog/api/test/test_insight.py', 'pnpm-lock.yaml', 'package.json'].map(filename => ({+ filename,+ status: ChangeStatus.Modified+ }))+ const result = filter.match(files)+ expect(result.python).toEqual([files[0]])+ expect(result.schema_python).toEqual([])+})diff --git a/.github/actions/paths-filter/__tests__/python-schema.test.ts b/.github/actions/paths-filter/__tests__/python-schema.test.tsnew file mode 100644index 000000000000..d3d23691a50a--- /dev/null+++ b/.github/actions/paths-filter/__tests__/python-schema.test.ts@@ -0,0 +1,49 @@+import {readFileSync} from 'fs'+import * as path from 'path'+import * as yaml from 'js-yaml'+import {ChangeStatus} from '../src/file'+import {Filter} from '../src/filter'++const workflow = yaml.load(+ readFileSync(path.join(__dirname, '../../../../.github/workflows/ci-python.yml'), 'utf8')+) as {jobs: {changes: {steps: {id?: string; with?: {filters?: string}}[]}}}+const filter = new Filter(workflow.jobs.changes.steps.find(step => step.id === 'filter')!.with!.filters!)++const inputs = [+ 'frontend/src/queries/schema.json',+ 'posthog/schema.py',+ 'posthog/schema_enums.py',+ 'bin/build-schema-python.sh',+ 'bin/patch-schema-array-discriminators.py',+ 'bin/patch-schema-property-filter-discriminator.py',+ 'bin/split-schema-enums.py',+ 'pyproject.toml',+ 'tools/hogli/pyproject.toml',+ 'ruff.toml',+ '.ruff.toml',+ 'posthog/ruff.toml',+ 'posthog/.ruff.toml',+ 'uv.lock',+ '.github/actions/paths-filter/src/filter.ts',+ '.github/workflows/ci-python.yml'+]++test.each([ChangeStatus.Added, ChangeStatus.Modified, ChangeStatus.Deleted])(+ 'Python schema %s inputs reach both the job and generation check',+ status => {+ const files = inputs.map(filename => ({filename, status}))+ const result = filter.match(files)+ expect(result.schema_python).toEqual(files)+ expect(result.python).toEqual(files)+ }+)++test('unrelated Python changes run Python checks without schema generation', () => {+ const files = ['posthog/api/test/test_insight.py', 'pnpm-lock.yaml', 'package.json'].map(filename => ({+ filename,+ status: ChangeStatus.Modified+ }))+ const result = filter.match(files)+ expect(result.python).toEqual([files[0]])+ expect(result.schema_python).toEqual([])+})diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.ymlindex dcc58ed777b7..289b4386987f 100644--- a/.github/workflows/ci-python.yml+++ b/.github/workflows/ci-python.yml@@ -69,6 +69,7 @@ jobs:bin_scripts: ${{ steps.filter.outputs.bin_scripts || 'true' }}api_ratchet: ${{ steps.filter.outputs.api_ratchet || 'true' }}mypy_cache_key: ${{ steps.filter.outputs.mypy_cache_key || 'false' }}+ schema_python: ${{ steps.filter.outputs.schema_python || 'true' }}steps:# For pull requests it's not necessary to checkout the code, but we# also want this to run on master so we need to checkout@@ -110,6 +111,20 @@ jobs:- 'uv.lock'- '**/pyproject.toml'- '**/mypy.ini'+ schema_python:+ - 'frontend/src/queries/schema.json'+ - 'posthog/schema.py'+ - 'posthog/schema_enums.py'+ - 'bin/build-schema-python.sh'+ - 'bin/patch-schema-array-discriminators.py'+ - 'bin/patch-schema-property-filter-discriminator.py'+ - 'bin/split-schema-enums.py'+ - '**/pyproject.toml'+ - '**/ruff.toml'+ - '**/.ruff.toml'+ - 'uv.lock'+ - '.github/actions/paths-filter/**'+ - '.github/workflows/ci-python.yml'python:# ruff/mypy/ty run repo-wide (`.`) in code-quality, so any Python# file anywhere must trigger this workflow — otherwise an unformatted@@ -117,12 +132,16 @@ jobs:- '**/*.py'- '*.py' # root-level scripts (e.g. manage.py); '**/' alone may not match root- 'pyproject.toml'+ - '**/pyproject.toml'+ - '**/ruff.toml'+ - '**/.ruff.toml'- 'uv.lock'- 'posthog/**/*'# Make sure we run if someone is explicitly change the workflows- .github/workflows/ci-python.yml- .github/workflows/ci-dagster.yml- .github/actions/setup-uv/**+ - '.github/actions/paths-filter/**'- .depot/actions/setup-uv/**- '.depot/workflows/*.yml'- .flox/env/manifest.toml@@ -369,9 +388,10 @@ jobs:key: ${{ steps.mypy-cache.outputs.cache-primary-key }}- name: Check if "schema.py" is up to date+ if: github.event_name != 'pull_request' || startsWith(github.head_ref, 'trunk-merge/') || needs.changes.outputs.schema_python != 'false'shell: bashrun: |- npm run schema:build:python && git diff --exit-code+ bash bin/build-schema-python.sh && git diff --exit-code# Every projection renderer is Python, so this job needs neither pnpm nor# node_modules. Keep the step after "Install Python dependencies": the taxonomydiff --git a/docs/published/handbook/engineering/type-system.md b/docs/published/handbook/engineering/type-system.mdindex d630705ab7c9..1057ce4999c7 100644--- a/docs/published/handbook/engineering/type-system.md+++ b/docs/published/handbook/engineering/type-system.md@@ -176,6 +176,8 @@ This runs:1. `build:schema-json` – TS → JSON Schema2. `build:schema-python` – JSON Schema → Pydantic+Python CI regenerates the Pydantic models on pull requests that change the JSON schema, generator scripts, generated outputs, or tool configuration and dependencies. Unrelated pull requests skip this generation check. Hourly and merge-queue runs always regenerate the models, as do runs with unavailable filter outputs.+### When to add types hereAdd to `schema.ts` when you need a type that:diff --git a/tools/workflow-plan/tests/workflows.test.ts b/tools/workflow-plan/tests/workflows.test.tsindex 00862ecd2bb8..975b7b7b15b5 100644--- a/tools/workflow-plan/tests/workflows.test.ts+++ b/tools/workflow-plan/tests/workflows.test.ts@@ -993,6 +993,27 @@ describe('CI workflow run plans', () => {expect(evaluateValue(step?.env?.RUN_JSON_TARGETS, { github }, functions)).toBe(runs)})+ it.each([+ ['unrelated PR', pullRequest(), 'false', false],+ ['schema PR', pullRequest(), 'true', true],+ ['missing filter output', pullRequest(), '', true],+ ['unrelated fork PR', pullRequest({ fork: true }), 'false', false],+ ['schema fork PR', pullRequest({ fork: true }), 'true', true],+ ['merge queue', mergeQueue(), 'false', true],+ ['hourly schedule', schedule(), 'false', true],+ ] as const)('Python schema generation on %s', (name, github, schema, runs) => {+ const wf = workflow('ci-python.yml')+ const plan = planWorkflow(wf, {+ name,+ github,+ steps: { changes: { filter: { outputs: { python: 'true', schema_python: schema } } } },+ })+ expect(plan.errors).toEqual([])+ expect(+ plan.jobs['code-quality']?.steps.find((step) => step.name === 'Check if "schema.py" is up to date')?.runs+ ).toBe(runs)+ })+it.each([['master schedule', schedule(), 'success', true],['same-repo PR', pullRequest(), 'success', false],