Skip to content

Commit ce349cf

Browse files
authored
chore(ci): use SHOPIFY_GH_ACCESS_TOKEN for agent PRs (#2192)
* fix(ci): triage only triggers when agent-triage label is added by a qualified user * chore(ci): improve agent workflows and skills from run feedback - Add pod install to allowed tools in fix, bot, and android-bot workflows - Add bundle exec to android-bot allowed tools (was missing) - Add git fetch origin main step to fix, bot, and android-bot workflows to prevent "no merge base" errors when diffing against main - Switch raise-pr skill to use --body-file instead of inline --body to avoid Claude Code permission checks on markdown headers - Triage skill: search closed issues too to catch regressions - Triage skill: allow clarification comments on vague feature requests - Fix skill: feature requests skip the "reproduce first" constraint * fix(ci): address copilot review comments - raise-pr: use Write tool instead of cat for /tmp/pr-body.md (cat not in allowed tools) - triage: fix Rules section to match Step 5 comment guidance * chore(ci): use SHOPIFY_GH_ACCESS_TOKEN for agent-raised PRs Agent-raised PRs must use the dedicated SHOPIFY_GH_ACCESS_TOKEN for PR creation to be mergeable. This injects it as AGENT_PR_TOKEN env var in all 3 agent workflows and updates the raise-pr skill and CLAUDE.md to enforce usage. * chore(ci): remove timeout-minutes from agent workflows Let agent workflows run without a hard timeout so they can complete naturally. Triage workflow keeps its 10-minute timeout. * chore(ci): kill background processes before finishing on CI Metro and other background processes prevent GitHub Actions jobs from exiting after the agent finishes. Added mandatory cleanup instructions to CLAUDE.md, fix-github-issue skill, and raise-pr skill. * fix(ci): allow GH_TOKEN prefixed gh pr commands in agent workflows The Bash permission pattern Bash(gh pr *) doesn't match when prefixed with GH_TOKEN=. Add explicit Bash(GH_TOKEN=* gh pr *) to ALLOWED_TOOLS.
1 parent 3835bf1 commit ce349cf

6 files changed

Lines changed: 56 additions & 13 deletions

File tree

.claude/skills/fix-github-issue/SKILL.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ These are hard rules. Violating any of them is a failure.
2323
3. Implement the fix
2424
4. Review your code for any obvious problems
2525
5. Verify the fix using `agent-device` skill
26-
6. **Raise a PR** using the raise-pr skill. When running interactively, confirm with dev first. On CI, raise directly.
26+
6. **Kill background processes** — before raising a PR, kill any Metro bundler or other background processes you started (see Cleanup section below).
27+
7. **Raise a PR** using the raise-pr skill. When running interactively, confirm with dev first. On CI, raise directly.
2728

2829
## Running Metro
2930

@@ -69,6 +70,19 @@ This runs `detox build -c ios.sim.release` followed by `detox test -c ios.sim.re
6970
cd fixture/react-native && yarn react-native run-ios
7071
```
7172

73+
## Cleanup (MANDATORY on CI)
74+
75+
**Before raising a PR or finishing, kill all background processes you started.** On CI, leftover processes (especially Metro) prevent the GitHub Actions job from exiting, causing it to run until the timeout.
76+
77+
```bash
78+
# Kill Metro bundler
79+
lsof -ti:8081 | xargs kill -9 2>/dev/null || true
80+
# Kill any other background processes you started
81+
kill %1 2>/dev/null || true
82+
```
83+
84+
Always do this **before** the raise-pr step.
85+
7286
## Common Pitfalls
7387

7488
- **`estimatedItemSize` does not exist** in this FlashList — it is not a prop. Do not add it to repro screens.

.claude/skills/raise-pr/SKILL.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ description: Create a GitHub PR for FlashList. Ensures no AI/Claude attribution
1515

1616
---
1717

18+
## Step 0 — Kill Background Processes (MANDATORY on CI)
19+
20+
Before creating the branch and PR, kill any background processes you started (Metro, emulators, etc.). On CI, leftover processes prevent the GitHub Actions job from exiting.
21+
22+
```bash
23+
lsof -ti:8081 | xargs kill -9 2>/dev/null || true
24+
```
25+
26+
---
27+
1828
## Step 1 — Create Branch and Commit
1929

2030
### Branch naming
@@ -110,11 +120,13 @@ Fixes #<number>
110120
- [ ] No regressions on related screens
111121
EOF
112122

113-
gh pr create \
123+
GH_TOKEN="$AGENT_PR_TOKEN" gh pr create \
114124
--title "fix(<scope>): <description>" \
115125
--body-file /tmp/pr-body.md
116126
```
117127

128+
**MANDATORY:** The `GH_TOKEN="$AGENT_PR_TOKEN"` prefix is required. PRs created without it cannot be merged. On CI, `AGENT_PR_TOKEN` is set automatically from `SHOPIFY_GH_ACCESS_TOKEN`. Locally, ensure it is exported or pass your token directly.
129+
118130
Before running `gh pr create`, double-check:
119131
- [ ] No mention of Claude, AI, Anthropic, or any AI tool anywhere
120132
- [ ] Description explains the "what" and "why" clearly

.github/workflows/agent-android-bot.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ env:
2626
Bash(git log),Bash(git log *),Bash(git diff),Bash(git diff *),Bash(git status),Bash(git show *),
2727
Bash(git checkout *),Bash(git add *),Bash(git commit *),Bash(git push -u *),
2828
Bash(git branch),Bash(git branch *),Bash(git rev-parse *),Bash(git fetch),Bash(git fetch *),
29-
Bash(gh issue *),Bash(gh pr *),Bash(gh label *),
29+
Bash(gh issue *),Bash(gh pr *),Bash(gh label *),Bash(GH_TOKEN=* gh pr *),
3030
Bash(agent-device *),
3131
Bash(adb devices),Bash(adb wait-for-device),Bash(adb install *),Bash(adb reverse *),
3232
Bash(adb shell getprop *),Bash(adb shell am *),Bash(adb shell pm *),Bash(adb shell screenrecord *),
3333
Bash(adb pull *),Bash(adb shell kill *),Bash(adb shell pidof *),
34-
Bash(curl -s http://localhost:*),
34+
Bash(curl http://localhost:*),Bash(curl -s http://localhost:*),Bash(curl -sS http://localhost:*),
3535
Bash(grep *),Bash(find *),Bash(ls),Bash(ls *),Bash(mkdir *),Bash(rm *),
3636
Bash(kill *),Bash(lsof),Bash(lsof *),Bash(nohup *),Bash(sleep *),
3737
Bash(head *),Bash(tail *),Bash(wc *),Bash(sort *),Bash(uniq *),
@@ -41,7 +41,6 @@ env:
4141
jobs:
4242
bot:
4343
runs-on: ubuntu-latest
44-
timeout-minutes: 45
4544
if: >-
4645
github.event_name == 'workflow_dispatch' ||
4746
(
@@ -151,6 +150,7 @@ jobs:
151150
uses: anthropics/claude-code-action@bf4f0de6fccd1eea7044a5f903fc928aff363134 # v1
152151
env:
153152
ANTHROPIC_BASE_URL: https://proxy.shopify.ai/vendors/anthropic
153+
AGENT_PR_TOKEN: ${{ secrets.SHOPIFY_GH_ACCESS_TOKEN }}
154154
with:
155155
trigger_phrase: "@android-agent"
156156
anthropic_api_key: ${{ secrets.AI_PROXY_TOKEN }}

.github/workflows/agent-bot.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ env:
2626
Bash(git log),Bash(git log *),Bash(git diff),Bash(git diff *),Bash(git status),Bash(git show *),
2727
Bash(git checkout *),Bash(git add *),Bash(git commit *),Bash(git push -u *),
2828
Bash(git branch),Bash(git branch *),Bash(git rev-parse *),Bash(git fetch),Bash(git fetch *),
29-
Bash(gh issue *),Bash(gh pr *),Bash(gh label *),
30-
Bash(agent-device *),Bash(xcrun simctl list),Bash(xcrun simctl list *),Bash(xcrun simctl get_app_container *),Bash(xcrun simctl install *),Bash(xcrun simctl launch *),Bash(xcrun simctl boot *),Bash(sips *),
31-
Bash(curl -s http://localhost:*),
29+
Bash(gh issue *),Bash(gh pr *),Bash(gh label *),Bash(GH_TOKEN=* gh pr *),
30+
Bash(agent-device *),Bash(xcrun simctl list),Bash(xcrun simctl list *),Bash(xcrun simctl get_app_container *),Bash(xcrun simctl install *),Bash(xcrun simctl launch *),Bash(xcrun simctl boot *),Bash(sips *),Bash(xcodebuild *),
31+
Bash(curl http://localhost:*),Bash(curl -s http://localhost:*),Bash(curl -sS http://localhost:*),
3232
Bash(grep *),Bash(find *),Bash(ls),Bash(ls *),Bash(mkdir *),Bash(rm *),
3333
Bash(kill *),Bash(lsof),Bash(lsof *),Bash(nohup *),Bash(sleep *),
3434
Bash(head *),Bash(tail *),Bash(wc *),Bash(sort *),Bash(uniq *),
@@ -38,7 +38,6 @@ env:
3838
jobs:
3939
bot:
4040
runs-on: macos-latest
41-
timeout-minutes: 45
4241
if: >-
4342
github.event_name == 'workflow_dispatch' ||
4443
(
@@ -75,6 +74,7 @@ jobs:
7574
uses: anthropics/claude-code-action@bf4f0de6fccd1eea7044a5f903fc928aff363134 # v1
7675
env:
7776
ANTHROPIC_BASE_URL: https://proxy.shopify.ai/vendors/anthropic
77+
AGENT_PR_TOKEN: ${{ secrets.SHOPIFY_GH_ACCESS_TOKEN }}
7878
with:
7979
trigger_phrase: "@agent"
8080
anthropic_api_key: ${{ secrets.AI_PROXY_TOKEN }}

.github/workflows/agent-fix.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ env:
1818
Bash(git log),Bash(git log *),Bash(git diff),Bash(git diff *),Bash(git status),Bash(git show *),
1919
Bash(git checkout *),Bash(git add *),Bash(git commit *),Bash(git push -u *),
2020
Bash(git branch),Bash(git branch *),Bash(git rev-parse *),Bash(git fetch),Bash(git fetch *),
21-
Bash(gh issue *),Bash(gh pr *),Bash(gh label *),
22-
Bash(agent-device *),Bash(xcrun simctl list),Bash(xcrun simctl list *),Bash(xcrun simctl get_app_container *),Bash(xcrun simctl install *),Bash(xcrun simctl launch *),Bash(xcrun simctl boot *),Bash(sips *),
23-
Bash(curl -s http://localhost:*),
21+
Bash(gh issue *),Bash(gh pr *),Bash(gh label *),Bash(GH_TOKEN=* gh pr *),
22+
Bash(agent-device *),Bash(xcrun simctl list),Bash(xcrun simctl list *),Bash(xcrun simctl get_app_container *),Bash(xcrun simctl install *),Bash(xcrun simctl launch *),Bash(xcrun simctl boot *),Bash(sips *),Bash(xcodebuild *),
23+
Bash(curl http://localhost:*),Bash(curl -s http://localhost:*),Bash(curl -sS http://localhost:*),
2424
Bash(grep *),Bash(find *),Bash(ls),Bash(ls *),Bash(mkdir *),Bash(rm *),
2525
Bash(kill *),Bash(lsof),Bash(lsof *),Bash(nohup *),Bash(sleep *),
2626
Bash(head *),Bash(tail *),Bash(wc *),Bash(sort *),Bash(uniq *),
@@ -45,7 +45,6 @@ jobs:
4545
github.event.comment.author_association == 'COLLABORATOR'
4646
)
4747
)
48-
timeout-minutes: 60
4948
steps:
5049
- name: Checkout
5150
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -71,6 +70,7 @@ jobs:
7170
uses: anthropics/claude-code-action@bf4f0de6fccd1eea7044a5f903fc928aff363134 # v1
7271
env:
7372
ANTHROPIC_BASE_URL: https://proxy.shopify.ai/vendors/anthropic
73+
AGENT_PR_TOKEN: ${{ secrets.SHOPIFY_GH_ACCESS_TOKEN }}
7474
with:
7575
anthropic_api_key: ${{ secrets.AI_PROXY_TOKEN }}
7676
github_token: ${{ secrets.GITHUB_TOKEN }}

CLAUDE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ Node 22.18.0
3535
- PR titles should be under 70 characters and match the commit format
3636
- Link issues with `Fixes #<number>` in the commit/PR body
3737

38+
## Agent PR Token (MANDATORY)
39+
40+
**All agent-raised PRs MUST use `SHOPIFY_GH_ACCESS_TOKEN` for PR creation.** PRs created without this token cannot be merged.
41+
42+
- On CI: The token is available as `$AGENT_PR_TOKEN` environment variable in agent workflows.
43+
- When creating a PR, **always** use: `GH_TOKEN="$AGENT_PR_TOKEN" gh pr create ...`
44+
- The default `GITHUB_TOKEN` is used for all other operations (issue comments, push, checkout). Only PR creation uses `AGENT_PR_TOKEN`.
45+
- **Never** use bare `gh pr create` without the `GH_TOKEN="$AGENT_PR_TOKEN"` prefix — the PR will be unmergeable.
46+
47+
## CI Cleanup (MANDATORY)
48+
49+
**Before finishing on CI, kill all background processes you started** — especially Metro (`port 8081`). Leftover processes prevent the GitHub Actions job from exiting, causing it to run until timeout and waste CI minutes.
50+
51+
```bash
52+
lsof -ti:8081 | xargs kill -9 2>/dev/null || true
53+
```
54+
3855
## Available Skills
3956

4057
Skills are reusable workflows in `.claude/skills/`. Use them when relevant:

0 commit comments

Comments
 (0)