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): build frontend Docker image in merge queue (#116402)

Paul D'Ambra0224d46f77f6
diff --git a/.depot/actions/paths-filter/__tests__/filter.test.ts b/.depot/actions/paths-filter/__tests__/filter.test.ts
index aac9d8e14c47..69851880d3d6 100644
--- a/.depot/actions/paths-filter/__tests__/filter.test.ts
+++ b/.depot/actions/paths-filter/__tests__/filter.test.ts
@@ -32,6 +32,32 @@ describe('yaml filter parsing tests', () => {
})
describe('matching tests', () => {
+ test('builds the Docker image when frontend source changes', () => {
+ const workflowYaml = readFileSync(
+ path.join(__dirname, '../../../../.github/workflows/container-images-ci.yml'),
+ 'utf8'
+ )
+ const workflow = jsyaml.load(workflowYaml) as {jobs: {changes: {steps: {id?: string; with?: {filters?: string}}[]}}}
+ const filtersYaml = workflow.jobs.changes.steps.find(step => step.id === 'filter')?.with?.filters
+ const files = modified([
+ 'products/posthog_ai/frontend/logics/runStreamLogic.ts',
+ 'products/cdp/frontend/emptyState/WebScriptPreview.scss',
+ 'products/cdp/frontend/emptyState/preview.svg',
+ 'packages/agent/packages/agent-contracts/src/acp-conversation.ts',
+ 'bin/turbo',
+ 'patches/[email protected]',
+ 'frontend/src/logics/example.test.ts',
+ 'frontend/src/logics/example.spec.tsx',
+ 'products/cdp/frontend/emptyState/WebScriptPreview.stories.tsx',
+ 'products/cdp/frontend/emptyState/WebScriptPreview.test.tsx',
+ 'products/cdp/frontend/emptyState/WebScriptPreview.spec.tsx',
+ 'products/desktop/src/App.tsx',
+ 'posthog/api/example.py'
+ ])
+
+ expect(new Filter(filtersYaml).match(files).build_inputs).toEqual(files.slice(0, 6))
+ })
+
test('runs frontend consumer tests when replay-shared source changes', () => {
const workflowYaml = readFileSync(path.join(__dirname, '../../../../.github/workflows/ci-frontend.yml'), 'utf8')
const workflow = jsyaml.load(workflowYaml) as {jobs: {changes: {steps: {id?: string; with?: {filters?: string}}[]}}}
diff --git a/.github/actions/paths-filter/__tests__/filter.test.ts b/.github/actions/paths-filter/__tests__/filter.test.ts
index aac9d8e14c47..69851880d3d6 100644
--- a/.github/actions/paths-filter/__tests__/filter.test.ts
+++ b/.github/actions/paths-filter/__tests__/filter.test.ts
@@ -32,6 +32,32 @@ describe('yaml filter parsing tests', () => {
})
describe('matching tests', () => {
+ test('builds the Docker image when frontend source changes', () => {
+ const workflowYaml = readFileSync(
+ path.join(__dirname, '../../../../.github/workflows/container-images-ci.yml'),
+ 'utf8'
+ )
+ const workflow = jsyaml.load(workflowYaml) as {jobs: {changes: {steps: {id?: string; with?: {filters?: string}}[]}}}
+ const filtersYaml = workflow.jobs.changes.steps.find(step => step.id === 'filter')?.with?.filters
+ const files = modified([
+ 'products/posthog_ai/frontend/logics/runStreamLogic.ts',
+ 'products/cdp/frontend/emptyState/WebScriptPreview.scss',
+ 'products/cdp/frontend/emptyState/preview.svg',
+ 'packages/agent/packages/agent-contracts/src/acp-conversation.ts',
+ 'bin/turbo',
+ 'patches/[email protected]',
+ 'frontend/src/logics/example.test.ts',
+ 'frontend/src/logics/example.spec.tsx',
+ 'products/cdp/frontend/emptyState/WebScriptPreview.stories.tsx',
+ 'products/cdp/frontend/emptyState/WebScriptPreview.test.tsx',
+ 'products/cdp/frontend/emptyState/WebScriptPreview.spec.tsx',
+ 'products/desktop/src/App.tsx',
+ 'posthog/api/example.py'
+ ])
+
+ expect(new Filter(filtersYaml).match(files).build_inputs).toEqual(files.slice(0, 6))
+ })
+
test('runs frontend consumer tests when replay-shared source changes', () => {
const workflowYaml = readFileSync(path.join(__dirname, '../../../../.github/workflows/ci-frontend.yml'), 'utf8')
const workflow = jsyaml.load(workflowYaml) as {jobs: {changes: {steps: {id?: string; with?: {filters?: string}}[]}}}
diff --git a/.github/workflows/container-images-ci.yml b/.github/workflows/container-images-ci.yml
index ecf6d998eb37..8d5cd7a7f462 100644
--- a/.github/workflows/container-images-ci.yml
+++ b/.github/workflows/container-images-ci.yml
@@ -20,14 +20,12 @@ jobs:
contents: read
pull-requests: read
outputs:
- # The image is only consumed by ci-hobby.yml. Skip the long image build
- # when ci-hobby would also skip, plus on changes to inputs that can
- # only break inside the Docker build (workflow self-edits, frontend
- # lockfile bumps that ci-hobby's filter ignores).
+ # Build for Hobby on PRs. In the merge queue, also check inputs that
+ # can break inside the Docker build, including frontend source.
should_build: >-
${{
steps.filter.outputs.hobby == 'true'
- || steps.filter.outputs.build_inputs == 'true'
+ || (startsWith(github.head_ref, 'trunk-merge/') && steps.filter.outputs.build_inputs == 'true')
|| contains(github.event.pull_request.labels.*.name, 'hobby-preview')
}}
dockerignore_changed: ${{ steps.filter.outputs.dockerignore }}
@@ -79,12 +77,10 @@ jobs:
- uv.lock
- .github/workflows/ci-hobby.yml
# Inputs that can break inside the Docker build but aren't covered
- # by the `hobby:` filter — workflow self-edits, `.dockerignore`
- # (silently changes the build context), and `pnpm-lock.yaml` so
- # Renovate-style dep bumps are exercised on PR (otherwise they'd
- # only fail after merging). Root `package.json` carries the
- # `packageManager` pin the image seeds corepack from, and a pin-only
- # edit leaves the lockfile untouched.
+ # by the `hobby:` filter. The merge queue checks these before
+ # merging. Root `package.json` carries the `packageManager` pin
+ # the image seeds corepack from, and a pin-only edit leaves the
+ # lockfile untouched.
build_inputs:
- .github/workflows/container-images-ci.yml
- .github/workflows/container-images-label-ci.yml
@@ -92,6 +88,31 @@ jobs:
- .dockerignore
- pnpm-lock.yaml
- package.json
+ - pnpm-workspace.yaml
+ - tsconfig.json
+ - turbo.json
+ - bin/turbo
+ - patches/**
+ - frontend/**
+ - products/**/frontend/**
+ - products/**/*.ts
+ - products/**/*.tsx
+ - products/**/*.json
+ - '!products/desktop/**'
+ - common/esbuilder/**
+ - common/hogvm/typescript/**
+ - common/replay-shared/**
+ - common/tailwind/**
+ - packages/quill/**
+ - packages/llm-normalizer/**
+ - packages/agent/packages/agent-contracts/src/**
+ - docs/onboarding/**
+ - '!products/**/*.test.*'
+ - '!products/**/*.spec.*'
+ - '!products/**/*.stories.*'
+ - '!frontend/src/**/*.test.*'
+ - '!frontend/src/**/*.spec.*'
+ - '!frontend/src/**/*.stories.*'
# Drives the fast PR-time guard below (models `COPY . .`, so it only reacts
# to .dockerignore — Dockerfile COPY changes are covered by the image boot check).
dockerignore:
@@ -147,15 +168,16 @@ jobs:
uses: ./.github/actions/build-n-cache-image
with:
actions-id-token-request-url: ${{ env.ACTIONS_ID_TOKEN_REQUEST_URL }}
- push-image: ${{ github.repository == 'PostHog/posthog' }} # Don't push on forks due to lack of credentials
+ push-image: ${{ !startsWith(github.head_ref, 'trunk-merge/') }}
# PR-only publish role: any branch, but can ONLY push to posthog-cloud-prs (not posthog-cloud).
aws-role-to-assume: ${{ vars.AWS_ECR_POSTHOG_PRS_PUBLISH_IAM_ROLE }}
dockerhub-username: ${{ secrets.DOCKERHUB_USER }}
dockerhub-password: ${{ secrets.DOCKERHUB_TOKEN }}
- pr-number: ${{ github.event.number }}
+ pr-number: ${{ !startsWith(github.head_ref, 'trunk-merge/') && github.event.number || '' }}
no-cache: ${{ contains(github.event.pull_request.labels.*.name, 'no-depot-docker-cache') }}
- name: Container image digest
+ if: ${{ !startsWith(github.head_ref, 'trunk-merge/') }}
env:
IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
IMAGE_REGISTRY: ${{ steps.build.outputs.registry }}
diff --git a/tools/workflow-plan/tests/workflows.test.ts b/tools/workflow-plan/tests/workflows.test.ts
index 9e9d13c786be..5d98485e2236 100644
--- a/tools/workflow-plan/tests/workflows.test.ts
+++ b/tools/workflow-plan/tests/workflows.test.ts
@@ -286,7 +286,12 @@ const EXPECTATIONS: Expectation[] = [
changes: { filter: pathsFilter({ backend: true, legacy: false }) },
'turbo-discover': {
discover: {
- outputs: { run_legacy: 'false', matrix: '[{"group":"a"}]', mode: '', selection: '{"json_targets_files":""}' },
+ outputs: {
+ run_legacy: 'false',
+ matrix: '[{"group":"a"}]',
+ mode: '',
+ selection: '{"json_targets_files":""}',
+ },
},
},
},
@@ -297,7 +302,15 @@ const EXPECTATIONS: Expectation[] = [
{ name: 'draft PR labeled no-ci', github: pullRequest({ draft: true, labels: ['no-ci'] }) },
{
runs: ['django_tests'],
- skipped: ['changes', 'django', 'turbo-tests', 'repo-checks', 'sdk-major-guard', 'check-migrations', 'dynamic-ci-filter'],
+ skipped: [
+ 'changes',
+ 'django',
+ 'turbo-tests',
+ 'repo-checks',
+ 'sdk-major-guard',
+ 'check-migrations',
+ 'dynamic-ci-filter',
+ ],
}
),
backend(
@@ -331,7 +344,14 @@ const EXPECTATIONS: Expectation[] = [
backend(
{ name: 'master push', github: push() },
{
- runs: ['changes', 'repo-checks', 'sdk-major-guard', 'check-migrations', 'mirror-schema-cache', 'django_tests'],
+ runs: [
+ 'changes',
+ 'repo-checks',
+ 'sdk-major-guard',
+ 'check-migrations',
+ 'mirror-schema-cache',
+ 'django_tests',
+ ],
skipped: [
'dynamic-ci-filter',
'detect-snapshot-mode',
@@ -650,6 +670,37 @@ describe('.github/workflows run plans', () => {
}
)
+ it.each([
+ ['frontend PR', pullRequest(), false, true, 'false', 'skipped', false],
+ ['frontend merge queue', mergeQueue(), false, true, 'true', 'success', false],
+ ['hobby PR', pullRequest(), true, false, 'true', 'success', true],
+ ['hobby merge queue', mergeQueue(), true, false, 'true', 'success', false],
+ ['unrelated merge queue', mergeQueue(), false, false, 'false', 'skipped', false],
+ ] as const)('Docker image build on %s', (name, github, hobby, buildInputs, shouldBuild, result, publish) => {
+ const wf = workflow('container-images-ci.yml')
+ const plan = planWorkflow(wf, {
+ name,
+ github,
+ steps: { changes: { filter: pathsFilter({ hobby, build_inputs: buildInputs }) } },
+ })
+ expect(plan.errors).toEqual([])
+ expect(plan.jobs.changes?.outputs.should_build).toBe(shouldBuild)
+ expect(plan.jobs.posthog_build?.result).toBe(result)
+ const build = wf.jobs.posthog_build?.steps?.find((step) => step.id === 'build')
+ if (result === 'success') {
+ const functions = planFunctions({
+ dependenciesSucceeded: true,
+ dependenciesFailed: false,
+ cancelled: false,
+ })
+ expect(evaluateValue(build?.with?.['push-image'], { github }, functions)).toBe(publish)
+ expect(evaluateValue(build?.with?.['pr-number'], { github }, functions)).toBe(publish ? 1 : '')
+ }
+ expect(plan.jobs.posthog_build?.steps.find((step) => step.name === 'Container image digest')?.runs).toBe(
+ result === 'success' && publish
+ )
+ })
+
it.each(PINNED_WORKFLOWS)('%s names every conditional job in an expectation row', (file) => {
const unnamed = Object.entries(workflow(file).jobs)
.filter(([id, job]) => job.if !== undefined && !namedJobs(file).has(id))