The Clipper delivery worker
The LaunchAgent poller that turns green pushes to main into TestFlight builds: installation, state file, ordering and skip rules, statuses and tests.

The worker is a Python script that a macOS LaunchAgent starts every 180 seconds on the build Mac, Clipper. Each start is one tick: find the next tested push to main that changed the app, build and upload it, and report a commit status. It exists because signing must happen on a Mac that holds the distribution identity, and GitHub's runners hold none.

Files

File

Role

tools/clipper-deploy.py

The worker. Installed as a copy named worker.py

tools/install-clipper-ci.sh

Installer for the checkouts and the LaunchAgent

tools/testclipperdeploy.py

Seven unit tests, run in GitHub Actions

Installation

Run BUN=<path to bun 1.4.2> tools/install-clipper-ci.sh in the signed in account that can export the archive. It (install-clipper-ci.sh):

    Checks that $BUN --version matches packageManager in package.json (exit 2 otherwise), that gh api repos/seed-hypermedia/seed works, and that the App Store Connect key metadata file is readable.

    Creates ~/.local/share/seed-exact-ci/ with two private checkouts:

      seed/: a blobless, sparse, single branch clone of main limited to frontend/apps/mobile-exact and .github/workflows.

      exact/: the Exact repository fetched at depth 1 at the commit in exact.rev, detached.

    Copies the worker to ~/.local/share/seed-exact-ci/worker.py. The running worker is this copy, not the file in the checkout, so "run it again after changing the worker or its installation settings" (README).

    Writes ~/Library/LaunchAgents/org.seedhypermedia.seed-exact-testflight.plist: /usr/bin/python3 worker.py, RunAtLoad, StartInterval 180, environment BUN and a PATH with Bun's directory, ~/.cargo/bin, Homebrew's node@24 and the system paths. Standard output goes to ~/Library/Logs/SeedExact/delivery.log, standard error to delivery.err.

    Boots out an existing agent with that label and bootstraps the new one in the gui/<uid> domain.

State file

~/.local/share/seed-exact-ci/delivery.json, written atomically through a .tmp file:

Field

Meaning

attempt

[run id, run_attempt] of the workflow run being or last processed. The run id is the cursor for the next poll

sha

Commit of that run

build

Build number allocated for it, see below

phase

pending, success, failure, or unchanged

shipped

Commit whose app directory is on TestFlight. Older files without it count a success state's sha as shipped

reserved

Set once App Store Connect confirmed the build number was unused, just before building

reported

The final commit status was posted

A worker.lock file is held with a non blocking flock; a tick that finds it held exits 0, so a long build is never doubled (L161-L167).

tick: ordering and skip rules

tick() does, in order:

    Fetch origin/main. If the workflow file is not on it, return.

    List push runs of seed-exact.yml on main, 100 per page. With no cursor (a fresh install) take only the newest run. Otherwise collect every run with id at or above the cursor.

    Walk the candidates in ascending run id. For each:

      Skip a run from another repository (a fork).

      Skip the attempt already reported, and any run for a commit already delivered successfully.

      If the run has no conclusion yet, return: later pushes wait for this one.

      Skip a run that did not succeed.

      Skip a commit that is not an ancestor of origin/main.

      Skip a commit whose app.json app.id is not media.hyper.seed.

      If shipped is set and git diff --quiet <shipped> <sha> -- frontend/apps/mobile-exact reports no difference, record the run as unchanged, mark it reported, and continue. No status is posted. If git cannot compare, the push is built.

      Otherwise this is the push to deliver.

    Resume the saved state if it is the same attempt; else create a new state with a fresh build number and phase pending.

    If pending: post the pending status, check out the commit detached, call deliver. An exception prints TestFlight delivery failed: ... to standard error and sets failure; otherwise success and shipped = sha.

    If not yet reported: post the final status, set reported, and on success delete the large artifacts in target/testflight/<build> (Seed.xcarchive, unpacked, unsigned.dSYM, export, unsigned.ipa), keeping the logs.

One push is delivered per tick. Because the cursor is a run id and the list is walked oldest first, pushes that arrived while Clipper was offline are processed in order when it returns. A failed delivery leaves shipped unchanged, so the next push is compared with the last shipped commit and still carries the undelivered change.

deliver

deliver(state):

    Moves the Exact checkout to the commit in the app's exact.rev if it differs.

    Sets EXACT2, EXACT, BUILD_NUMBER, VERIFY=1, UPLOAD=1, and requires $BUN --version to equal packageManager.

    Probes the build number with testflight-verify.mjs <build> <version> --exists. Exit 4 means unused: mark reserved and go on. If it exists and was reserved by this state, the upload already happened before a restart, so only verification runs. If it exists and was not reserved, allocate the next number and probe again.

    Runs bun install --frozen-lockfile in Exact and in the app, bun run test, then ./tools/testflight.sh. See Building and uploading to TestFlight.

allocatebuild

allocate_build(previous) returns <days since 2019-01-01 UTC>.<UTC hour>.<UTC minute>, for example 2890.12.14. Given a previous number it never returns less than one minute after it, so numbers always increase even for two builds in the same minute.

Commit status

Context TestFlight / Clipper, posted with gh api repos/seed-hypermedia/seed/statuses/<sha>, target URL the workflow run:

State

Description

pending

Building Seed Exact <build>

success

Available to internal testers: <build>

failure

Delivery failed: <build>

A push that left the app unchanged gets no status at all.

Unit tests

test_clipper_deploy.py patches output, run, subprocess.run, deliver and status, so no git, GitHub or signing is touched:

Test

Asserts

success is published once and rerunning a green build is a noop

One delivery, statuses pending then success, even after run_attempt increases

personal bundle and failed checks do not start delivery

A different bundle id or a failed run is never delivered

queued pushes wait for checks and deploy in order

An unfinished run blocks later ones; order is oldest first

pushes that leave the app alone are not delivered

Unchanged pushes are skipped without status; shipped advances only on delivery

an undelivered app change is built with the next push

After a failed delivery the next push is built even if it did not touch the app

failure waits for a new attempt

A failed attempt is not retried until run_attempt increases, then gets a new build number

interrupted status update does not repeat upload

A status call that raises is retried next tick without a second delivery

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Comments