Skip to content

Commit 0de8ba0

Browse files
authored
Merge branch 'main' into fix/704
2 parents 8f87946 + 83a4cc7 commit 0de8ba0

1,072 files changed

Lines changed: 103102 additions & 9716 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
name: merging-prs
3+
description: Merge a PR into main through the Trunk merge queue and babysit it until it lands. Enqueue with a "/trunk merge" comment, then poll the "Trunk Merge Queue" check run and the PR state until it is MERGED or FAILED, reporting the Trunk bot's failure reason if the PR is kicked out. Use when asked to merge a PR, "merge when ready", "land it", "ship it", or to babysit/watch a PR through the queue. Never use `gh pr merge` in this repo -- the queue is the only path into main.
4+
allowed-tools: Bash(gh pr view:*), Bash(gh pr checks:*), Bash(gh pr comment:*), Bash(gh pr ready:*), Bash(gh api:*), Bash(sleep:*)
5+
---
6+
7+
# Merge a PR through the Trunk merge queue
8+
9+
Merges into `main` go **exclusively** through the [Trunk](https://trunk.io) merge
10+
queue. `gh pr merge` and the GitHub merge button are blocked by branch ruleset.
11+
To merge, you enqueue the PR with a comment, then watch it until Trunk lands it.
12+
13+
When a developer says "merge this PR", "merge it when it's ready", "land it",
14+
"ship it", or "babysit this PR", do the full loop below — enqueue **and** watch
15+
to completion, reporting the outcome. See also [docs/merge-queue.md](../../../docs/merge-queue.md).
16+
17+
`<n>` below is the PR number. Resolve the repo slug once if you need it:
18+
`REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)`.
19+
20+
## 1. Preflight
21+
22+
```bash
23+
gh pr view <n> --json state,isDraft,mergeable,reviewDecision,statusCheckRollup
24+
```
25+
26+
- **Not open** (already merged/closed) → report and stop.
27+
- **Draft** → it can't be merged. Ask the developer to confirm, then
28+
`gh pr ready <n>` before continuing. Don't un-draft silently.
29+
- **Failing required checks** (`statusCheckRollup`) → the queue will just reject
30+
it. Report which checks are red and stop; fix them first. **Pending** checks
31+
are fine — the queue waits for them.
32+
- **Merge conflicts** (`mergeable == "CONFLICTING"`) → report and stop; rebase first.
33+
34+
## 2. Enqueue
35+
36+
```bash
37+
gh pr comment <n> --body "/trunk merge"
38+
```
39+
40+
Within ~2 minutes, confirm Trunk picked it up — a check run whose name starts
41+
with `Trunk Merge Queue` should appear on the head commit:
42+
43+
```bash
44+
SHA=$(gh pr view <n> --json headRefOid -q .headRefOid)
45+
gh api repos/$REPO/commits/$SHA/check-runs \
46+
--jq '.check_runs[] | select(.name | startswith("Trunk Merge Queue")) | {name, status, conclusion, details_url}'
47+
```
48+
49+
If nothing appears after a couple of minutes, the developer may lack write
50+
access or GitHub-comment commands may be disabled — report that and suggest the
51+
`trunk-merge-queue-submit` label as a fallback.
52+
53+
## 3. Poll until it lands
54+
55+
Loop about every 60 seconds, up to ~45–60 minutes total. Each iteration:
56+
57+
```bash
58+
gh pr view <n> --json state,mergedAt # MERGED -> success, stop
59+
SHA=$(gh pr view <n> --json headRefOid -q .headRefOid)
60+
gh api repos/$REPO/commits/$SHA/check-runs \
61+
--jq '.check_runs[] | select(.name | startswith("Trunk Merge Queue")) | {status, conclusion, details_url}'
62+
sleep 60
63+
```
64+
65+
- `state == "MERGED"` → done. Report success with the merge commit.
66+
- Check run `status` moves `queued``in_progress``completed`. Report each
67+
transition so the developer can follow along.
68+
- Watch the **check run + PR state**, not `gh pr checks --watch`: the queue runs
69+
CI on Trunk's own draft/`trunk-merge/**` branch, so this PR's own checks don't
70+
reflect the queue's testing.
71+
- Stop at the timeout with a status summary rather than looping forever.
72+
73+
## 4. Handle failure
74+
75+
If the check run completes with `conclusion == "failure"` (or the PR drops out
76+
of the queue), Trunk kicks the PR and its bot comments with the failing
77+
workflow. Read the newest comments and report the reason:
78+
79+
```bash
80+
gh pr view <n> --comments | tail -n 40
81+
```
82+
83+
- If the failure is clearly caused by this PR **and** the fix is obvious, fix it,
84+
push, wait for the PR's own checks to go green, and re-enqueue **once** with
85+
`/trunk merge`.
86+
- Otherwise stop and report the failure and the workflow link. Don't repeatedly
87+
re-enqueue a red PR.
88+
89+
## 5. Cancel
90+
91+
If the developer asks to stop the merge:
92+
93+
```bash
94+
gh pr comment <n> --body "/trunk cancel"
95+
```
96+
97+
Confirm the check run reports cancelled.
98+
99+
## Hard rules
100+
101+
- **Never** run `gh pr merge` — it's blocked and it's not how this repo merges.
102+
- **Never** force-push a branch while it is in the queue — it removes the PR
103+
from the queue.
104+
- Re-enqueue a failed PR **at most once** automatically; beyond that, hand back
105+
to the developer.

.github/workflows/agent-release.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,29 @@ jobs:
6868
run: pnpm publish --access public --no-git-checks
6969
env:
7070
NPM_CONFIG_PROVENANCE: true
71+
72+
rebuild-sandbox-images:
73+
name: Rebuild tasks sandbox base images
74+
needs: release
75+
runs-on: ubuntu-latest
76+
timeout-minutes: 5
77+
permissions:
78+
contents: read
79+
steps:
80+
- name: Mint posthog/posthog workflow dispatch token
81+
id: dispatch-token
82+
uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
83+
with:
84+
app-id: ${{ secrets.GH_APP_POSTHOG_WORKFLOW_TRIGGER_APP_ID }}
85+
private-key: ${{ secrets.GH_APP_POSTHOG_WORKFLOW_TRIGGER_PRIVATE_KEY }}
86+
owner: PostHog
87+
repositories: posthog
88+
89+
- name: Dispatch posthog/posthog sandbox image rebuild
90+
env:
91+
GH_TOKEN: ${{ steps.dispatch-token.outputs.token }}
92+
run: |
93+
echo "Dispatching sandbox base image rebuild for $GITHUB_REF_NAME"
94+
gh workflow run cd-sandbox-base-image.yml \
95+
--repo PostHog/posthog \
96+
--ref master

.github/workflows/code-release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ jobs:
196196
echo "OK: $bin"
197197
done
198198
199+
# The native codex CLI must ship as a sibling of codex-acp, or the
200+
# app-server harness silently falls back to codex-acp in production.
201+
for f in codex rg; do
202+
if [[ ! -f "$RESOURCES/app.asar.unpacked/.vite/build/codex-acp/$f" ]]; then
203+
echo "FAIL: codex-acp/$f missing in bundled binaries"
204+
exit 1
205+
fi
206+
echo "OK: codex-acp/$f"
207+
done
208+
199209
- name: Install Playwright
200210
run: pnpm --filter code exec playwright install
201211

.github/workflows/code-tag.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
permissions:
2828
contents: write
2929
actions: write
30+
pull-requests: write
31+
issues: write
3032
runs-on: ubuntu-latest
3133
steps:
3234
- name: Get app token
@@ -42,6 +44,44 @@ jobs:
4244
fetch-depth: 0
4345
token: ${{ steps.app-token.outputs.token }}
4446

47+
- name: Check labeler is a member of team-posthog-code
48+
id: labeler
49+
if: github.event_name == 'pull_request'
50+
env:
51+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
52+
COMMENT_TOKEN: ${{ github.token }}
53+
REPOSITORY: ${{ github.repository }}
54+
PR_NUMBER: ${{ github.event.pull_request.number }}
55+
TEAM_SLUG: team-posthog-code
56+
run: |
57+
skip() {
58+
echo "$1 Skipping auto-release; the next scheduled release will pick this up."
59+
echo "authorized=false" >> "$GITHUB_OUTPUT"
60+
GH_TOKEN="$COMMENT_TOKEN" gh pr comment "$PR_NUMBER" --repo "$REPOSITORY" \
61+
--body "$1 Auto-release is limited to Team PostHog Code members, so this will ship with the next scheduled release instead." || true
62+
}
63+
64+
LABELER=$(gh api "repos/${REPOSITORY}/issues/${PR_NUMBER}/events" --paginate \
65+
--jq '.[] | select(.event == "labeled" and (.label.name | ascii_downcase) == "create release") | "\(.id) \(.actor.login)"' \
66+
| sort -n | tail -1 | cut -d" " -f2)
67+
68+
if [ -z "$LABELER" ]; then
69+
skip "Could not determine who added the 'Create release' label."
70+
exit 0
71+
fi
72+
73+
if ! MEMBERS=$(gh api "orgs/${REPOSITORY%%/*}/teams/${TEAM_SLUG}/members" --paginate --jq '.[].login'); then
74+
skip "Could not verify ${TEAM_SLUG} membership (GitHub API error)."
75+
exit 0
76+
fi
77+
78+
if echo "$MEMBERS" | grep -qixF "$LABELER"; then
79+
echo "'Create release' was added by ${LABELER}, a member of ${TEAM_SLUG}."
80+
echo "authorized=true" >> "$GITHUB_OUTPUT"
81+
else
82+
skip "'Create release' was added by @${LABELER}, who is not on ${TEAM_SLUG}."
83+
fi
84+
4585
- name: Check quiet period
4686
id: quiet
4787
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.quiet_retries != '0')
@@ -75,7 +115,7 @@ jobs:
75115
echo "proceed=false" >> "$GITHUB_OUTPUT"
76116
77117
- name: Compute version and create tag
78-
if: steps.quiet.outputs.proceed != 'false'
118+
if: steps.quiet.outputs.proceed != 'false' && steps.labeler.outputs.authorized != 'false'
79119
env:
80120
GH_TOKEN: ${{ steps.app-token.outputs.token }}
81121
REPOSITORY: ${{ github.repository }}

.github/workflows/pr-approval-agent.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ jobs:
6767
ANTHROPIC_API_KEY: ${{ secrets.STAMPHOG_ANTHROPIC_API_KEY }}
6868
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_TOKEN }}
6969
GH_TOKEN: ${{ steps.app-token.outputs.token }}
70+
# Set both to route through the ai-gateway (gateway.py overrides
71+
# ANTHROPIC_* at runtime). Unset means direct Anthropic.
72+
AI_GATEWAY_URL: ${{ secrets.STAMPHOG_AI_GATEWAY_URL }}
73+
AI_GATEWAY_API_KEY: ${{ secrets.STAMPHOG_AI_GATEWAY_API_KEY }}
7074
run: |
7175
uv run tools/pr-approval-agent/review_pr.py \
7276
${{ github.event.pull_request.number }} \

0 commit comments

Comments
 (0)