The installer job was waiting on a commented matrix row, USB stayed on Image Capture, face detection could not read the Windows CPU, and notarisation had nowhere to put an Apple account.
109 lines
5.9 KiB
Bash
Executable File
109 lines
5.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Builds the macOS installer (PhotoReport.dmg, Apple Silicon and Intel) on a Mac, from a fresh clone.
|
|
# git clone https://git.bitreport.pt/BitReport.pt/photoreport.git ~/Projects/photoreport-build
|
|
# bash ~/Projects/photoreport-build/infra/desktop/build-macos.sh
|
|
# Installs what is missing (Rust, pnpm, the wasm tools) and opens the folder with the .dmg at the end.
|
|
set -Eeuo pipefail
|
|
|
|
main() {
|
|
DIR="${PHOTOREPORT_BUILD_DIR:-$HOME/Projects/photoreport-build}"
|
|
API="${VITE_API_URL:-https://api.next.photoreport.pt}"
|
|
# The installed app shows the live web app from here, so it updates itself with every web deploy.
|
|
export PHOTOREPORT_APP_URL="${PHOTOREPORT_APP_URL:-https://app.next.photoreport.pt}"
|
|
|
|
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 "Source ($DIR)"
|
|
# The build may refresh the desktop Cargo.lock; drop that so the pull never stops on it.
|
|
if [[ -d "$DIR/.git" ]]; then git -C "$DIR" checkout -- apps/desktop/src-tauri/Cargo.lock 2>/dev/null || true; git -C "$DIR" pull --ff-only; else mkdir -p "$(dirname "$DIR")" && git clone https://git.bitreport.pt/BitReport.pt/photoreport.git "$DIR"; fi
|
|
cd "$DIR"
|
|
# The pull may have changed this very script: carry on with the new version, not the one already in memory.
|
|
if [[ -z "${PHOTOREPORT_BUILD_REEXEC:-}" ]]; then PHOTOREPORT_BUILD_REEXEC=1 exec bash "$DIR/infra/desktop/build-macos.sh"; fi
|
|
|
|
step "Photo engine (WebAssembly)"
|
|
want="$(sed -n 's/^wasm-bindgen = "=\(.*\)"/\1/p' engine/wasm/Cargo.toml)"
|
|
[[ "$(wasm-bindgen --version 2>/dev/null | awk '{print $2}')" == "$want" ]] || cargo install wasm-bindgen-cli --version "$want" --locked
|
|
bash infra/engine/build-wasm.sh
|
|
|
|
step "App"
|
|
pnpm install --frozen-lockfile
|
|
pnpm --filter "./packages/*" build
|
|
pnpm --filter @photoreport/desktop icons
|
|
|
|
step "Installer (API: $API)"
|
|
# With the release key (TAURI_SIGNING_PRIVATE_KEY, and TAURI_UPDATER_PUBKEY for the matching public key) the build is
|
|
# also signed for self-updates; without it the app is built as before and never updates itself.
|
|
extra=(--bundles dmg)
|
|
if [[ -n "${TAURI_SIGNING_PRIVATE_KEY:-}" && -n "${TAURI_UPDATER_PUBKEY:-}" ]]; then
|
|
export PHOTOREPORT_UPDATER_PUBKEY="$TAURI_UPDATER_PUBKEY"
|
|
# The bundler checks each signature against plugins.updater.pubkey, so the public key goes into the config too.
|
|
extra=(--bundles dmg,app --config "$(node -e 'console.log(JSON.stringify({bundle:{createUpdaterArtifacts:true},plugins:{updater:{pubkey:process.env.PHOTOREPORT_UPDATER_PUBKEY}}}))')")
|
|
fi
|
|
step "Code signing"
|
|
# macOS remembers the folders an app may open (Desktop, Documents, cards) by its signature. Unsigned, every build
|
|
# (and every update) looks like a new app and asks again, once per access. Signed always with the same identity, the
|
|
# answer is kept. With an Apple Developer ID set in APPLE_SIGNING_IDENTITY that one is used; otherwise a local
|
|
# identity, made once in the login keychain, the same for every build on this Mac.
|
|
if [[ -z "${APPLE_SIGNING_IDENTITY:-}" ]]; then
|
|
local_id="PhotoReport Local Signing"
|
|
if ! security find-identity -p codesigning | grep -q "\"$local_id\""; then
|
|
tmp="$(mktemp -d)"
|
|
cat >"$tmp/cert.cfg" <<CFG
|
|
[req]
|
|
distinguished_name = dn
|
|
x509_extensions = ext
|
|
prompt = no
|
|
[dn]
|
|
CN = $local_id
|
|
[ext]
|
|
keyUsage = critical, digitalSignature
|
|
extendedKeyUsage = critical, codeSigning
|
|
basicConstraints = critical, CA:false
|
|
CFG
|
|
# The system's LibreSSL: its .p12 is one the keychain imports (OpenSSL 3's default one is not).
|
|
/usr/bin/openssl req -x509 -newkey rsa:2048 -nodes -days 3650 -keyout "$tmp/key.pem" -out "$tmp/cert.pem" -config "$tmp/cert.cfg" 2>/dev/null
|
|
/usr/bin/openssl pkcs12 -export -inkey "$tmp/key.pem" -in "$tmp/cert.pem" -name "$local_id" -out "$tmp/id.p12" -passout pass:photoreport
|
|
security import "$tmp/id.p12" -k "$HOME/Library/Keychains/login.keychain-db" -P photoreport -T /usr/bin/codesign
|
|
echo "macOS asks for your password once, to trust this certificate for signing:"
|
|
security add-trusted-cert -r trustRoot -p codeSign -k "$HOME/Library/Keychains/login.keychain-db" "$tmp/cert.pem"
|
|
rm -rf "$tmp"
|
|
fi
|
|
export APPLE_SIGNING_IDENTITY="$local_id"
|
|
# Not a Developer ID: no notarisation, so no hardened runtime (it would refuse the bundled ONNX library).
|
|
extra+=(--config '{"bundle":{"macOS":{"hardenedRuntime":false}}}')
|
|
else
|
|
# Developer ID. Notarisation (when APPLE_ID / APPLE_PASSWORD / APPLE_TEAM_ID, or the API key, are set)
|
|
# requires the hardened runtime. The entitlements let the bundled ONNX library load.
|
|
extra+=(--config '{"bundle":{"macOS":{"hardenedRuntime":true,"entitlements":"entitlements.plist"}}}')
|
|
fi
|
|
echo "Signing as: $APPLE_SIGNING_IDENTITY"
|
|
|
|
VITE_API_URL="$API" PHOTOREPORT_API_URL="$API" pnpm --filter @photoreport/desktop exec tauri build --target universal-apple-darwin "${extra[@]}"
|
|
BUNDLE="apps/desktop/src-tauri/target/universal-apple-darwin/release/bundle"
|
|
OUT="$BUNDLE/dmg"
|
|
if [[ -n "${PHOTOREPORT_UPDATER_PUBKEY:-}" ]]; then
|
|
version="$(node -p 'require("./apps/desktop/src-tauri/tauri.conf.json").version')"
|
|
node infra/desktop/update-manifest.mjs "$BUNDLE" darwin-universal "$version"
|
|
echo "For installed apps to update: attach the .dmg, the .app.tar.gz, its .sig and update-darwin-universal.json to the"
|
|
echo "desktop-v$version release on Gitea."
|
|
fi
|
|
step "Done"
|
|
ls -lh "$OUT"/*.dmg
|
|
open "$OUT"
|
|
}
|
|
|
|
main "$@"
|