ci / typescript (push) Successful in 24m55s
desktop-release / build (--target universal-apple-darwin, dmg,app, darwin-universal, macos) (push) Successful in 19m18s
ci / rust (push) Successful in 24m31s
desktop-release / build (deb,appimage, linux-x86_64, ubuntu-latest) (push) Successful in 1h16m12s
Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
87 lines
4.1 KiB
Bash
Executable File
87 lines
4.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Turns a Mac into the macOS builder for desktop releases (run once, on the Mac that will build).
|
|
# bash ~/Projects/photoreport-build/infra/desktop/macos-runner.sh
|
|
#
|
|
# It installs Gitea's act_runner as a background service of this user (starts at login, restarts if it stops) with
|
|
# the label "macos". From then on every `desktop-v*` release also builds the signed .dmg and the macOS update, and the
|
|
# installed apps update themselves: nobody compiles by hand again. The Mac only has to be on (and logged in) when a
|
|
# release is made; a release made while it is off waits and builds when it comes back.
|
|
#
|
|
# The registration token comes from Gitea (BitReport.pt/photoreport → Definições → Actions → Runners → Criar
|
|
# runner). The script asks for it; it is used once and not saved.
|
|
set -Eeuo pipefail
|
|
|
|
VERSION="${ACT_RUNNER_VERSION:-0.2.11}"
|
|
INSTANCE="${GITEA_URL:-https://git.bitreport.pt}"
|
|
HOME_DIR="$HOME/.photoreport-runner"
|
|
PLIST="$HOME/Library/LaunchAgents/pt.photoreport.act-runner.plist"
|
|
|
|
step() { printf '\n\033[1;34m== %s\033[0m\n' "$*"; }
|
|
|
|
[[ "$(uname)" == Darwin ]] || { echo "Run this on a Mac." >&2; exit 1; }
|
|
xcode-select -p >/dev/null 2>&1 || { xcode-select --install; echo "Install the Xcode command line tools, then run this again." >&2; exit 1; }
|
|
command -v node >/dev/null || { echo "Node.js 22 is needed: brew install node@22" >&2; exit 1; }
|
|
|
|
step "Rust"
|
|
if ! command -v cargo >/dev/null; then curl -fsSL https://sh.rustup.rs | sh -s -- -y; fi
|
|
# shellcheck disable=SC1091
|
|
source "$HOME/.cargo/env"
|
|
rustup target add aarch64-apple-darwin x86_64-apple-darwin wasm32-unknown-unknown >/dev/null
|
|
|
|
step "pnpm"
|
|
command -v pnpm >/dev/null || corepack enable pnpm 2>/dev/null || npm install -g pnpm
|
|
|
|
step "act_runner $VERSION"
|
|
mkdir -p "$HOME_DIR"
|
|
cd "$HOME_DIR"
|
|
arch="$(uname -m)"; [[ "$arch" == "arm64" ]] || arch="amd64"
|
|
if [[ ! -x ./act_runner ]] || ! ./act_runner --version 2>/dev/null | grep -q "$VERSION"; then
|
|
curl -fsSL -o act_runner "https://dl.gitea.com/act_runner/${VERSION}/act_runner-${VERSION}-darwin-${arch}"
|
|
chmod +x act_runner
|
|
fi
|
|
|
|
if [[ ! -f .runner ]]; then
|
|
step "Register with $INSTANCE"
|
|
token="${GITEA_RUNNER_TOKEN:-}"
|
|
if [[ -z "$token" ]]; then read -rsp "Registration token (Gitea → Actions → Runners → Criar runner): " token; echo; fi
|
|
[[ -n "$token" ]] || { echo "No token." >&2; exit 1; }
|
|
./act_runner generate-config > config.yaml
|
|
# One build at a time; jobs run on this Mac directly (no containers on macOS).
|
|
sed -i '' 's/^ capacity: .*/ capacity: 1/' config.yaml
|
|
./act_runner register --no-interactive --config config.yaml --instance "$INSTANCE" --token "$token" \
|
|
--name "$(scutil --get ComputerName | tr ' ' '-')-macos" --labels "macos:host"
|
|
fi
|
|
|
|
step "Background service"
|
|
mkdir -p "$(dirname "$PLIST")"
|
|
cat > "$PLIST" <<PLIST
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>Label</key><string>pt.photoreport.act-runner</string>
|
|
<key>ProgramArguments</key><array><string>$HOME_DIR/act_runner</string><string>daemon</string><string>--config</string><string>$HOME_DIR/config.yaml</string></array>
|
|
<key>WorkingDirectory</key><string>$HOME_DIR</string>
|
|
<key>EnvironmentVariables</key><dict>
|
|
<key>PATH</key><string>$HOME/.cargo/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
|
|
<key>HOME</key><string>$HOME</string>
|
|
</dict>
|
|
<key>RunAtLoad</key><true/>
|
|
<key>KeepAlive</key><true/>
|
|
<key>StandardOutPath</key><string>$HOME_DIR/runner.log</string>
|
|
<key>StandardErrorPath</key><string>$HOME_DIR/runner.log</string>
|
|
</dict>
|
|
</plist>
|
|
PLIST
|
|
launchctl bootout "gui/$(id -u)" "$PLIST" 2>/dev/null || true
|
|
launchctl bootstrap "gui/$(id -u)" "$PLIST"
|
|
|
|
sleep 3
|
|
if launchctl print "gui/$(id -u)/pt.photoreport.act-runner" >/dev/null 2>&1; then
|
|
printf '\n\033[1;32mDone.\033[0m This Mac now builds the macOS version of every desktop release.\n'
|
|
printf 'Log: %s/runner.log Stop: launchctl bootout gui/%s %s\n' "$HOME_DIR" "$(id -u)" "$PLIST"
|
|
else
|
|
echo "The service did not start; see $HOME_DIR/runner.log" >&2
|
|
exit 1
|
|
fi
|