|
| 1 | +# Two-Branch Architecture for openmoq/moxygen |
| 2 | + |
| 3 | +## Context |
| 4 | + |
| 5 | +The current single-branch approach has compounding problems: patches modify |
| 6 | +upstream files creating perpetual conflicts, getdeps builds 30+ deps producing |
| 7 | +1.7 GB tarballs, and the sync workflow has grown complex. The standalone build |
| 8 | +(upstream PR #99, merged) eliminates most of this: no manifests, 5 FetchContent |
| 9 | +deps, ~50-150 MB artifacts. |
| 10 | + |
| 11 | +## The Full Flow |
| 12 | + |
| 13 | +### Branches |
| 14 | + |
| 15 | +- **`main`** — Pure upstream mirror. Unmodified copy of latest green upstream |
| 16 | + commit. No openmoq files. No workflows run. Not the default branch. |
| 17 | +- **`openmoq-main`** (DEFAULT) — Working branch. All openmoq customizations. |
| 18 | + Developer PRs go here. Artifacts published from here. |
| 19 | + |
| 20 | +### Daily sync cycle |
| 21 | + |
| 22 | +``` |
| 23 | +upstream (facebookexperimental/moxygen) |
| 24 | + │ |
| 25 | + │ 1. Sync workflow scans last 20 commits, picks newest green one |
| 26 | + │ |
| 27 | + ▼ |
| 28 | +main (pure mirror) |
| 29 | + │ 2. Fast-forward push: main = upstream green commit |
| 30 | + │ No workflows fire (all disabled on fork) |
| 31 | + │ |
| 32 | + │ 3. Check: is main already ancestor of openmoq-main? |
| 33 | + │ YES → done, nothing to merge |
| 34 | + │ NO → continue |
| 35 | + │ |
| 36 | + ▼ |
| 37 | +PR: main → openmoq-main |
| 38 | + │ 4. GitHub App bot creates PR (bot identity, not you) |
| 39 | + │ 5. PAT (OMOQ_SYNC_TOKEN) approves PR (different identity, satisfies review) |
| 40 | + │ 6. Auto-merge enabled |
| 41 | + │ |
| 42 | + │ 7. CI fires: standalone build on ubuntu + macOS (PR event) |
| 43 | + │ PASS → auto-merge fires → merged to openmoq-main |
| 44 | + │ FAIL → PR stays open, Slack alert, developer resolves |
| 45 | + │ |
| 46 | + ▼ |
| 47 | +openmoq-main (merge lands) |
| 48 | + │ 8. Push to openmoq-main triggers publish-artifacts |
| 49 | + │ 9. Standalone build on all 4 platforms |
| 50 | + │ 10. Release created: build-<sha> with per-platform tarballs |
| 51 | + │ |
| 52 | + ▼ |
| 53 | +orelay submodule can point to this commit |
| 54 | +``` |
| 55 | + |
| 56 | +### Developer workflow |
| 57 | + |
| 58 | +Normal trunk-based git. Developers open PRs against `openmoq-main`. CI runs |
| 59 | +standalone build. Reviews + merge as usual. Changes persist through upstream |
| 60 | +syncs because git merge handles it — once a merge conflict is resolved, the |
| 61 | +merge base advances and the same conflict doesn't recur. |
| 62 | + |
| 63 | +Two classes of local mods: |
| 64 | +- **Upstreamable**: commit on openmoq-main, PR upstream when ready. When upstream |
| 65 | + absorbs it, next sync merge resolves cleanly (or trivial conflict, resolved once). |
| 66 | +- **Non-upstreamable**: permanent commits on openmoq-main. Git merge carries them |
| 67 | + forward naturally. |
| 68 | + |
| 69 | +### What runs where |
| 70 | + |
| 71 | +| Branch | Workflows | Trigger | |
| 72 | +|--------|-----------|---------| |
| 73 | +| `main` | **NOTHING** (all upstream workflows disabled) | — | |
| 74 | +| PR → `openmoq-main` | `openmoq-ci.yml` (standalone build) | `pull_request` | |
| 75 | +| `openmoq-main` (push) | `openmoq-publish-artifacts.yml` | `push` | |
| 76 | +| `openmoq-main` (cron) | `openmoq-upstream-sync.yml` | `schedule` / `workflow_dispatch` | |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## Implementation |
| 81 | + |
| 82 | +### Phase 1: Setup (do first, one-time) |
| 83 | + |
| 84 | +**1a. Create GitHub App** (manual, in GitHub UI) |
| 85 | +- Go to `https://github.com/organizations/openmoq/settings/apps/new` |
| 86 | +- Name: `openmoq-sync-bot` (or similar) |
| 87 | +- Permissions: Contents R/W, Pull requests R/W, Workflows R/W |
| 88 | +- Webhook: off |
| 89 | +- Install on `openmoq/moxygen` only |
| 90 | +- Store: `OMOQ_APP_ID` (variable) + `OMOQ_APP_PRIVATE_KEY` (secret) |
| 91 | + |
| 92 | +**1b. Create branches and set default** |
| 93 | +```bash |
| 94 | +git fetch upstream main |
| 95 | +# Create openmoq-main from current main (has all openmoq files) |
| 96 | +git checkout -b openmoq-main origin/main |
| 97 | +git push -u origin openmoq-main |
| 98 | +# Set as default |
| 99 | +gh api repos/openmoq/moxygen -X PATCH -f default_branch=openmoq-main |
| 100 | +# Reset main to pure upstream |
| 101 | +git push origin upstream/main:refs/heads/main --force-with-lease |
| 102 | +``` |
| 103 | + |
| 104 | +**1c. Branch protection** |
| 105 | +- Remove protection from `main` (bot pushes directly) |
| 106 | +- Add protection on `openmoq-main` (required check: standalone build, 1 review) |
| 107 | + |
| 108 | +**1d. Disable upstream workflows** via API |
| 109 | +- getdeps_linux, getdeps_mac, standalone, docker-build-amd64, docker-build-arm64, |
| 110 | + docker-interop-client — all disabled |
| 111 | + |
| 112 | +**Verification**: `main` = upstream exactly. `openmoq-main` = default with all |
| 113 | +openmoq files. No upstream workflows fire on push to main. |
| 114 | + |
| 115 | +### Phase 2: Sync workflow (rewrite) |
| 116 | + |
| 117 | +`.github/workflows/openmoq-upstream-sync.yml` on `openmoq-main`: |
| 118 | + |
| 119 | +1. Generate app token (`actions/create-github-app-token@v2`) |
| 120 | +2. Checkout `openmoq-main` with app token (for push access) |
| 121 | +3. Scan upstream for newest green commit (reuse existing logic) |
| 122 | +4. Fast-forward `main`: `git push origin $SHA:refs/heads/main` |
| 123 | +5. Check if merge needed (`merge-base --is-ancestor`) |
| 124 | +6. Create PR `main` → `openmoq-main` using app token (bot identity) |
| 125 | +7. Approve PR using `OMOQ_SYNC_TOKEN` (your identity, satisfies review) |
| 126 | +8. Enable auto-merge using app token |
| 127 | +9. Slack on failure |
| 128 | + |
| 129 | +Key simplifications vs current: |
| 130 | +- No candidate branches, no patches, no conflict auto-resolution |
| 131 | +- PR is `main` → `openmoq-main` (if already open, it auto-updates on next push) |
| 132 | + |
| 133 | +### Phase 3: CI + artifact publishing (rewrite) |
| 134 | + |
| 135 | +**`openmoq-ci.yml`** (new) — runs on PRs to `openmoq-main`: |
| 136 | +- Standalone build on ubuntu-22.04 + macos-15 |
| 137 | +- `cmake -B _build -S standalone && cmake --build _build && ctest` |
| 138 | + |
| 139 | +**`openmoq-publish-artifacts.yml`** (rewrite) — runs on push to `openmoq-main`: |
| 140 | +- 4-platform matrix (ubuntu, macos, bookworm-amd64, bookworm-arm64) |
| 141 | +- `cmake -B _build -S standalone -DCMAKE_INSTALL_PREFIX=install/` |
| 142 | +- `cmake --build _build && cmake --install _build` |
| 143 | +- Package: gather install prefix + any needed headers into tarball |
| 144 | +- Release: `create-release.sh` (unchanged) |
| 145 | + |
| 146 | +**Headers**: `cmake --install` should install headers for all deps (each |
| 147 | +FetchContent dep has its own install rules). If moxygen's own headers aren't |
| 148 | +covered, the packaging script gathers them from source. This is a packaging |
| 149 | +concern — we verify during Phase 3 and handle in the collection script. |
| 150 | + |
| 151 | +**New `collect-artifacts-standalone.sh`**: takes `--install-prefix` and |
| 152 | +`--src-dir`, strips debug symbols, packages tarball. Much simpler than current |
| 153 | +getdeps-based version. |
| 154 | + |
| 155 | +### Phase 4: Cleanup |
| 156 | + |
| 157 | +- Delete `openmoq/patches/` (no longer needed) |
| 158 | +- Delete/archive old `collect-artifacts.sh` |
| 159 | +- Update `openmoq/README.md` and `GITHUB_WORKFLOW.md` |
| 160 | +- Clean up stale branches |
| 161 | +- Update o-rly `.gitmodules` to track `openmoq-main` |
| 162 | + |
| 163 | +### Phase 5: End-to-end verification |
| 164 | + |
| 165 | +1. Trigger sync → main advances → PR created (bot) → approved (you) → CI passes → merged |
| 166 | +2. Publish-artifacts fires → standalone build → tarball ~50-150 MB → release |
| 167 | +3. Conflict test: local mod on openmoq-main + upstream touches same file → PR open → Slack → resolve |
| 168 | + |
| 169 | +--- |
| 170 | + |
| 171 | +## Files |
| 172 | + |
| 173 | +| File | Action | Phase | |
| 174 | +|------|--------|-------| |
| 175 | +| `.github/workflows/openmoq-upstream-sync.yml` | Rewrite for two-branch + app token | 2 | |
| 176 | +| `.github/workflows/openmoq-ci.yml` | Create (standalone build CI) | 3 | |
| 177 | +| `.github/workflows/openmoq-publish-artifacts.yml` | Rewrite for standalone build | 3 | |
| 178 | +| `openmoq/scripts/collect-artifacts-standalone.sh` | Create | 3 | |
| 179 | +| `openmoq/scripts/collect-artifacts.sh` | Delete | 4 | |
| 180 | +| `openmoq/patches/` | Delete directory | 4 | |
| 181 | +| `openmoq/README.md` | Update | 4 | |
| 182 | +| `o-rly/design/GITHUB_WORKFLOW.md` | Update | 4 | |
| 183 | +| `o-rly/.gitmodules` | Track `openmoq-main` | 4 | |
0 commit comments