: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): offload hot setup-action calls and alert on mint failures (#77607)
Georges-Antoine Assi3283d40fe63e
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex 25e5aa28fa10..86a5e8bbe837 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -1258,6 +1258,8 @@ jobs:run: |# Same as above, except now for CH looking at files that were added in posthog/clickhouse/migrations/git diff --name-status origin/master..HEAD | grep "A\sposthog/clickhouse/migrations/" | grep -v README | awk '{print $2}' | python manage.py test_ch_migrations_are_safe+ # Shadow trial: canonical threads a setup-action app token into+ # pnpm-install; mint stripped here (secret not available on Depot).- name: Install package.json dependencies with pnpmuses: ./.depot/actions/pnpm-installwith:@@ -1675,6 +1677,10 @@ jobs:shell: bashrun: |UV_PROJECT_ENVIRONMENT=$pythonLocation uv sync --frozen --dev+ # Shadow trial: canonical precedes this with a setup-node step (.nvmrc,+ # threading a setup-action app token). The shadow has never mirrored that+ # step and runs npm on the runner's ambient Node, so the token threading+ # has nothing to mirror here.- name: Install canvas builder dependenciesif: ${{ needs.changes.outputs.backend == 'true' && matrix.segment == 'Core' }}shell: bashdiff --git a/.github/scripts/monitor-github-rate-limit.js b/.github/scripts/monitor-github-rate-limit.jsindex b27a6c810a57..2d15a498d164 100644--- a/.github/scripts/monitor-github-rate-limit.js+++ b/.github/scripts/monitor-github-rate-limit.js@@ -10,6 +10,7 @@const POSTHOG_HOST = 'https://us.i.posthog.com'const EVENT_NAME = 'github_rate_limit_observed'+const MINT_FAILURE_EVENT_NAME = 'github_app_token_mint_failed'const DEFAULT_SOURCE = 'github_token'async function captureEvent({ fetchImpl, posthogToken, event, distinctId, properties, timestamp }) {@@ -77,6 +78,53 @@ function buildProperties({ resource, snapshot, observedAt, observedAtSeconds, re}}+// Every App-token mint in the workflows is `continue-on-error`, and every+// consumer reads `steps.<mint>.outputs.token || github.token`. That combination+// degrades silently: a broken App credential leaves the run green while the+// bucket's entire call volume moves onto the shared per-repo GITHUB_TOKEN — a+// whole matrix's worth of stampede that only shows up downstream as an+// unexplained burn. Emitting the failure makes the fallback alertable.+async function reportMintFailures({ context, core }, { mints, now: _now, fetch: _fetch } = {}) {+ const posthogToken = process.env.POSTHOG_DEVEX_PROJECT_API_TOKEN+ if (!posthogToken) {+ core.warning('POSTHOG_DEVEX_PROJECT_API_TOKEN not set; nothing to emit')+ core.setOutput('mint_failures', '0')+ return []+ }++ const fetchImpl = _fetch || fetch+ const observedAt = (_now ? _now() : new Date()).toISOString()+ const repo = `${context.repo.owner}/${context.repo.repo}`+ // An App whose secrets aren't configured yet is a deliberate no-op, not a+ // failure — only a configured App that handed back no token is broken.+ const failed = (mints || []).filter((mint) => mint.configured && !mint.minted)++ for (const { source } of failed) {+ core.warning(`App token mint failed for ${source}; its callers fell back to the shared GITHUB_TOKEN bucket`)+ try {+ await captureEvent({+ fetchImpl,+ posthogToken,+ event: MINT_FAILURE_EVENT_NAME,+ distinctId: repo,+ properties: {+ repo,+ source,+ observed_at: observedAt,+ workflow_run_id: process.env.GITHUB_RUN_ID || null,+ },+ timestamp: observedAt,+ })+ } catch (err) {+ core.warning(`Failed to emit mint failure for ${source}: ${err.message}`)+ }+ }++ core.info(`${failed.length} App token mint failure(s)`)+ core.setOutput('mint_failures', String(failed.length))+ return failed.map(({ source }) => source)+}+module.exports = async ({ github, context, core }, { now: _now, fetch: _fetch, source: _source } = {}) => {const source = _source || DEFAULT_SOURCEconst fetchImpl = _fetch || fetch@@ -128,3 +176,4 @@ module.exports = async ({ github, context, core }, { now: _now, fetch: _fetch, smodule.exports.buildProperties = buildPropertiesmodule.exports.buildTrigger = buildTriggermodule.exports.captureEvent = captureEvent+module.exports.reportMintFailures = reportMintFailuresdiff --git a/.github/scripts/monitor-github-rate-limit.test.js b/.github/scripts/monitor-github-rate-limit.test.jsindex 94dced6001e8..5262409334e4 100644--- a/.github/scripts/monitor-github-rate-limit.test.js+++ b/.github/scripts/monitor-github-rate-limit.test.js@@ -191,6 +191,69 @@ describe('monitor-github-rate-limit', () => {})}+ // The `configured` flag is the whole reason this isn't just `!minted`: the+ // Apps are rolled out one org secret at a time, so an App with no secrets+ // yet reports exactly like one whose credential broke. Collapsing the two+ // would alert on every run until the last secret landed.+ for (const [configured, minted, expectedEmissions] of [+ [true, false, 1],+ [true, true, 0],+ [false, false, 0],+ ]) {+ it(`emits ${expectedEmissions} mint failure(s) when configured=${configured} minted=${minted}`, async () => {+ process.env.POSTHOG_DEVEX_PROJECT_API_TOKEN = 'devex-key'+ const captured = []+ const fetchMock = recordingFn((_url, opts) => {+ captured.push(JSON.parse(opts.body))+ return fetchOk()+ })+ const core = createCore()++ const failed = await monitor.reportMintFailures(+ { context, core },+ {+ mints: [{ source: 'posthog-setup-actions', configured, minted }],+ now: () => T_BASE,+ fetch: fetchMock,+ }+ )++ assert.equal(captured.length, expectedEmissions)+ assert.equal(failed.length, expectedEmissions)+ assert.ok(calledWith(core.setOutput, 'mint_failures', String(expectedEmissions)))+ })+ }++ it('names the broken bucket in the mint failure payload', async () => {+ process.env.POSTHOG_DEVEX_PROJECT_API_TOKEN = 'devex-key'+ const captured = []+ const fetchMock = recordingFn((_url, opts) => {+ captured.push(JSON.parse(opts.body))+ return fetchOk()+ })+ const core = createCore()++ await monitor.reportMintFailures(+ { context, core },+ {+ mints: [+ { source: 'posthog-tests', configured: true, minted: true },+ { source: 'posthog-paths-filter', configured: true, minted: false },+ ],+ now: () => T_BASE,+ fetch: fetchMock,+ }+ )++ assert.equal(captured.length, 1)+ assertMatch(captured[0], {+ api_key: 'devex-key',+ event: 'github_app_token_mint_failed',+ distinct_id: 'PostHog/posthog',+ properties: { repo: 'PostHog/posthog', source: 'posthog-paths-filter' },+ })+ })+it('skips emission when devex token is not configured', async () => {const fetchMock = recordingFn(fetchOk)const github = createGithubMock({ core: snapshot({ remaining: 1, limit: 15000 }) })diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 145a50828fa2..717df7faf0da 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -428,6 +428,11 @@ jobs:echo "migrations_key=posthog-schema-mig-${SCHEMA_CACHE_EPOCH}-${MIG_HASH}" >> $GITHUB_OUTPUTfi+ # Dedicated app: every "Mint setup-action GitHub token" step in this file+ # draws on posthog-devex-general rather than the posthog-setup-actions app+ # the other workflows share. Backend CI is the largest single consumer of+ # setup-action calls in the repo, enough to threaten a shared 15k/hr bucket+ # at merge peaks, so it gets one to itself.- name: Mint setup-action GitHub tokenid: setup-gh-tokenif: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository@@ -2035,6 +2040,7 @@ jobs:uses: ./.github/actions/pnpm-installwith:install-command: pnpm --filter=@posthog/root --filter=@posthog/frontend... --filter=@posthog/mcp... install --frozen-lockfile+ token: ${{ steps.setup-gh-token.outputs.token || github.token }}- name: Wait for Docker servicesenv:@@ -2630,6 +2636,7 @@ jobs:uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0with:node-version-file: .nvmrc+ token: ${{ steps.setup-gh-token.outputs.token || github.token }}- name: Install canvas builder dependenciesif: ${{ needs.changes.outputs.backend == 'true' && matrix.segment == 'Core' }}diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.ymlindex 0ff400d559c1..44aade675885 100644--- a/.github/workflows/ci-frontend.yml+++ b/.github/workflows/ci-frontend.yml@@ -329,10 +329,21 @@ jobs:steps:- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ - name: Mint setup-action GitHub token+ id: setup-gh-token+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ continue-on-error: true+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1+ with:+ client-id: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_APP_ID }}+ private-key: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_PRIVATE_KEY }}+ skip-token-revoke: true+- name: Install pnpm dependenciesuses: ./.github/actions/pnpm-installwith:install-command: pnpm --filter=@posthog/playwright... install --frozen-lockfile+ token: ${{ steps.setup-gh-token.outputs.token || github.token }}- name: Prepare frontendrun: bin/turbo --filter=@posthog/frontend prepare@@ -626,10 +637,21 @@ jobs:steps:- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ - name: Mint setup-action GitHub token+ id: setup-gh-token+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ continue-on-error: true+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1+ with:+ client-id: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_APP_ID }}+ private-key: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_PRIVATE_KEY }}+ skip-token-revoke: true+- name: Install pnpm dependenciesuses: ./.github/actions/pnpm-installwith:install-command: pnpm --filter=@posthog/playwright... install --no-frozen-lockfile+ token: ${{ steps.setup-gh-token.outputs.token || github.token }}- name: Prepare frontendrun: bin/turbo --filter=@posthog/frontend prepare@@ -818,11 +840,23 @@ jobs:steps:- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ - name: Mint setup-action GitHub token+ id: setup-gh-token+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ continue-on-error: true+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1+ with:+ client-id: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_APP_ID }}+ private-key: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_PRIVATE_KEY }}+ skip-token-revoke: true+# Full workspace install: the suite's jsdom test environment resolves# through the workspace root, not the package's own dependencies, so a# filtered install can't run it.- name: Install pnpm dependenciesuses: ./.github/actions/pnpm-install+ with:+ token: ${{ steps.setup-gh-token.outputs.token || github.token }}- name: Test with Jestid: run-jestdiff --git a/.github/workflows/ci-mcp-ui-apps.yml b/.github/workflows/ci-mcp-ui-apps.ymlindex 862f8bedc13a..0e5f533386e1 100644--- a/.github/workflows/ci-mcp-ui-apps.yml+++ b/.github/workflows/ci-mcp-ui-apps.yml@@ -66,11 +66,22 @@ jobs:cache-dependency-glob: uv.locksave-cache: ${{ github.ref == 'refs/heads/master' }}+ - name: Mint setup-action GitHub token+ id: setup-gh-token+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ continue-on-error: true+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1+ with:+ client-id: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_APP_ID }}+ private-key: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_PRIVATE_KEY }}+ skip-token-revoke: true+- name: Install pnpm dependencies# Match services/mcp/Dockerfile exactlyuses: ./.github/actions/pnpm-installwith:install-command: pnpm --filter=@posthog/mcp... install --frozen-lockfile+ token: ${{ steps.setup-gh-token.outputs.token || github.token }}- name: Check generated UI apps are up to daterun: |diff --git a/.github/workflows/ci-mcp.yml b/.github/workflows/ci-mcp.ymlindex 52ce4d367202..c10d6b6cf6bb 100644--- a/.github/workflows/ci-mcp.yml+++ b/.github/workflows/ci-mcp.yml@@ -222,10 +222,21 @@ jobs:- name: Checkout codeuses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ - name: Mint setup-action GitHub token+ id: setup-gh-token+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ continue-on-error: true+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1+ with:+ client-id: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_APP_ID }}+ private-key: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_PRIVATE_KEY }}+ skip-token-revoke: true+- name: Install pnpm dependenciesuses: ./.github/actions/pnpm-installwith:install-command: pnpm --filter=@posthog/mcp... --filter='./products/*' install --frozen-lockfile+ token: ${{ steps.setup-gh-token.outputs.token || github.token }}# The workers-pool project in vitest.config.mts parses wrangler.jsonc# up front and needs `assets.directory` (./public/) populated anddiff --git a/.github/workflows/ci-nodejs.yml b/.github/workflows/ci-nodejs.ymlindex af2b109e170f..359fbf2fbba4 100644--- a/.github/workflows/ci-nodejs.yml+++ b/.github/workflows/ci-nodejs.yml@@ -143,10 +143,21 @@ jobs:with:clean: false+ - name: Mint setup-action GitHub token+ id: setup-gh-token+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ continue-on-error: true+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1+ with:+ client-id: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_APP_ID }}+ private-key: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_PRIVATE_KEY }}+ skip-token-revoke: true+- name: Install pnpm dependenciesuses: ./.github/actions/pnpm-installwith:install-command: pnpm --filter=@posthog/nodejs... install --frozen-lockfile+ token: ${{ steps.setup-gh-token.outputs.token || github.token }}- name: Install rustuses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9@@ -197,10 +208,21 @@ jobs:with:clean: false+ - name: Mint setup-action GitHub token+ id: setup-gh-token+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ continue-on-error: true+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1+ with:+ client-id: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_APP_ID }}+ private-key: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_PRIVATE_KEY }}+ skip-token-revoke: true+- name: Install pnpm dependenciesuses: ./.github/actions/pnpm-installwith:install-command: pnpm --filter=@posthog/nodejs... install --frozen-lockfile+ token: ${{ steps.setup-gh-token.outputs.token || github.token }}- name: Install rustuses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9diff --git a/.github/workflows/ci-turbo.yml b/.github/workflows/ci-turbo.ymlindex 98e686dd6a4f..8d31a85d66e4 100644--- a/.github/workflows/ci-turbo.yml+++ b/.github/workflows/ci-turbo.yml@@ -49,10 +49,21 @@ jobs:echo "TURBO_SCM_BASE=master" >> $GITHUB_ENVfi+ - name: Mint setup-action GitHub token+ id: setup-gh-token+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ continue-on-error: true+ uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1+ with:+ client-id: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_APP_ID }}+ private-key: ${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_PRIVATE_KEY }}+ skip-token-revoke: true+- name: Install pnpm dependenciesuses: ./.github/actions/pnpm-installwith:install-command: pnpm install --frozen-lockfile --filter=@posthog/root+ token: ${{ steps.setup-gh-token.outputs.token || github.token }}- name: Turbo Affectedrun: |diff --git a/.github/workflows/monitor-github-rate-limit.yml b/.github/workflows/monitor-github-rate-limit.ymlindex 2c886f365c47..f9769556f7b8 100644--- a/.github/workflows/monitor-github-rate-limit.yml+++ b/.github/workflows/monitor-github-rate-limit.yml@@ -215,3 +215,26 @@ jobs:script: |const script = require('./.github/scripts/monitor-github-rate-limit.js')await script({ github, context, core }, { source: 'posthog-product-tests' })++ # A mint that fails is invisible from the buckets alone: the poll for+ # that source is simply absent, which looks the same as an App whose+ # secrets were never configured. Report the two apart so a broken+ # credential — which silently redirects that App's whole call volume+ # onto the shared GITHUB_TOKEN bucket — can be alerted on downstream.+ # Only booleans are interpolated here, never the tokens themselves.+ - name: Report App token mint failures+ if: always()+ uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0+ env:+ POSTHOG_DEVEX_PROJECT_API_TOKEN: ${{ secrets.POSTHOG_DEVEX_PROJECT_API_TOKEN }}+ MINTS: >-+ [{"source":"posthog-devex-general","configured":${{ secrets.GH_APP_POSTHOG_DEVEX_GENERAL_APP_ID != '' && secrets.GH_APP_POSTHOG_DEVEX_GENERAL_PRIVATE_KEY != '' }},"minted":${{ steps.devex-token.outputs.token != '' }}},+ {"source":"posthog-tests","configured":${{ secrets.GH_APP_POSTHOG_TESTS_APP_ID != '' && secrets.GH_APP_POSTHOG_TESTS_PRIVATE_KEY != '' }},"minted":${{ steps.tests-token.outputs.token != '' }}},+ {"source":"posthog-paths-filter","configured":${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_APP_ID != '' && secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY != '' }},"minted":${{ steps.paths-filter-token.outputs.token != '' }}},+ {"source":"posthog-telemetry","configured":${{ secrets.GH_APP_TELEMETRY_APP_ID != '' && secrets.GH_APP_TELEMETRY_PRIVATE_KEY != '' }},"minted":${{ steps.telemetry-token.outputs.token != '' }}},+ {"source":"posthog-setup-actions","configured":${{ secrets.GH_APP_POSTHOG_SETUP_ACTIONS_APP_ID != '' && secrets.GH_APP_POSTHOG_SETUP_ACTIONS_PRIVATE_KEY != '' }},"minted":${{ steps.setup-actions-token.outputs.token != '' }}},+ {"source":"posthog-product-tests","configured":${{ secrets.GH_APP_POSTHOG_PRODUCT_TESTS_APP_ID != '' && secrets.GH_APP_POSTHOG_PRODUCT_TESTS_PRIVATE_KEY != '' }},"minted":${{ steps.product-tests-token.outputs.token != '' }}}]+ with:+ script: |+ const script = require('./.github/scripts/monitor-github-rate-limit.js')+ await script.reportMintFailures({ github, context, core }, { mints: JSON.parse(process.env.MINTS) })