# Task — Deliver Current main → Staging (TestFlight + Play Store Internal)

## Context
PR #202 just merged the staging CI workflow with `detect-native-changes` gate. The latest deploy-staging run on main:
- ✅ Test, ✅ Detect Native Changes, ✅ EAS Update (OTA), 🚫 Build Staging (skipped — no native change)

So OTA is up-to-date but **no native build was published to TestFlight / Play Store Internal**. User wants the current main built and submitted.

`deploy-staging.yml` only triggers on `push: branches: [main]` — no `workflow_dispatch`. Two paths to deliver:

1. **Add `workflow_dispatch` trigger** (small PR) → trigger from GitHub UI → workflow runs build-staging matrix.
2. **Manual `eas build`** locally — bypass CI, run from this main checkout.

## Recommended path: option 1 (small PR + dispatch)
- Lower risk: same code path CI uses.
- Adds value: future on-demand staging builds without forcing a native diff.

## Branch / Worktree
**You operate from the MAIN repo checkout** (`/Users/fathoni/Documents/Project/BlockDev/nano-street/mobile`), creating a small PR branch for the workflow change.

## Steps

### Step 1 — Add workflow_dispatch
```
cd /Users/fathoni/Documents/Project/BlockDev/nano-street/mobile
rtk git pull origin main --ff-only
git checkout -b feat/ci-staging-manual-trigger
```

Edit `.github/workflows/deploy-staging.yml`:
- Add `workflow_dispatch:` to the `on:` triggers block.
- For build-staging job's `if:` clause, allow either native change OR manual dispatch:
  ```yaml
  if: needs.detect-native-changes.outputs.native == 'true' || github.event_name == 'workflow_dispatch'
  ```

Verify YAML syntax: `cat .github/workflows/deploy-staging.yml | head -20`.

### Step 2 — Commit + open PR
```
rtk pnpm check  # ensure nothing else is broken
rtk git add .github/workflows/deploy-staging.yml
rtk git commit -m "feat(ci): add workflow_dispatch to deploy-staging for on-demand TestFlight builds"
```
HOLD push, ping coor for auth.

After auth + push: `gh pr create --draft --title "feat(ci): on-demand staging build trigger" --body "Adds workflow_dispatch + dispatch-bypass for the native-change gate so we can rebuild staging from current main without forcing a fake native diff. Tested by triggering immediately after merge."`
Then `gh pr ready <N>` (after explicit auth).

### Step 3 — Babysit PR through CR
Standard mobile babysit: /loop 7m /babysit-cr <N>, terminal = APPROVED, user merges. Same rules as previous CI agents: no @coderabbitai review, atomic fixes, inline replies with SHA.

### Step 4 — After merge: trigger the build
Once user merges, trigger:
```
gh workflow run deploy-staging.yml --ref main
```
Watch:
```
rtk gh run list --workflow=deploy-staging.yml --limit 3
rtk gh run watch <run-id>
```
Confirm Build Staging matrix kicks off (both ios + android), passes, and submits.

### Step 5 — Verify TestFlight + Play Internal
- Check TestFlight: agent reports status here. User confirms on App Store Connect.
- Check Play Store Internal: agent reports.
- Document in `.agent-status/staging-delivery-2026-04-27.md`:
  - Workflow run ID
  - Build IDs (ios + android)
  - Submission IDs
  - TestFlight processing status (visible / processing / failed)
  - Any issues encountered

## Constraints
- No push without auth.
- No marking PR ready without auth.
- No merging this PR yourself — user merges per mobile rule.
- If you hit credential issues during the actual build, report to coor — don't try to fix EAS credential setup.
- The first staging native build will exercise: ASC API key auto-provisioning App Store distribution cert (per #197 design). If this fails, that's a real bug worth flagging.

## Coordination
- Coordinator: `nanodev:1`.
- Ping at every milestone: PR opened, PR ready, CR transitions, merged, workflow triggered, build kicked off (with run ID), build complete, submit complete, TestFlight visible.
- Final ping: "staging delivery complete: TestFlight build <build_id>, Play Internal build <build_id>"
