Python
The openworker program for the Mac
Rohit C Prasad857e4e7b292f
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 2db9b7f7..d1421df1 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -1,5 +1,6 @@# Desktop release builds — macOS (.dmg, arm64 + Intel) and Windows (.msi + NSIS .exe) — and-# the Linux `openworker` program (.tar.gz, x86_64 + aarch64; packaging/build_linux.sh).+# the `openworker` command-line program for Linux (.tar.gz, x86_64 + aarch64;+# packaging/build_linux.sh) and for macOS (.tar.gz, arm64 + x86_64; packaging/build_macos_cli.sh).## CI calls the SAME scripts developers run locally (packaging/build_dmg.sh and# build_windows.ps1); this file only provisions the toolchain (Node, Rust, a Python venv at@@ -117,6 +118,9 @@ jobs:fiunset APPLE_API_KEY_CONTENTbash packaging/build_dmg.sh+ # The command-line program for the Mac, from the same venv and identity: signed+ # and notarized when the secrets are present.+ bash packaging/build_macos_cli.sh- name: Build .msi + NSIS .exe (Windows)if: runner.os == 'Windows'@@ -147,6 +151,11 @@ jobs:cp "$BUNDLE"/macos/OpenWorker.app.tar.gz out/OpenWorker-${{ matrix.slug }}.app.tar.gzcp "$BUNDLE"/macos/OpenWorker.app.tar.gz.sig out/OpenWorker-${{ matrix.slug }}.app.tar.gz.sigfi+ # The command-line program, named by uname -m (arm64, x86_64) as install.sh asks.+ ARCH=$(uname -m)+ cp packaging/dist/openworker-*-macos-"$ARCH".tar.gz* out/+ cp packaging/dist/openworker-*-macos-"$ARCH".tar.gz out/openworker-macos-"$ARCH".tar.gz+ (cd out && shasum -a 256 openworker-macos-"$ARCH".tar.gz > openworker-macos-"$ARCH".tar.gz.sha256)fils -la outdiff --git a/docs/remote-machines.md b/docs/remote-machines.mdindex 6e735231..9be4ef3f 100644--- a/docs/remote-machines.md+++ b/docs/remote-machines.md@@ -27,19 +27,15 @@ A few things are true by design, before any setup:## 1. Install on the machine-On the remote machine:+On the remote machine (Linux or a Mac):```bash-sudo apt update && sudo apt install -y git curl python3-venv python3-pip-python3 -m venv ~/ow-venv-~/ow-venv/bin/pip install "git+https://github.com/andrewyng/openworker.git"+curl -fsSL https://openworker.com/install.sh | sh```-Optional but recommended, so `openworker` is on your PATH:--```bash-echo 'export PATH=$HOME/ow-venv/bin:$PATH' >> ~/.bashrc && source ~/.bashrc-```+This downloads the `openworker` program for the machine into `~/.local/share/openworker`+and links it into `~/.local/bin`. No Python is needed. The script tells you if+`~/.local/bin` is not on your PATH yet.Check it:diff --git a/packaging/build_macos_cli.sh b/packaging/build_macos_cli.shnew file mode 100755index 00000000..b22ad56b--- /dev/null+++ b/packaging/build_macos_cli.sh@@ -0,0 +1,110 @@+#!/usr/bin/env bash+# Build the macOS `openworker` program: one folder with the program and its support files+# (no Python needed on the Mac), packed as openworker-<version>-macos-<arch>.tar.gz.+#+# 1. PyInstaller with packaging/openworker-server.spec, OPENWORKER_BUNDLE=cli: the whole+# command line as the entry point (the same freeze as the Linux program).+# 2. With APPLE_SIGNING_IDENTITY set: sign every Mach-O file (hardened runtime), submit+# the folder to Apple's notary service, and check it the way Gatekeeper does. The+# ticket for a command-line program lives with Apple, not in the files, so there is+# nothing to staple. Without the identity the program is unsigned: fine for your own+# Mac, not for distribution.+# 3. Pack the folder and write its SHA-256 next to it, in packaging/dist/.+#+# Prerequisites: the .venv that build_dmg.sh uses (the package with the bedrock and+# openshell extras, pyinstaller, typer), Xcode command line tools. Notary credentials as+# for build_dmg.sh: NOTARYTOOL_API_KEY_PATH / _KEY_ID / _ISSUER_ID, the APPLE_API_* names+# from CI, or `.ocw-notary.env` one directory above the repo. OCW_SKIP_NOTARIZE=1 signs+# but does not notarize.+#+# Install on a Mac (packaging/install.sh does this):+# tar -xzf openworker-<version>-macos-<arch>.tar.gz -C ~/.local/share+# ln -sf ~/.local/share/openworker/openworker ~/.local/bin/openworker+set -euo pipefail++HERE="$(cd "$(dirname "$0")" && pwd)"+ROOT="$(dirname "$HERE")"+OUT="$HERE/dist"+VENV="$ROOT/.venv"+VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' "$ROOT/pyproject.toml" | head -1)"+ARCH="$(uname -m)" # arm64 or x86_64+NAME="openworker-$VERSION-macos-$ARCH"+PROGRAM="$OUT/openworker"++[ "$(uname -s)" = "Darwin" ] || { echo "ERROR: this script builds on macOS only (Linux: build_linux.sh)" >&2; exit 1; }+[ -x "$VENV/bin/pyinstaller" ] || { echo "ERROR: $VENV has no pyinstaller; see the VENV PREREQS in build_dmg.sh" >&2; exit 1; }+"$VENV/bin/python" -c "import grpc" 2>/dev/null || { echo "ERROR: grpcio is missing from .venv; install the openshell extra" >&2; exit 1; }++mkdir -p "$OUT"+rm -rf "$PROGRAM" "$OUT/$NAME.tar.gz" "$OUT/$NAME.tar.gz.sha256" "$OUT/$NAME.zip"++echo "==> [1/3] PyInstaller: $NAME"+OPENWORKER_BUNDLE=cli "$VENV/bin/pyinstaller" --noconfirm --clean --log-level WARN \+ --distpath "$OUT" --workpath "$HERE/build" "$HERE/openworker-server.spec"+# No *.framework may ship: codesign and the notary service treat it as a bundle, which this+# flattened layout can never satisfy (the sidecar learned this; see build_dmg.sh). The+# interpreter PyInstaller loads is _internal/Python, so the framework copy is a duplicate.+rm -rf "$PROGRAM/_internal/Python.framework"+if [ -n "$(find "$PROGRAM" -type d -name "*.framework" | head -1)" ]; then+ echo "ERROR: a .framework is in the program folder; it cannot pass notarization" >&2+ exit 1+fi+chmod +x "$PROGRAM/openworker"++if [ -n "${APPLE_SIGNING_IDENTITY:-}" ]; then+ echo "==> [2/3] signing"+ # Every Mach-O gets its own file signature with the hardened runtime; the entry point+ # also gets the entitlements (disable-library-validation: the bundled Python libraries+ # carry python.org's Team ID).+ find "$PROGRAM" -type f ! -name "openworker" \+ ! -name "*.py" ! -name "*.pyc" ! -name "*.txt" ! -name "*.pem" ! -name "*.json" \+ -print0 | while IFS= read -r -d '' f; do+ file -b "$f" | grep -q "Mach-O" || continue+ codesign --force --sign "$APPLE_SIGNING_IDENTITY" --timestamp --options runtime "$f"+ done+ codesign --force --sign "$APPLE_SIGNING_IDENTITY" --timestamp --options runtime \+ --entitlements "$ROOT/surfaces/gui/src-tauri/entitlements.plist" "$PROGRAM/openworker"++ if [ "${OCW_SKIP_NOTARIZE:-}" = "1" ]; then+ echo " OCW_SKIP_NOTARIZE=1: signed, NOT notarized (do not distribute)"+ else+ NOTARYTOOL_API_KEY_PATH="${NOTARYTOOL_API_KEY_PATH:-${APPLE_API_KEY_PATH:-}}"+ NOTARYTOOL_API_KEY_ID="${NOTARYTOOL_API_KEY_ID:-${APPLE_API_KEY:-}}"+ NOTARYTOOL_API_ISSUER_ID="${NOTARYTOOL_API_ISSUER_ID:-${APPLE_API_ISSUER:-}}"+ NOTARY_ENV="${OCW_NOTARY_ENV:-$ROOT/../.ocw-notary.env}"+ if [ -z "${NOTARYTOOL_API_KEY_PATH:-}" ] && [ -f "$NOTARY_ENV" ]; then+ set -a; # shellcheck disable=SC1090+ source "$NOTARY_ENV"; set +a+ fi+ if [ -n "${NOTARYTOOL_API_KEY_PATH:-}" ] && [ -n "${NOTARYTOOL_API_KEY_ID:-}" ] \+ && [ -n "${NOTARYTOOL_API_ISSUER_ID:-}" ]; then+ echo " notarizing"+ # The notary service takes a zip of the folder. The ticket is recorded with Apple;+ # the files themselves do not change, so the tarball packed below is what was checked.+ ditto -c -k --keepParent "$PROGRAM" "$OUT/$NAME.zip"+ xcrun notarytool submit "$OUT/$NAME.zip" \+ --key "$NOTARYTOOL_API_KEY_PATH" \+ --key-id "$NOTARYTOOL_API_KEY_ID" \+ --issuer "$NOTARYTOOL_API_ISSUER_ID" \+ --wait+ rm -f "$OUT/$NAME.zip"+ # `notarytool submit --wait` exits non-zero when Apple does not accept. spctl cannot+ # assess a bare command-line program ("does not seem to be an app"), so the local+ # check is the signature itself.+ codesign --verify --strict --deep -v "$PROGRAM/openworker"+ echo " notarized and accepted"+ else+ echo " WARNING: signed but NOT notarized. Provide NOTARYTOOL_API_KEY_PATH/_KEY_ID/_ISSUER_ID"+ echo " (env, \$OCW_NOTARY_ENV, or $NOTARY_ENV)."+ fi+ fi+else+ echo "==> [2/3] unsigned (set APPLE_SIGNING_IDENTITY for a distributable program)"+fi++echo "==> [3/3] packing"+"$PROGRAM/openworker" version+tar -C "$OUT" -czf "$OUT/$NAME.tar.gz" openworker+(cd "$OUT" && shasum -a 256 "$NAME.tar.gz" > "$NAME.tar.gz.sha256")+ls -la "$OUT/$NAME.tar.gz"+cat "$OUT/$NAME.tar.gz.sha256"diff --git a/packaging/install.sh b/packaging/install.shindex de90dd95..69c16459 100755--- a/packaging/install.sh+++ b/packaging/install.sh@@ -5,11 +5,11 @@## Installs the `openworker` command for the current user (no sudo). Re-run it to upgrade.#-# On Linux (x86_64, aarch64; glibc 2.31 or newer) it downloads the `openworker` program from-# the GitHub release, checks its SHA-256, unpacks it into ~/.local/share/openworker and links-# it into ~/.local/bin. No Python is needed.+# On Linux (x86_64, aarch64; glibc 2.31 or newer) and on macOS (Apple Silicon, Intel) it+# downloads the `openworker` program from the GitHub release, checks its SHA-256, unpacks it+# into ~/.local/share/openworker and links it into ~/.local/bin. No Python is needed.#-# Elsewhere (macOS, other Linux) it installs the Python package: with `uv` when present,+# Elsewhere (other Linux) it installs the Python package: with `uv` when present,# `pipx` when that is what the machine has, and otherwise it installs `uv` first (uv brings# its own Python, so the system's Python version does not matter).#@@ -66,8 +66,12 @@ main() {say " 3. To keep it running in the background: openworker machine service install"}-# The program is built for Linux with glibc 2.31 or newer, on x86_64 and aarch64.+# The program is built for macOS on Apple Silicon and Intel, and for Linux with glibc 2.31+# or newer on x86_64 and aarch64.program_runs_here() {+ if [ "$(uname -s)" = "Darwin" ]; then+ case "$(uname -m)" in arm64 | x86_64) return 0 ;; *) return 1 ;; esac+ fi[ "$(uname -s)" = "Linux" ] || return 1case "$(uname -m)" in x86_64 | aarch64) ;; *) return 1 ;; esacglibc="$(getconf GNU_LIBC_VERSION 2>/dev/null | awk '{print $2}')"@@ -80,6 +84,7 @@ program_runs_here() {install_program() {arch="$(uname -m)"+ case "$(uname -s)" in Darwin) os="macos" ;; *) os="linux" ;; esaccommand -v curl >/dev/null 2>&1 || fail "curl is needed to download OpenWorker. Install curl, then run this again."command -v tar >/dev/null 2>&1 || fail "tar is needed to unpack OpenWorker."if command -v sha256sum >/dev/null 2>&1; then@@ -91,10 +96,10 @@ install_program() {fiif [ -n "${OPENWORKER_VERSION:-}" ]; then- file="openworker-${OPENWORKER_VERSION}-linux-${arch}.tar.gz"+ file="openworker-${OPENWORKER_VERSION}-${os}-${arch}.tar.gz"base="${OPENWORKER_DOWNLOAD_URL:-$repo/releases/download/v${OPENWORKER_VERSION}}"else- file="openworker-linux-${arch}.tar.gz" # the stable name of the latest release+ file="openworker-${os}-${arch}.tar.gz" # the stable name of the latest releasebase="${OPENWORKER_DOWNLOAD_URL:-$repo/releases/latest/download}"fi@@ -137,6 +142,11 @@ install_program() {for unit in $units; dosay "Restart the running machine to use it: systemctl --user restart $unit"done+ elif command -v launchctl >/dev/null 2>&1; then+ labels="$(launchctl list 2>/dev/null | awk '$3 ~ /^com\.openworker\.machine\./ {print $3}')"+ for label in $labels; do+ say "Restart the running machine to use it: launchctl kickstart -k gui/$(id -u)/$label"+ donefi}diff --git a/tests/test_cli_surface.py b/tests/test_cli_surface.pyindex 170e98db..3be4b603 100644--- a/tests/test_cli_surface.py+++ b/tests/test_cli_surface.py@@ -233,3 +233,20 @@ def test_install_script_refuses_an_unsupported_os(tmp_path):env = {"PATH": f"{tmp_path}:/usr/bin:/bin", "HOME": str(tmp_path)}done = subprocess.run(["sh", str(INSTALL_SH)], env=env, capture_output=True, text=True)assert done.returncode == 1 and "Linux and macOS" in done.stderr+++def test_install_script_downloads_the_program_on_a_mac(tmp_path):+ """A Mac gets the program, like Linux, not the Python package (which needs PyPI)."""+ fake = tmp_path / "uname"+ fake.write_text('#!/bin/sh\ncase "$1" in -m) echo arm64 ;; *) echo Darwin ;; esac\n')+ fake.chmod(0o755)+ # A curl that records the first address asked for and fails, so nothing is installed.+ curl = tmp_path / "curl"+ curl.write_text('#!/bin/sh\nfor a in "$@"; do case "$a" in http*) echo "$a" > "$ASKED" ;; esac; done\nexit 22\n')+ curl.chmod(0o755)+ env = {"PATH": f"{tmp_path}:/usr/bin:/bin", "HOME": str(tmp_path), "ASKED": str(tmp_path / "asked")}+ done = subprocess.run(["sh", str(INSTALL_SH)], env=env, capture_output=True, text=True)+ assert done.returncode == 1 and "could not download" in done.stderr+ asked = (tmp_path / "asked").read_text().strip()+ assert asked.endswith("/releases/latest/download/openworker-macos-arm64.tar.gz")+ assert "uv" not in done.stdout and "pipx" not in done.stdout