|
| 1 | +#!/usr/bin/env bash |
| 2 | +# One command to try the Forge -> electron-builder macOS auto-update locally |
| 3 | +# against the CI-signed builds, no local signing. It downloads the old Forge |
| 4 | +# (v0.55.132, versioned 1.0.0) app and the new (2.0.0) feed from the latest green |
| 5 | +# Code Update E2E run, serves the feed, and launches the Forge app pointed at it. |
| 6 | +# Its genuine built-in Squirrel.Mac client checks the feed, downloads 2.0.0, and |
| 7 | +# on restart swaps + relaunches into 2.0.0 -- the path real Forge users take. |
| 8 | +# |
| 9 | +# Squirrel verifies signatures cryptographically, so the CI-signed pair updates |
| 10 | +# here without the cert being in your keychain. |
| 11 | +# |
| 12 | +# Usage: |
| 13 | +# bash scripts/dev-update/run-from-ci-forge.sh [run-id] |
| 14 | +# AUTOMATED=1 bash scripts/dev-update/run-from-ci-forge.sh # run the Playwright spec instead |
| 15 | +set -euo pipefail |
| 16 | + |
| 17 | +cd "$(dirname "$0")/../.." |
| 18 | + |
| 19 | +command -v gh >/dev/null || { |
| 20 | + echo "gh (GitHub CLI) is required and must be authenticated" >&2 |
| 21 | + exit 1 |
| 22 | +} |
| 23 | + |
| 24 | +if pgrep -x "PostHog Code" >/dev/null; then |
| 25 | + echo "PostHog Code is already running. Quit it first; the test build shares its single-instance lock and data dir." >&2 |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +RUN_ID="${1:-$(gh run list --workflow=code-update-e2e.yml --status success -L 1 --json databaseId -q '.[0].databaseId')}" |
| 30 | +[[ -n "$RUN_ID" ]] || { |
| 31 | + echo "no successful Code Update E2E run found; pass a run id explicitly" >&2 |
| 32 | + exit 1 |
| 33 | +} |
| 34 | +echo "==> using CI run $RUN_ID" |
| 35 | + |
| 36 | +TMP="$(mktemp -d)" |
| 37 | +cleanup() { |
| 38 | + [[ -n "${SERVE_PID:-}" ]] && kill "$SERVE_PID" 2>/dev/null || true |
| 39 | + rm -rf "$TMP" |
| 40 | +} |
| 41 | +trap cleanup EXIT |
| 42 | + |
| 43 | +echo "==> downloading signed builds from CI" |
| 44 | +gh run download "$RUN_ID" -n update-old-forge-build-1.0.0 -D "$TMP/old" |
| 45 | +gh run download "$RUN_ID" -n update-new-build-2.0.0 -D "$TMP/new" |
| 46 | + |
| 47 | +OLD_ZIP="$(find "$TMP/old" -name '*.zip' | head -1)" |
| 48 | +FEED_YML="$(find "$TMP/new" -name latest-mac.yml | head -1)" |
| 49 | +[[ -n "$OLD_ZIP" ]] || { |
| 50 | + echo "old Forge app zip not found in artifact" >&2 |
| 51 | + exit 1 |
| 52 | +} |
| 53 | +[[ -n "$FEED_YML" ]] || { |
| 54 | + echo "latest-mac.yml not found in new build artifact" >&2 |
| 55 | + exit 1 |
| 56 | +} |
| 57 | + |
| 58 | +echo "==> old Forge 1.0.0 app -> out/old-forge" |
| 59 | +rm -rf out/old-forge && mkdir -p out/old-forge |
| 60 | +ditto -x -k "$OLD_ZIP" out/old-forge |
| 61 | +xattr -dr com.apple.quarantine "out/old-forge/PostHog Code.app" 2>/dev/null || true |
| 62 | + |
| 63 | +# The Squirrel swap only completes if the running app's signature is intact, so |
| 64 | +# fail loudly here rather than time out mid-swap if the artifact arrived corrupt. |
| 65 | +echo "==> verifying the CI signature survived transport" |
| 66 | +codesign --verify --strict "out/old-forge/PostHog Code.app" || { |
| 67 | + echo "old Forge app failed signature verification; the Squirrel swap will not complete" >&2 |
| 68 | + exit 1 |
| 69 | +} |
| 70 | + |
| 71 | +echo "==> new 2.0.0 feed -> out/dev-update-feed" |
| 72 | +rm -rf out/dev-update-feed && mkdir -p out/dev-update-feed |
| 73 | +cp "$(dirname "$FEED_YML")"/* out/dev-update-feed/ |
| 74 | + |
| 75 | +if [[ "${AUTOMATED:-}" == "1" ]]; then |
| 76 | + echo "==> running the automated Forge update test" |
| 77 | + pnpm exec playwright test --config=tests/e2e/playwright.update-forge.config.ts |
| 78 | + exit $? |
| 79 | +fi |
| 80 | + |
| 81 | +PORT="${PORT:-8788}" |
| 82 | +node scripts/dev-update/serve.mjs out/dev-update-feed "$PORT" & |
| 83 | +SERVE_PID=$! |
| 84 | + |
| 85 | +APP_LOG="out/run-from-ci-forge-app.log" |
| 86 | +echo |
| 87 | +echo "==> launching Forge PostHog Code 1.0.0 (feed http://127.0.0.1:$PORT)" |
| 88 | +echo " Its built-in Squirrel.Mac client downloads 2.0.0 in the background." |
| 89 | +echo " When prompted, click Restart (or quit and reopen) to apply the swap." |
| 90 | +echo " It relaunches into 2.0.0. Quit the app (or Ctrl+C) to finish." |
| 91 | +echo " App output: $APP_LOG update log: ~/.posthog-code/logs/main.log" |
| 92 | +echo |
| 93 | +POSTHOG_E2E_UPDATE_HOST="http://127.0.0.1:$PORT" \ |
| 94 | + "out/old-forge/PostHog Code.app/Contents/MacOS/PostHog Code" >"$APP_LOG" 2>&1 || true |
| 95 | + |
| 96 | +echo "==> app exited; cleaning up" |
0 commit comments