- #!/usr/bin/env bash
- # Build, sign (Developer ID Application), and notarise the macOS arm64 binary
- # for Forge's `binaries-macos` protected landing job (mirroring Forge's own
- # signing flow on `forge-mac-1`).
- #
- # Usage:
- # ci/binaries/macos/build.sh <commit-sha>
- #
- # Environment:
- # FORGE_SIGNING "keychain" (Developer ID + notarytool) or "adhoc" (default)
- # FORGE_SIGNING_TEAM Apple Team ID (default: 4SKW2Z97A2)
- # FORGE_SIGNING_ID codesign identity (default: "Developer ID Application: Cleyrop ($FORGE_SIGNING_TEAM)")
- # NOTARY_PROFILE keychain profile for `xcrun notarytool` (default: forge-notary)
- # RONEO_MACOS_RECORD output metadata JSON (default: roneo-macos.json)
- # RONEO_NOTARISATIONS notarisation record JSON (default: notarisations.json)
- set -euo pipefail
- COMMIT="${1:-$(git rev-parse HEAD)}"
- TARGET_TRIPLE="aarch64-apple-darwin"
- SIGNING_MODE="${FORGE_SIGNING:-adhoc}"
- SIGNING_TEAM="${FORGE_SIGNING_TEAM:-4SKW2Z97A2}"
- SIGNING_ID="${FORGE_SIGNING_ID:-Developer ID Application: Cleyrop (${SIGNING_TEAM})}"
- NOTARY_PROFILE="${NOTARY_PROFILE:-forge-notary}"
- RECORD_PATH="${RONEO_MACOS_RECORD:-roneo-macos.json}"
- NOTARISATIONS_PATH="${RONEO_NOTARISATIONS:-notarisations.json}"
- BUNDLE_ID="com.cleyrop.roneo"
- printf '[]\n' > "$NOTARISATIONS_PATH"
- RUSTFLAGS="--remap-path-prefix=${HOME}=/build --remap-path-prefix=$(pwd)=/src -C link-arg=-Wl,-S,-x,-dead_strip" \
- cargo build --release --locked --target "$TARGET_TRIPLE" -p roneo-cli --bin roneo
- BIN="target/${TARGET_TRIPLE}/release/roneo"
- test -x "$BIN"
- if [ "$SIGNING_MODE" = "keychain" ]; then
- codesign --force --options runtime --timestamp \
- --identifier "$BUNDLE_ID" \
- --sign "$SIGNING_ID" \
- "$BIN"
- codesign --verify --strict --verbose=2 "$BIN"
- TMP_ZIP="$(mktemp -t roneo-notary.XXXXXX.zip)"
- trap 'rm -f "$TMP_ZIP"' EXIT
- ditto -c -k --keepParent "$BIN" "$TMP_ZIP"
- NOTARY_JSON="$(xcrun notarytool submit "$TMP_ZIP" \
- --keychain-profile "$NOTARY_PROFILE" \
- --wait \
- --output-format json)"
- printf '[%s]\n' "$NOTARY_JSON" > "$NOTARISATIONS_PATH"
- STATUS="$(printf '%s' "$NOTARY_JSON" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("status",""))')"
- if [ "$STATUS" != "Accepted" ]; then
- printf 'error: Apple notarisation failed (status=%s)\n' "$STATUS" >&2
- exit 1
- fi
- else
- codesign --force --sign - --identifier "$BUNDLE_ID" "$BIN"
- codesign --verify --strict "$BIN"
- fi
- SHA256="$(shasum -a 256 "$BIN" | awk '{print $1}')"
- SIZE="$(stat -f%z "$BIN")"
- "$BIN" --version
- python3 - "$COMMIT" "$SHA256" "$SIZE" "$SIGNING_MODE" "$RECORD_PATH" <<'PY'
- import json, sys
- commit, sha256, size, mode, out_path = sys.argv[1:]
- record = {
- "commit": commit,
- "bin": "roneo",
- "os": "darwin",
- "arch": "arm64",
- "sha256": sha256,
- "size": int(size),
- "signing": mode,
- }
- with open(out_path, "w") as f:
- json.dump(record, f, indent=2)
- f.write("\n")
- PY