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): use repository tokens outside the canonical repo (#122412)

Georges-Antoine Assiee1ab02d63ba
diff --git a/.github/workflows/ci-agent-proxy.yml b/.github/workflows/ci-agent-proxy.yml
index 8c71cfa8a756..7d7f6899f103 100644
--- a/.github/workflows/ci-agent-proxy.yml
+++ b/.github/workflows/ci-agent-proxy.yml
@@ -34,7 +34,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-agent-skills.yml b/.github/workflows/ci-agent-skills.yml
index 68fbecec0342..d49509161d74 100644
--- a/.github/workflows/ci-agent-skills.yml
+++ b/.github/workflows/ci-agent-skills.yml
@@ -33,7 +33,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-dagster.yml b/.github/workflows/ci-dagster.yml
index 7040065af017..fe461f295bcb 100644
--- a/.github/workflows/ci-dagster.yml
+++ b/.github/workflows/ci-dagster.yml
@@ -132,7 +132,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-e2e-playwright.yml b/.github/workflows/ci-e2e-playwright.yml
index 4a515123396a..957a316aa714 100644
--- a/.github/workflows/ci-e2e-playwright.yml
+++ b/.github/workflows/ci-e2e-playwright.yml
@@ -98,6 +98,9 @@ jobs:
token: ${{ secrets.TRUNK_API_TOKEN }}
changes:
+ permissions:
+ contents: read
+ pull-requests: read
runs-on: ubuntu-24.04
# 7 not 5: the debounce step below sleeps up to 60s, so widen the budget to
# keep ample headroom. A timeout here skips Playwright, which the aggregator
@@ -145,7 +148,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.yml
index d4cc5dc7ec0b..d3a7fb75f25a 100644
--- a/.github/workflows/ci-frontend.yml
+++ b/.github/workflows/ci-frontend.yml
@@ -117,7 +117,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-hobby.yml b/.github/workflows/ci-hobby.yml
index 11239b2a68e9..4f48754d5086 100644
--- a/.github/workflows/ci-hobby.yml
+++ b/.github/workflows/ci-hobby.yml
@@ -68,7 +68,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-hog.yml b/.github/workflows/ci-hog.yml
index f19852746aff..c974bd80a71f 100644
--- a/.github/workflows/ci-hog.yml
+++ b/.github/workflows/ci-hog.yml
@@ -65,7 +65,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-llm-gateway.yml b/.github/workflows/ci-llm-gateway.yml
index 927edec1445e..2afe61022996 100644
--- a/.github/workflows/ci-llm-gateway.yml
+++ b/.github/workflows/ci-llm-gateway.yml
@@ -37,7 +37,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-mcp-ui-apps.yml b/.github/workflows/ci-mcp-ui-apps.yml
index 563c9421e786..74289b2fb57d 100644
--- a/.github/workflows/ci-mcp-ui-apps.yml
+++ b/.github/workflows/ci-mcp-ui-apps.yml
@@ -28,7 +28,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-mcp.yml b/.github/workflows/ci-mcp.yml
index 164bdbbc9aaa..6142d6e36655 100644
--- a/.github/workflows/ci-mcp.yml
+++ b/.github/workflows/ci-mcp.yml
@@ -64,7 +64,7 @@ jobs:
# non-pytest Python change across the app triggers it.
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-migrations-service-separation-check.yml b/.github/workflows/ci-migrations-service-separation-check.yml
index 5eebabe0ee05..53cf96beba82 100644
--- a/.github/workflows/ci-migrations-service-separation-check.yml
+++ b/.github/workflows/ci-migrations-service-separation-check.yml
@@ -43,7 +43,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: steps.skip-label.outputs.skip != 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && steps.skip-label.outputs.skip != 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-nodejs.yml b/.github/workflows/ci-nodejs.yml
index 7342c39577e2..a946a3409009 100644
--- a/.github/workflows/ci-nodejs.yml
+++ b/.github/workflows/ci-nodejs.yml
@@ -85,7 +85,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-oauth-proxy.yml b/.github/workflows/ci-oauth-proxy.yml
index b1fbc54ec3eb..5e77fc6ba60f 100644
--- a/.github/workflows/ci-oauth-proxy.yml
+++ b/.github/workflows/ci-oauth-proxy.yml
@@ -28,7 +28,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-proto.yml b/.github/workflows/ci-proto.yml
index a14c6e85c542..d940ab9dd8fd 100644
--- a/.github/workflows/ci-proto.yml
+++ b/.github/workflows/ci-proto.yml
@@ -29,7 +29,7 @@ jobs:
sparse-checkout-cone-mode: false
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml
index cfb311964bef..bfda50e42c9b 100644
--- a/.github/workflows/ci-python.yml
+++ b/.github/workflows/ci-python.yml
@@ -76,7 +76,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-rust.yml b/.github/workflows/ci-rust.yml
index 031bb3c21969..1b0fa502b52e 100644
--- a/.github/workflows/ci-rust.yml
+++ b/.github/workflows/ci-rust.yml
@@ -60,7 +60,7 @@ jobs:
sparse-checkout-cone-mode: false
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-security.yaml b/.github/workflows/ci-security.yaml
index c6042f7e610e..55d92144dc8b 100644
--- a/.github/workflows/ci-security.yaml
+++ b/.github/workflows/ci-security.yaml
@@ -51,7 +51,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
# forks can't read org secrets — fall back to github.token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/ci-storybook.yml b/.github/workflows/ci-storybook.yml
index 82ba7e3b0d34..be0a2e22d799 100644
--- a/.github/workflows/ci-storybook.yml
+++ b/.github/workflows/ci-storybook.yml
@@ -63,6 +63,9 @@ jobs:
# Job to decide if we should run storybook ci
# See .github/actions/paths-filter/README.md for filter semantics
changes:
+ permissions:
+ contents: read
+ pull-requests: read
runs-on: ubuntu-24.04
timeout-minutes: 5
# A draft PR labeled `no-ci` skips this workflow entirely (prototypes):
@@ -122,7 +125,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/container-images-ci.yml b/.github/workflows/container-images-ci.yml
index ad4b3b65d556..f41a56782f3b 100644
--- a/.github/workflows/container-images-ci.yml
+++ b/.github/workflows/container-images-ci.yml
@@ -42,7 +42,7 @@ jobs:
sparse-checkout-cone-mode: false
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml
index 7bfc61a7d997..2d570eb812df 100644
--- a/.github/workflows/desktop-build.yml
+++ b/.github/workflows/desktop-build.yml
@@ -40,7 +40,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
# forks can't read org secrets, so fall back to github.token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/desktop-ci.yml b/.github/workflows/desktop-ci.yml
index 90044e1a7ac3..b767c3f93fab 100644
--- a/.github/workflows/desktop-ci.yml
+++ b/.github/workflows/desktop-ci.yml
@@ -81,7 +81,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
# forks can't read org secrets; fall back to github.token
- if: github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/desktop-quality.yml b/.github/workflows/desktop-quality.yml
index 23d9c8627aab..dde5fef2d15e 100644
--- a/.github/workflows/desktop-quality.yml
+++ b/.github/workflows/desktop-quality.yml
@@ -35,7 +35,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
# forks can't read org secrets, so fall back to github.token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/desktop-test.yml b/.github/workflows/desktop-test.yml
index ad30a06eae61..307368434a48 100644
--- a/.github/workflows/desktop-test.yml
+++ b/.github/workflows/desktop-test.yml
@@ -46,7 +46,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
# forks can't read org secrets, so fall back to github.token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/desktop-typecheck.yml b/.github/workflows/desktop-typecheck.yml
index 4fa3b8cd5a5b..fc83040c8b92 100644
--- a/.github/workflows/desktop-typecheck.yml
+++ b/.github/workflows/desktop-typecheck.yml
@@ -40,7 +40,7 @@ jobs:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
# forks can't read org secrets, so fall back to github.token
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
+ if: github.repository == 'PostHog/posthog' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
client-id: ${{ vars.GH_APP_POSTHOG_PATHS_FILTER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_PATHS_FILTER_PRIVATE_KEY }}
diff --git a/.github/workflows/pr-resolve-outdated-bot-comments.yml b/.github/workflows/pr-resolve-outdated-bot-comments.yml
index 45c4a608b6c5..b82dd4159aa7 100644
--- a/.github/workflows/pr-resolve-outdated-bot-comments.yml
+++ b/.github/workflows/pr-resolve-outdated-bot-comments.yml
@@ -19,7 +19,7 @@ jobs:
name: Resolve outdated bot review comments
runs-on: ubuntu-24.04
timeout-minutes: 5
- if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
+ if: github.repository == 'PostHog/posthog' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
steps:
- name: Get app token
diff --git a/tools/workflow-plan/tests/workflows.test.ts b/tools/workflow-plan/tests/workflows.test.ts
index e04d34358e1f..d36671ec72f8 100644
--- a/tools/workflow-plan/tests/workflows.test.ts
+++ b/tools/workflow-plan/tests/workflows.test.ts
@@ -459,7 +459,45 @@ const E2E_DISPATCH: Scenario = {
},
}
+const mirrorPullRequest = (): Scenario['github'] =>
+ JSON.parse(JSON.stringify(pullRequest()).replaceAll('PostHog/posthog', 'PostHog/example'))
+
+const pathsFilterJobs = workflowFiles.flatMap((file) =>
+ Object.entries(workflow(file).jobs).flatMap(([job, definition]) =>
+ definition.steps?.some(
+ (step) =>
+ step.id === 'app-token' &&
+ String(step.with?.['client-id']).includes('GH_APP_POSTHOG_PATHS_FILTER_APP_ID')
+ )
+ ? [{ file, job }]
+ : []
+ )
+)
+
const STEP_EXPECTATIONS: StepExpectation[] = [
+ ...pathsFilterJobs.flatMap(({ file, job }) => [
+ {
+ file,
+ job,
+ step: 'app-token',
+ scenario: { name: 'canonical PR token', github: pullRequest() },
+ runs: true,
+ },
+ {
+ file,
+ job,
+ step: 'app-token',
+ scenario: { name: 'mirror PR token', github: mirrorPullRequest() },
+ runs: false,
+ },
+ {
+ file,
+ job,
+ step: 'app-token',
+ scenario: { name: 'fork PR token', github: pullRequest({ fork: true }) },
+ runs: false,
+ },
+ ]),
...[
{ name: 'known fallback', selective: '', changedFiles: '', fork: false },
{ name: 'empty source selection', selective: 'true', changedFiles: '', fork: false },
@@ -521,6 +559,33 @@ const namedJobs = (file: string): Set<string> =>
)
describe('CI workflow run plans', () => {
+ it.each([
+ { name: 'canonical PR', github: pullRequest(), runs: true },
+ { name: 'mirror PR', github: mirrorPullRequest(), runs: false },
+ { name: 'fork PR', github: pullRequest({ fork: true }), runs: false },
+ ])('bot comment resolver on $name runs=$runs', ({ name, github, runs }) => {
+ const plan = planWorkflow(workflow('pr-resolve-outdated-bot-comments.yml'), { name, github })
+ expect(runningJobs(plan).includes('resolve-outdated')).toBe(runs)
+ })
+
+ it.each(pathsFilterJobs)('$file $job can read changed files without the App token', ({ file, job }) => {
+ const wf = workflow(file)
+ const definition = wf.jobs[job]!
+ const tokens = definition
+ .steps!.map((step) => step.with?.token ?? step.with?.['github-token'] ?? step.env?.GH_TOKEN)
+ .filter((token) => String(token).includes('steps.app-token.outputs.token'))
+ expect(tokens.length).toBeGreaterThan(0)
+ for (const token of tokens) {
+ expect(
+ evaluateValue(
+ token,
+ { github: mirrorPullRequest(), steps: { 'app-token': { outputs: { token: '' } } } },
+ planFunctions({ dependenciesSucceeded: true, dependenciesFailed: false, cancelled: false })
+ )
+ ).toBe('stub-token')
+ }
+ })
+
it.each([
['failed install', 'failure', 'src/example.ts', 'full'],
['empty source selection', 'skipped', '', 'selective'],