Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

ci: offer a release only once the App Store has an iPhone app it works with

leepokai28e805df99ad
diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml
index dd71af9a..fb202164 100644
--- a/.github/workflows/auto-tag.yml
+++ b/.github/workflows/auto-tag.yml
@@ -39,9 +39,10 @@ jobs:
echo "Creating tag $TAG"
git tag "$TAG"
git push origin "$TAG"
- # Created here, before the build jobs upload to it, so it carries a description.
+ # Created here, before the build jobs upload to it, so it carries a description. Not
+ # latest: release-gate.yml marks it once it's uploaded and the App Store has its iPhone app.
tools/release-notes.sh "$TAG" > notes.md
- gh release create "$TAG" --verify-tag --title "$TAG" --notes-file notes.md --generate-notes
+ gh release create "$TAG" --verify-tag --title "$TAG" --notes-file notes.md --generate-notes --latest=false
# Announce it in the Discord server's #releases channel. A release created with
# GITHUB_TOKEN triggers no `release` workflow, so this happens here. The Discord Worker turns
# each @login linked to a member into a mention, which the message pings (discord/README.md).
diff --git a/.github/workflows/host.yml b/.github/workflows/host.yml
index e545e918..984a1d43 100644
--- a/.github/workflows/host.yml
+++ b/.github/workflows/host.yml
@@ -95,43 +95,16 @@ jobs:
--version "$GITHUB_REF_NAME" --platform "${{ matrix.name }}"
- uses: softprops/action-gh-release@v2
with:
+ make_latest: false
files: |
codync-host-*.tar.gz
codync-host-*.tar.gz.sha256
codync-host-*.compat.json
codync-host-*.compat.json.sig
- # The update manifest last: hosts offer the release once they see it, so the archive
- # it points at must already be downloadable.
+ # The update manifest last: the release gate takes a release with all its feeds as fully uploaded.
- uses: softprops/action-gh-release@v2
with:
+ make_latest: false
files: |
codync-host-*.update.json
codync-host-*.update.json.sig
-
- homebrew:
- # Keeps `brew install leepokai/codync/codync-host` (Linux, headless Macs) in step with releases.
- needs: release
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v4
- - name: Update the tap's formula
- env:
- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
- VERSION=${GITHUB_REF_NAME#v}
- gh release download "$GITHUB_REF_NAME" --pattern 'codync-host-*.sha256' --dir sums
- sha() { cut -d' ' -f1 "sums/codync-host-$1.tar.gz.sha256"; }
- sed -e "s/^ version .*/ version \"$VERSION\"/" \
- -e "0,/REPLACE_WITH_SHA256/s//$(sha macos-arm64)/" \
- -e "0,/REPLACE_WITH_SHA256/s//$(sha macos-x86_64)/" \
- -e "0,/REPLACE_WITH_SHA256/s//$(sha linux-arm64)/" \
- -e "0,/REPLACE_WITH_SHA256/s//$(sha linux-x86_64)/" \
- packaging/homebrew/codync-host.rb > codync-host.rb
- git clone https://x-access-token:${{ secrets.TAP_TOKEN }}@github.com/leepokai/homebrew-codync.git tap
- mkdir -p tap/Formula && cp codync-host.rb tap/Formula/ && cp packaging/homebrew/README.md tap/
- cd tap
- git config user.name "github-actions[bot]"
- git config user.email "github-actions[bot]@users.noreply.github.com"
- git add -A
- git commit -m "codync-host $VERSION" || exit 0
- git push
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.yml
index 78b4d29f..16b6d9e6 100644
--- a/.github/workflows/release-desktop.yml
+++ b/.github/workflows/release-desktop.yml
@@ -154,29 +154,13 @@ jobs:
cd apps/desktop/dist
shasum -a 256 codync-macos.dmg > codync-macos.dmg.sha256
FILES="codync-macos.dmg codync-macos.dmg.sha256 codync-macos.zip codync-macos.zip.blockmap"
- # The host workflow may have created this release already (same tag).
- gh release create "$GITHUB_REF_NAME" $FILES --title "Codync $GITHUB_REF_NAME" --generate-notes ||
+ # Auto Tag or the host workflow has usually created this release already (same tag). Not
+ # latest: release-gate.yml marks it (and updates the Homebrew tap) once it's safe to offer.
+ gh release create "$GITHUB_REF_NAME" $FILES --title "Codync $GITHUB_REF_NAME" --generate-notes --latest=false ||
gh release upload "$GITHUB_REF_NAME" $FILES --clobber
- # Update feeds last: installed apps offer the release once they see them, so the files
- # they point at must already be downloadable.
+ # Update feeds last: the release gate takes a release with all its feeds as fully uploaded.
gh release upload "$GITHUB_REF_NAME" latest-mac.yml ../../../build/appcast.xml --clobber
- - name: Update Homebrew tap
- if: startsWith(github.ref, 'refs/tags/')
- run: |
- VERSION=${GITHUB_REF_NAME#v}
- SHA=$(shasum -a 256 apps/desktop/dist/codync-macos.dmg | awk '{print $1}')
- git clone https://x-access-token:${{ secrets.TAP_TOKEN }}@github.com/leepokai/homebrew-codync.git tap
- mkdir -p tap/Casks
- sed -e "s/^ version .*/ version \"$VERSION\"/" -e "s/REPLACE_WITH_SHA256/$SHA/" packaging/homebrew/codync.rb > tap/Casks/codync.rb
- cp packaging/homebrew/README.md tap/
- cd tap
- git config user.name "github-actions[bot]"
- git config user.email "github-actions[bot]@users.noreply.github.com"
- git add -A
- git commit -m "Update Codync to $VERSION" || exit 0
- git push
-
windows:
needs: check
runs-on: windows-latest
@@ -228,6 +212,7 @@ jobs:
- uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
+ make_latest: false
files: |
apps/desktop/dist/codync-windows-x64.exe
apps/desktop/dist/codync-windows-x64.exe.sha256
@@ -236,6 +221,7 @@ jobs:
- uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
+ make_latest: false
files: apps/desktop/dist/latest.yml
linux:
@@ -277,9 +263,11 @@ jobs:
- uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
+ make_latest: false
files: apps/desktop/dist/codync-${{ matrix.name }}.*
# The update feed last, once the packages it points at are downloadable.
- uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
+ make_latest: false
files: apps/desktop/dist/latest-linux*.yml
diff --git a/.github/workflows/release-gate.yml b/.github/workflows/release-gate.yml
new file mode 100644
index 00000000..4b75db49
--- /dev/null
+++ b/.github/workflows/release-gate.yml
@@ -0,0 +1,40 @@
+name: Release gate
+
+# Marks the newest release the App Store's iPhone app works with as GitHub's latest and points the
+# Homebrew tap at it (tools/release-gate.py): website downloads, install.sh and every updater follow
+# that mark, so a release that needs a newer iPhone app waits for App Review. After each release,
+# and hourly for the App Store to catch up.
+on:
+ workflow_run:
+ workflows: ["Release desktop", "codync-host"]
+ types: [completed]
+ schedule:
+ - cron: "17 * * * *"
+ workflow_dispatch:
+ inputs:
+ allow_back:
+ description: "Mark an older release than the latest (when the latest needs an iPhone app still in review)"
+ type: boolean
+ default: false
+
+permissions:
+ contents: write
+
+jobs:
+ gate:
+ if: >-
+ github.repository == 'leepokai/Codync' &&
+ (github.event_name != 'workflow_run' || github.event.workflow_run.event == 'push')
+ # In the job, so a run skipped by `if` (a pull request's release build) never queues here.
+ concurrency:
+ group: release-gate
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ - run: python3 tools/release-gate.py
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ TAP_TOKEN: ${{ secrets.TAP_TOKEN }}
+ ALLOW_BACK: ${{ inputs.allow_back && '1' || '' }}
diff --git a/docs/guides/development.md b/docs/guides/development.md
index 7b50757d..fa7f1495 100644
--- a/docs/guides/development.md
+++ b/docs/guides/development.md
@@ -113,7 +113,7 @@ Versions are defined in `apps/project.yml` (`MARKETING_VERSION`), `host/Cargo.to
## GitHub releases
-Auto Tag (`.github/workflows/auto-tag.yml`) creates each `v*` release right after pushing the tag, before the host and desktop jobs upload to it. Its description comes from `tools/release-notes.sh`: the `## Summary` of the PR that merged the version bump into `main` (or the PR's opening text without that heading), else the `feat`/`fix` commits since the previous tag, followed by GitHub's generated PR list and compare link. Write the release PR's Summary for people reading the release page. The same description is posted to the Discord server's #releases channel through the webhook in the `DISCORD_RELEASES_WEBHOOK` secret (a failed post only leaves a warning on the run); each `@login` there whose GitHub account is linked on the Discord Worker becomes a mention that pings them (`DISCORD_MENTIONS_SECRET`, [discord/README.md](../../discord/README.md)).
+Auto Tag (`.github/workflows/auto-tag.yml`) creates each `v*` release right after pushing the tag, before the host and desktop jobs upload to it. Releases go up without GitHub's *latest* mark: the release gate gives it to the newest fully uploaded release the App Store's iPhone app works with, so downloads, updaters and Homebrew wait for App Review when a release needs a newer iPhone app ([holding releases](../reference/compatibility.md#holding-releases-for-the-app-store)). Its description comes from `tools/release-notes.sh`: the `## Summary` of the PR that merged the version bump into `main` (or the PR's opening text without that heading), else the `feat`/`fix` commits since the previous tag, followed by GitHub's generated PR list and compare link. Write the release PR's Summary for people reading the release page. The same description is posted to the Discord server's #releases channel through the webhook in the `DISCORD_RELEASES_WEBHOOK` secret (a failed post only leaves a warning on the run); each `@login` there whose GitHub account is linked on the Discord Worker becomes a mention that pings them (`DISCORD_MENTIONS_SECRET`, [discord/README.md](../../discord/README.md)).
## codync-mem releases
diff --git a/docs/guides/updates.md b/docs/guides/updates.md
index 0ee6cbbc..1cd14d64 100644
--- a/docs/guides/updates.md
+++ b/docs/guides/updates.md
@@ -99,6 +99,11 @@ or `brew reinstall leepokai/codync/codync-host`, then run `codync-host install`.
`codync-host uninstall` removes the background service, not the executable or
saved bots, so it is not a complete application uninstall.
+Reinstalling gets the latest release, which can be older than what is installed while a
+newer release waits for App Review
+([holding releases](../reference/compatibility.md#holding-releases-for-the-app-store)); then
+download the installed version from its release page instead.
+
After reinstalling, confirm the app version and that the computer reconnects.
Existing bots and pairings should remain when the original data and keys are
kept. Repair the app on the affected computer: an SSH-connected Mac mini must
@@ -121,11 +126,14 @@ percentage, staged, restarting, errors) and the labels of the shared update acti
not the rendering itself.
The release workflow publishes `latest-mac.yml`, `latest.yml` and `latest-linux*.yml`
-after the app archives they point at, so an install never offers a release it can't
-download yet. macOS build versions follow the marketing version; the iOS build
-counter is independent. Installs of the SwiftUI Mac app that preceded the desktop
-app still read the Sparkle appcast; the release workflow generates one for the
-desktop zip, so those installs move to the desktop app.
+after the app archives they point at. Installs read the release GitHub marks *latest*,
+which only the release gate sets: once every feed is up and the App Store has an iPhone
+app the release serves
+([holding releases](../reference/compatibility.md#holding-releases-for-the-app-store)).
+macOS build versions follow the marketing version; the iOS build counter is independent.
+Installs of the SwiftUI Mac app that preceded the desktop app still read the Sparkle
+appcast; the release workflow generates one for the desktop zip, so those installs move
+to the desktop app.
### Deprecated: the Sparkle migration appcast (remove after 2026-11-06)
@@ -186,11 +194,12 @@ with the commands above, independently of the app.
## Release configuration
-Both workflows (`host.yml`, `release-desktop.yml`) run for a `vMAJOR.MINOR.PATCH` tag. Keep the host Cargo version,
-`apps/desktop/package.json` and the marketing version aligned before tagging; the
-desktop workflow fails when the app and host versions differ. The host workflow refuses a
-tag/version mismatch. Existing clients without this updater need one manual
-upgrade to adopt it.
+Both workflows (`host.yml`, `release-desktop.yml`) run for a `vMAJOR.MINOR.PATCH` tag and publish
+without the *latest* mark; `release-gate.yml` sets it and updates the Homebrew tap (secret
+`TAP_TOKEN`). Keep the host Cargo version, `apps/desktop/package.json` and the marketing
+version aligned before tagging; the desktop workflow fails when the app and host versions
+differ. The host workflow refuses a tag/version mismatch. Existing clients without this
+updater need one manual upgrade to adopt it.
Public keys are committed in `packaging/updates/`. Keep their corresponding
private keys backed up securely; replacing a public key breaks updates for
@@ -200,6 +209,7 @@ already distributed clients. Repository Actions secrets:
| --- | --- |
| `SPARKLE_PRIVATE_KEY` | Sparkle's base64 Ed25519 private key export (the migration appcast; deprecated, see above) |
| `HOST_UPDATE_SIGNING_KEY` | Separate base64 32-byte Ed25519 seed for host manifests |
+| `TAP_TOKEN` | Token that pushes `leepokai/homebrew-codync` (release gate) and the version tags (Auto Tag) |
The desktop workflow signs and notarizes the Mac app, builds its DMG and zip, adds
`minApp` to `latest-mac.yml` and generates `appcast.xml` for the zip; it builds the
diff --git a/docs/reference/compatibility.md b/docs/reference/compatibility.md
index bbe753c3..d85769c6 100644
--- a/docs/reference/compatibility.md
+++ b/docs/reference/compatibility.md
@@ -53,8 +53,9 @@ couldn't get the matching side yet.
- **Renaming, removing or changing the meaning** of anything an older client reads or sends:
change it, set `MIN_APP` to this release (its iPhone part ships with it: the change
touches `apps/ios/Kit/`, so `Submit iOS` includes it), add a row to the floor history, and re-record
- the wire shape snapshot. Hosts hold that release back until the App Store has the iPhone
- app (next section), so nobody is asked for an update that isn't there yet.
+ the wire shape snapshot. That release isn't offered (downloads, updaters, Homebrew) until
+ the App Store has the iPhone app (next section), so nobody is asked for an update that
+ isn't there yet.
- **Raise `minHost`** when the client's core flows need something older hosts lack. Hosts
update without review, so this only asks the person to update the computer. An optional
feature that needs a newer host hides its control instead.
@@ -63,11 +64,29 @@ couldn't get the matching side yet.
`unsupportedVersion`, close code 4400) is separate: the host must keep accepting every `v`
a supported client sends.
-### Holding host updates for the App Store
-
-A release that raises `minApp` would lock out paired iPhones until App Review passes. Every
-updater therefore asks the App Store (`itunes.apple.com/lookup?id=6760984418`) before
-installing such a release:
+### Holding releases for the App Store
+
+A release that raises `minApp` would lock out paired iPhones until App Review passes, and a
+computer set up from it would lock out the iPhone it pairs with. So what anyone can get
+follows the App Store:
+
+- **Release gate** (`tools/release-gate.py`, run by `.github/workflows/release-gate.yml` after
+ each release and hourly): releases are published without GitHub's *latest* mark. The gate
+ marks the newest fully uploaded release whose `MIN_APP` the App Store's iPhone version meets
+ (`itunes.apple.com/lookup?id=6760984418`) and points the Homebrew tap (cask and formula) at
+ it. The website's download links (`releases/latest/download/…`), `packaging/install.sh`,
+ electron-updater and `codync-host update` all read the latest release, so none of them sees
+ a release that waits. Every release after a raise waits with it, desktop-only ones too, until
+ App Review passes; the next hourly run then offers the newest. The mark only moves forward
+ on its own (a lookup can briefly answer with an older version); to move it back, run the
+ *Release gate* workflow by hand with `allow_back` on. `DRY_RUN=1 python3
+ tools/release-gate.py` prints the decision; `python3 tools/release-gate-test.py` checks it.
+ Before the gate, 2.18.0 (the first real raise) went straight to the website: in its first
+ day 33 new computers were paired by the App Store's iPhone 2.17.0 and received no message
+ from it.
+- **Each updater** also asks the App Store before installing a release that raises `minApp`.
+ It predates the gate, which now keeps such releases from updaters, so this second check
+ rarely decides anything:
| Situation | Host update |
|---|---|
@@ -92,8 +111,7 @@ installing such a release:
anything downloads. A check the person starts shows why. While waiting it checks hourly. The Sparkle appcast kept for the
SwiftUI Mac app's installs carries `<codync:minApp>` (`packaging/updates/annotate-appcast.py`);
it is deprecated and removed after 2026-11-06 ([updates guide](../guides/updates.md#deprecated-the-sparkle-migration-appcast-remove-after-2026-11-06)).
-- Hosts released before 2.5.0 don't have this gate and install any release. Before the first
- real `minApp` raise, most computers should be on 2.5.0 or newer.
+- Hosts released before 2.5.0 don't ask; the release gate keeps such releases from them.
On the iPhone, the *Update Codync* button of an *Update this app* notice is greyed out with
"still in App Store review" while the App Store has an older version; an unanswered lookup
diff --git a/packaging/homebrew/README.md b/packaging/homebrew/README.md
index e990b7ff..5255a992 100644
--- a/packaging/homebrew/README.md
+++ b/packaging/homebrew/README.md
@@ -9,4 +9,4 @@ brew install leepokai/codync/codync-host # host only: Linux, headless Mac
Or without Homebrew: `curl -fsSL https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh | sh`
-Generated from [`packaging/homebrew`](https://github.com/leepokai/Codync/tree/main/packaging/homebrew) by the release workflows in the Codync repo; edit the templates there, not this repo.
+Generated from [`packaging/homebrew`](https://github.com/leepokai/Codync/tree/main/packaging/homebrew) by `tools/release-gate.py` in the Codync repo, for the release it marks latest; edit the templates there, not this repo.
diff --git a/packaging/homebrew/codync-host.rb b/packaging/homebrew/codync-host.rb
index 49546f0e..d70d6b47 100644
--- a/packaging/homebrew/codync-host.rb
+++ b/packaging/homebrew/codync-host.rb
@@ -1,6 +1,6 @@
# Homebrew formula template for the leepokai/homebrew-codync tap.
-# The `homebrew` job in .github/workflows/host.yml fills in the version and the four
-# sha256 values (in this order: mac arm, mac intel, linux arm, linux intel) on every `v*` tag.
+# tools/release-gate.py fills in the version and the four sha256 values (in this order: mac arm,
+# mac intel, linux arm, linux intel) of the release it marks latest.
class CodyncHost < Formula
desc "Host that runs coding agents (Claude Code, Codex, Cursor…) as Codync bots"
homepage "https://www.codync.dev"
diff --git a/packaging/homebrew/codync.rb b/packaging/homebrew/codync.rb
index 92eeabef..de25e971 100644
--- a/packaging/homebrew/codync.rb
+++ b/packaging/homebrew/codync.rb
@@ -1,6 +1,5 @@
# Homebrew cask template for the leepokai/homebrew-codync tap.
-# The macOS job in .github/workflows/release-desktop.yml fills in the version and the
-# DMG's sha256 on every `v*` tag.
+# tools/release-gate.py fills in the version and the DMG's sha256 of the release it marks latest.
cask "codync" do
version "0.0.0"
sha256 "REPLACE_WITH_SHA256"
diff --git a/tools/release-gate-test.py b/tools/release-gate-test.py
new file mode 100644
index 00000000..dc3a0652
--- /dev/null
+++ b/tools/release-gate-test.py
@@ -0,0 +1,34 @@
+"""Self-check for release-gate.py's choice: python3 tools/release-gate-test.py"""
+
+import importlib.util
+import pathlib
+import sys
+
+sys.dont_write_bytecode = True
+
+spec = importlib.util.spec_from_file_location("release_gate", pathlib.Path(__file__).with_name("release-gate.py"))
+gate = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(gate)
+
+floors = {"v2.17.5": "2.3.0", "v2.18.0": "2.18.0", "v2.19.1": "2.18.0", "v2.19.2": "2.19.2"}
+uploaded = {"v2.17.5", "v2.18.0", "v2.19.1"}
+
+
+def choose(store):
+ return gate.choose(store, ["v2.19.2", "v2.19.1", "v2.18.0", "v2.17.5", "v2.19.3-beta"],
+ min_app=floors.get, complete=uploaded.__contains__)
+
+
+# 2.18.0 raised the floor: while the App Store has 2.17.0, downloads stay on 2.17.5.
+assert choose("2.17.0") == "v2.17.5"
+# The newest whose floor the App Store meets, even when it isn't the newest release.
+assert choose("2.18.0") == "v2.19.1"
+# 2.19.2 meets 2.19.2, but it is still uploading.
+assert choose("2.19.2") == "v2.19.1"
+uploaded.add("v2.19.2")
+assert choose("2.19.2") == "v2.19.2"
+# Versions compare as numbers, not text.
+assert choose("2.100.0") == "v2.19.2"
+# No release's floor is met: the latest mark stays where it is.
+assert choose("2.0.0") is None
+print("ok")
diff --git a/tools/release-gate.py b/tools/release-gate.py
new file mode 100644
index 00000000..75ba8546
--- /dev/null
+++ b/tools/release-gate.py
@@ -0,0 +1,148 @@
+#!/usr/bin/env python3
+"""Point every download at the newest release the App Store's iPhone app works with.
+
+Usage: release-gate.py
+Env: GH_TOKEN (gh: reads the releases, marks the latest), TAP_TOKEN (pushes the Homebrew tap);
+DRY_RUN=1 prints what it would do instead; ALLOW_BACK=1 may mark an older release than the latest.
+Runs in a checkout with the release tags.
+
+Releases are published without GitHub's "latest" mark. The website's download links,
+packaging/install.sh, the desktop app's and the host's updaters all read the latest release, and the
+Homebrew tap follows it, so this decides what anyone can get: the newest complete release whose
+host serves the iPhone app the App Store has (its `MIN_APP`). A newer one waits for App Review;
+offered earlier, a computer on it would tell every paired iPhone to update to a version still in
+review. The mark only moves forward on its own: an App Store lookup that briefly answers with an
+older version doesn't take downloads back. Runs after each release and hourly
+(.github/workflows/release-gate.yml).
+"""
+
+import json
+import os
+import re
+import subprocess
+import tempfile
+import urllib.request
+from pathlib import Path
+
+REPO = "leepokai/Codync"
+TAP = "leepokai/homebrew-codync"
+APP_STORE_LOOKUP = "https://itunes.apple.com/lookup?id=6760984418"
+DRY_RUN = os.environ.get("DRY_RUN") == "1"
+# In the order of the formula template's sha256 lines.
+HOST_PLATFORMS = ("macos-arm64", "macos-x86_64", "linux-arm64", "linux-x86_64")
+# Each platform's update feed goes up after the files it points at, so with all of them there the
+# release is downloadable everywhere.
+FEEDS = {"latest-mac.yml", "latest.yml", "latest-linux.yml", "latest-linux-arm64.yml"} | {
+ f"codync-host-{p}.update.json" for p in HOST_PLATFORMS}
+
+
+def run(*args, cwd=None):
+ return subprocess.run(args, cwd=cwd, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
+
+
+def gh_json(*args):
+ return json.loads(run("gh", *args, "--repo", REPO))
+
+
+def parse(version):
+ """`[major, minor, patch]` of `2.19.1` or `v2.19.1`; None for anything else (a pre-release)."""
+ match = re.fullmatch(r"v?(\d+)\.(\d+)\.(\d+)", version)
+ return [int(n) for n in match.groups()] if match else None
+
+
+def app_store_version():
+ with urllib.request.urlopen(APP_STORE_LOOKUP, timeout=20) as response:
+ results = json.load(response)["results"]
+ return results[0]["version"] if results else None
+
+
+def min_app(tag):
+ """The iPhone app the tag's host asks for. Fails rather than guess: the latest mark stays."""
+ source = run("git", "show", f"{tag}:host/src/compat.rs")
+ return re.search(r'pub const MIN_APP: &str = "([^"]+)";', source).group(1)
+
+
+def complete(tag):
+ names = {a["name"] for a in gh_json("release", "view", tag, "--json", "assets")["assets"]}
+ missing = FEEDS - names
+ if missing:
+ print(f"{tag} isn't fully uploaded yet (no {', '.join(sorted(missing))})")
+ return not missing
+
+
+def choose(store, releases, min_app=min_app, complete=complete):
+ """The newest of `releases` (published tags) that is complete and whose MIN_APP the App Store
+ version meets."""
+ for tag in sorted((t for t in releases if parse(t)), key=parse, reverse=True):
+ needs = min_app(tag)
+ if parse(needs) > parse(store):
+ print(f"{tag} needs iPhone {needs}; the App Store has {store}")
+ elif complete(tag):
+ return tag
+ return None
+
+
+def tap(tag):
+ """The Mac app's cask and the host's formula, at `tag`, from that release's templates."""
+ version = tag.removeprefix("v")
+ show = lambda path: run("git", "show", f"{tag}:{path}") + "\n"
+ with tempfile.TemporaryDirectory() as tmp:
+ run("gh", "release", "download", tag, "--repo", REPO, "--pattern", "*.sha256", "--dir", tmp)
+
+ def filled(template, *archives):
+ """`template` at `version`, its sha256 placeholders filled with those of `archives`, in order."""
+ text = re.sub(r'(?m)^ version "[^"]*"', f' version "{version}"', show(template))
+ for name in archives:
+ text = text.replace("REPLACE_WITH_SHA256", Path(tmp, f"{name}.sha256").read_text().split()[0], 1)
+ return text
+
+ files = {
+ "Casks/codync.rb": filled("packaging/homebrew/codync.rb", "codync-macos.dmg"),
+ "Formula/codync-host.rb": filled("packaging/homebrew/codync-host.rb",
+ *(f"codync-host-{p}.tar.gz" for p in HOST_PLATFORMS)),
+ "README.md": show("packaging/homebrew/README.md"),
+ }
+ checkout = Path(tmp, "tap")
+ auth = f"x-access-token:{os.environ['TAP_TOKEN']}@" if os.environ.get("TAP_TOKEN") else ""
+ run("git", "clone", "--depth", "1", f"https://{auth}github.com/{TAP}.git", str(checkout))
+ for path, text in files.items():
+ target = Path(checkout, path)
+ target.parent.mkdir(parents=True, exist_ok=True)
+ target.write_text(text)
+ if not run("git", "status", "--porcelain", cwd=checkout):
+ return
+ print(f"Homebrew tap → {version}")
+ if DRY_RUN:
+ print(run("git", "diff", cwd=checkout))
+ return
+ run("git", "add", "-A", cwd=checkout)
+ run("git", "-c", "user.name=github-actions[bot]",
+ "-c", "user.email=github-actions[bot]@users.noreply.github.com",
+ "commit", "-m", f"Codync {version}", cwd=checkout)
+ run("git", "push", cwd=checkout)
+
+
+def main():
+ store = app_store_version()
+ if not parse(store or ""):
+ print(f"::warning::The App Store lookup gave no version ({store!r}); the latest release stays as it is")
+ return
+ releases = gh_json("release", "list", "--limit", "30", "--exclude-drafts", "--exclude-pre-releases",
+ "--json", "tagName,isLatest")
+ current = next((r["tagName"] for r in releases if r["isLatest"]), None)
+ tag = choose(store, [r["tagName"] for r in releases])
+ if not tag:
+ print(f"::warning::No release works with iPhone {store}; the latest release stays as it is")
+ return
+ if current and parse(tag) < parse(current) and os.environ.get("ALLOW_BACK") != "1":
+ print(f"::warning::{current} needs a newer iPhone app than the App Store's {store}; {tag} becomes latest "
+ "only on a run with allow_back (Actions → Release gate → Run workflow)")
+ return
+ print(f"App Store: {store}; latest release: {current} → {tag}")
+ if tag != current and not DRY_RUN:
+ run("gh", "release", "edit", tag, "--repo", REPO, "--latest")
+ tap(tag)
+
+
+if __name__ == "__main__":
+ main()