: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(mobile): narrow CI for generated API type changes (#125808)
Chris Volzer4ca7279dd9d7
diff --git a/.github/workflows/mobile-ci.yml b/.github/workflows/mobile-ci.ymlindex 63dc81d3b9ff..8370adb85d73 100644--- a/.github/workflows/mobile-ci.yml+++ b/.github/workflows/mobile-ci.yml@@ -5,8 +5,8 @@ name: Mobile CI# installs the repo root workspace.## "Mobile CI Pass" reports on every pull request so repository rules can require it.-# PR housekeeping calls this workflow on each PR event, and the changes job turns-# the run into a no-op when the diff does not touch the app. A trigger-level+# PR housekeeping calls this workflow on each PR event. Change detection skips+# validation when neither the app nor its imported API types changed. A trigger-level# paths filter would leave unrelated PRs waiting for a status that never arrives.on:@@ -20,8 +20,6 @@ on:paths:- 'products/mobile/**'- '!products/mobile/**/*.md'- - 'products/signals/frontend/generated/api.schemas.ts'- - 'products/error_tracking/frontend/generated/api.schemas.ts'- '.github/workflows/mobile-ci.yml'concurrency:@@ -45,6 +43,7 @@ jobs:# A push has no PR diff to filter: a master push already matched the# trigger paths, and the release caller validates its exact commit.mobile: ${{ steps.filter.outputs.mobile || 'true' }}+ api_types: ${{ steps.filter.outputs.api_types || 'false' }}steps:- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2with:@@ -67,20 +66,24 @@ jobs:mobile:- 'products/mobile/**'- '!products/mobile/**/*.md'+ - '.github/workflows/mobile-ci.yml'+ api_types:- 'products/signals/frontend/generated/api.schemas.ts'- 'products/error_tracking/frontend/generated/api.schemas.ts'- - '.github/workflows/mobile-ci.yml'check:- name: Typecheck, lint and test+ name: Check mobileneeds: changes- if: needs.changes.outputs.mobile == 'true'+ if: needs.changes.outputs.mobile == 'true' || needs.changes.outputs.api_types == 'true'runs-on: depot-ubuntu-24.04timeout-minutes: 15env:# Reusable workflows keep the caller's name. Only the direct master# trigger warms the cache; release callers must validate their commit.MOBILE_RUN_CHECKS: ${{ github.event_name != 'push' || github.workflow != 'Mobile CI' }}+ # The generated API files are type-only imports, so their changes need+ # typechecking but cannot affect mobile lint, runtime or release policy.+ MOBILE_RUN_FULL_CHECKS: ${{ needs.changes.outputs.mobile == 'true' && (github.event_name != 'push' || github.workflow != 'Mobile CI') }}defaults:run:working-directory: products/mobile@@ -146,29 +149,29 @@ jobs:run: pnpm typecheck- name: Lint- if: env.MOBILE_RUN_CHECKS == 'true'+ if: env.MOBILE_RUN_FULL_CHECKS == 'true'run: pnpm lint- name: Test- if: env.MOBILE_RUN_CHECKS == 'true'+ if: env.MOBILE_RUN_FULL_CHECKS == 'true'run: pnpm test --ci# Workflow changes also reach branches that have not rebased onto the# release tooling yet. Those branches still run the existing checks.- name: Fetch release validation base- if: env.MOBILE_RUN_CHECKS == 'true' && hashFiles('products/mobile/scripts/releases/release.mjs') != '' && (github.event.pull_request.base.sha != '' || github.event.before != '')+ if: env.MOBILE_RUN_FULL_CHECKS == 'true' && hashFiles('products/mobile/scripts/releases/release.mjs') != '' && (github.event.pull_request.base.sha != '' || github.event.before != '')env:MOBILE_RELEASE_BASE: ${{ github.event.pull_request.base.sha || github.event.before }}run: git fetch --no-tags --depth=1 --filter=blob:none origin "$MOBILE_RELEASE_BASE"- name: Validate release requests- if: env.MOBILE_RUN_CHECKS == 'true' && hashFiles('products/mobile/scripts/releases/release.mjs') != ''+ if: env.MOBILE_RUN_FULL_CHECKS == 'true' && hashFiles('products/mobile/scripts/releases/release.mjs') != ''env:MOBILE_RELEASE_BASE: ${{ github.event.pull_request.base.sha || github.event.before }}run: pnpm release:check- name: Test release policy- if: env.MOBILE_RUN_CHECKS == 'true' && hashFiles('products/mobile/scripts/releases/release.mjs') != ''+ if: env.MOBILE_RUN_FULL_CHECKS == 'true' && hashFiles('products/mobile/scripts/releases/release.mjs') != ''run: pnpm release:testmobile_checks:@@ -186,7 +189,7 @@ jobs:exit 1fi- if [[ "${{ needs.changes.outputs.mobile }}" != "true" ]]; then+ if [[ "${{ needs.changes.outputs.mobile }}" != "true" && "${{ needs.changes.outputs.api_types }}" != "true" ]]; thenecho "Mobile checks were skipped (no relevant changes)"exit 0fidiff --git a/products/mobile/docs/CI.md b/products/mobile/docs/CI.mdindex a7ff0287c22f..6c51514c7378 100644--- a/products/mobile/docs/CI.md+++ b/products/mobile/docs/CI.md@@ -7,11 +7,20 @@ Three GitHub Actions workflows cover the app. They install the independent `prod`.github/workflows/mobile-ci.yml` is a reusable workflow. `pr-housekeeping.yml` calls it on every pull request, and `mobile-release.yml` calls it for each release commit.Direct pushes to `master` that match the workflow's paths only install dependencies and warm the pnpm store cache. They do not repeat validation.-A `changes` job reads the pull request diff. When nothing under `products/mobile/**` (Markdown excluded), the generated Signals API types, or the workflow changed, the check job is skipped and the run ends in seconds.+A `changes` job reads the pull request diff and selects the mobile checks.++| Changed files | Mobile checks |+| --------------------------------------------------------------------- | ---------------------------------------- |+| `products/mobile/**` (Markdown excluded) or `mobile-ci.yml` | Typecheck, lint, Jest and release checks |+| Generated Signals or Error Tracking API types, with no mobile changes | Typecheck |+| Neither group | Status report only |++The generated API files are type-only imports in the app, so typechecking checks compatibility without repeating runtime tests.+Changes in both groups run the full suite. Release commits also run the full suite.The `Mobile CI Pass` job reports a verdict on every run, so it can be a required branch-protection check.A trigger-level `paths:` filter cannot do this: a required check that never dispatches leaves the pull request waiting for a status that never arrives. See `/authoring-ci-workflows`.-The check job runs these steps for pull requests and release commits, using the same commands you run locally:+The full check job runs these steps, using the same commands you run locally:```shpnpm install --frozen-lockfile@@ -34,10 +43,11 @@ Markdown, MDX, SCSS and YAML use the repository's Oxfmt configuration. The shareDetails:-- The checkout includes the mobile app and its existing generated Signals API types. Keep new runtime dependencies inside the mobile workspace.+- The checkout includes the mobile app and its imported generated Signals and Error Tracking API types. Keep new runtime dependencies inside the mobile workspace.- pnpm comes from `packageManager` in `products/mobile/package.json`, not from the repo root.- Node comes from `products/mobile/.node-version`. Keep it equal to the repo's `.nvmrc` and to `node` in `eas.json`.- The pnpm store cache is keyed on `products/mobile/pnpm-lock.yaml`. Pull requests only restore it. Pushes to `master` save it.+- Generated API type changes do not trigger a separate cache-warming run on `master`; they do not change the mobile dependencies.- Change detection uses the existing paths-filter GitHub App. Both reusable-workflow callers pass `GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY` by name. The workflow creates a token with pull-request read access only for same-repository PRs; fork and Dependabot PRs use `GITHUB_TOKEN` because they do not receive the app secret. No credential value belongs in the repository.- A newer push to the same pull request cancels the older run.- Push runs use a separate concurrency group for each commit, so a later release cannot replace an earlier pending validation run. Publication stays serialized; see [release ordering and retries](RELEASING.md#receipts-ordering-and-retries).diff --git a/tools/workflow-plan/tests/workflows.test.ts b/tools/workflow-plan/tests/workflows.test.tsindex c85106ffa550..7d428866e111 100644--- a/tools/workflow-plan/tests/workflows.test.ts+++ b/tools/workflow-plan/tests/workflows.test.ts@@ -1,5 +1,6 @@// These tests check the CI workflows, not the planner. A failure here means a// job condition in a workflow file changed what runs; the planner itself is covered by plan.test.ts.+import { spawnSync } from 'node:child_process'import { readdirSync } from 'node:fs'import path from 'node:path'import { describe, expect, it } from 'vitest'@@ -562,12 +563,21 @@ const namedJobs = (file: string): Set<string> =>describe('CI workflow run plans', () => {it.each([- { name: 'mobile PR', github: pullRequest(), mobile: true, validate: true, install: true, appToken: true },+ {+ name: 'mobile PR',+ github: pullRequest(),+ mobile: true,+ apiTypes: false,+ checks: 'full',+ install: true,+ appToken: true,+ },{name: 'fork PR',github: pullRequest({ fork: true }),mobile: true,- validate: true,+ apiTypes: false,+ checks: 'full',install: true,appToken: false,},@@ -575,16 +585,44 @@ describe('CI workflow run plans', () => {name: 'Dependabot PR',github: { ...pullRequest(), actor: 'dependabot[bot]' },mobile: true,- validate: true,+ apiTypes: false,+ checks: 'full',install: true,appToken: false,},- { name: 'unrelated PR', github: pullRequest(), mobile: false, validate: false, install: false, appToken: true },+ {+ name: 'API types only',+ github: pullRequest(),+ mobile: false,+ apiTypes: true,+ checks: 'typecheck',+ install: true,+ appToken: true,+ },+ {+ name: 'mobile and API types',+ github: pullRequest(),+ mobile: true,+ apiTypes: true,+ checks: 'full',+ install: true,+ appToken: true,+ },+ {+ name: 'unrelated PR',+ github: pullRequest(),+ mobile: false,+ apiTypes: false,+ checks: 'none',+ install: false,+ appToken: true,+ },{name: 'master cache warmer',github: { ...push(), workflow: workflow('mobile-ci.yml').name! },mobile: true,- validate: false,+ apiTypes: false,+ checks: 'none',install: true,appToken: false,},@@ -592,15 +630,16 @@ describe('CI workflow run plans', () => {name: 'release checks',github: { ...push(), workflow: 'Mobile Release' },mobile: true,- validate: true,+ apiTypes: false,+ checks: 'full',install: true,appToken: false,},- ])('mobile CI on $name', ({ name, github, mobile, validate, install, appToken }) => {+ ])('mobile CI on $name', ({ name, github, mobile, apiTypes, checks, install, appToken }) => {const plan = planWorkflow(workflow('mobile-ci.yml'), {name,github,- steps: { changes: { filter: pathsFilter({ mobile }) } },+ steps: { changes: { filter: pathsFilter({ mobile, api_types: apiTypes }) } },})const validationSteps = ['Typecheck',@@ -617,7 +656,31 @@ describe('CI workflow run plans', () => {plan.jobs.check?.steps.filter((step) => step.runs && validationSteps.includes(step.name ?? '')).map((step) => step.name)- ).toEqual(validate ? validationSteps : [])+ ).toEqual(checks === 'full' ? validationSteps : checks === 'typecheck' ? ['Typecheck'] : [])+ })++ it.each([+ { result: 'success', exitCode: 0 },+ { result: 'failure', exitCode: 1 },+ { result: 'cancelled', exitCode: 1 },+ ])('mobile gate reports an API-only typecheck $result', ({ result, exitCode }) => {+ const script = evaluateValue(+ workflow('mobile-ci.yml').jobs.mobile_checks?.steps?.[0]?.run,+ {+ needs: {+ changes: { result: 'success', outputs: { mobile: 'false', api_types: 'true' } },+ check: { result },+ },+ },+ planFunctions({+ dependenciesSucceeded: result === 'success',+ dependenciesFailed: result === 'failure',+ cancelled: false,+ })+ )+ const gate = spawnSync('bash', ['-eu', '-c', String(script)], { encoding: 'utf8' })+ expect(gate.error).toBeUndefined()+ expect(gate.status, gate.stderr || gate.stdout).toBe(exitCode)})it.each([