code.cleyrop.techFRENBrowse the repositories

At commit 98ff76d

82 lines · 2.9 KiBShellRaw
  1. #!/usr/bin/env bash
  2. # Build, sign (Developer ID Application), and notarise the macOS arm64 binary
  3. # for Forge's `binaries-macos` protected landing job (mirroring Forge's own
  4. # signing flow on `forge-mac-1`).
  5. #
  6. # Usage:
  7. # ci/binaries/macos/build.sh <commit-sha>
  8. #
  9. # Environment:
  10. # FORGE_SIGNING "keychain" (Developer ID + notarytool) or "adhoc" (default)
  11. # FORGE_SIGNING_TEAM Apple Team ID (default: 4SKW2Z97A2)
  12. # FORGE_SIGNING_ID codesign identity (default: "Developer ID Application: Cleyrop ($FORGE_SIGNING_TEAM)")
  13. # NOTARY_PROFILE keychain profile for `xcrun notarytool` (default: forge-notary)
  14. # RONEO_MACOS_RECORD output metadata JSON (default: roneo-macos.json)
  15. # RONEO_NOTARISATIONS notarisation record JSON (default: notarisations.json)
  16. set -euo pipefail
  17. COMMIT="${1:-$(git rev-parse HEAD)}"
  18. TARGET_TRIPLE="aarch64-apple-darwin"
  19. SIGNING_MODE="${FORGE_SIGNING:-adhoc}"
  20. SIGNING_TEAM="${FORGE_SIGNING_TEAM:-4SKW2Z97A2}"
  21. SIGNING_ID="${FORGE_SIGNING_ID:-Developer ID Application: Cleyrop (${SIGNING_TEAM})}"
  22. NOTARY_PROFILE="${NOTARY_PROFILE:-forge-notary}"
  23. RECORD_PATH="${RONEO_MACOS_RECORD:-roneo-macos.json}"
  24. NOTARISATIONS_PATH="${RONEO_NOTARISATIONS:-notarisations.json}"
  25. BUNDLE_ID="com.cleyrop.roneo"
  26. printf '[]\n' > "$NOTARISATIONS_PATH"
  27. RUSTFLAGS="--remap-path-prefix=${HOME}=/build --remap-path-prefix=$(pwd)=/src -C link-arg=-Wl,-S,-x,-dead_strip" \
  28. cargo build --release --locked --target "$TARGET_TRIPLE" -p roneo-cli --bin roneo
  29. BIN="target/${TARGET_TRIPLE}/release/roneo"
  30. test -x "$BIN"
  31. if [ "$SIGNING_MODE" = "keychain" ]; then
  32. codesign --force --options runtime --timestamp \
  33. --identifier "$BUNDLE_ID" \
  34. --sign "$SIGNING_ID" \
  35. "$BIN"
  36. codesign --verify --strict --verbose=2 "$BIN"
  37. TMP_ZIP="$(mktemp -t roneo-notary.XXXXXX.zip)"
  38. trap 'rm -f "$TMP_ZIP"' EXIT
  39. ditto -c -k --keepParent "$BIN" "$TMP_ZIP"
  40. NOTARY_JSON="$(xcrun notarytool submit "$TMP_ZIP" \
  41. --keychain-profile "$NOTARY_PROFILE" \
  42. --wait \
  43. --output-format json)"
  44. printf '[%s]\n' "$NOTARY_JSON" > "$NOTARISATIONS_PATH"
  45. STATUS="$(printf '%s' "$NOTARY_JSON" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("status",""))')"
  46. if [ "$STATUS" != "Accepted" ]; then
  47. printf 'error: Apple notarisation failed (status=%s)\n' "$STATUS" >&2
  48. exit 1
  49. fi
  50. else
  51. codesign --force --sign - --identifier "$BUNDLE_ID" "$BIN"
  52. codesign --verify --strict "$BIN"
  53. fi
  54. SHA256="$(shasum -a 256 "$BIN" | awk '{print $1}')"
  55. SIZE="$(stat -f%z "$BIN")"
  56. "$BIN" --version
  57. python3 - "$COMMIT" "$SHA256" "$SIZE" "$SIGNING_MODE" "$RECORD_PATH" <<'PY'
  58. import json, sys
  59. commit, sha256, size, mode, out_path = sys.argv[1:]
  60. record = {
  61. "commit": commit,
  62. "bin": "roneo",
  63. "os": "darwin",
  64. "arch": "arm64",
  65. "sha256": sha256,
  66. "size": int(size),
  67. "signing": mode,
  68. }
  69. with open(out_path, "w") as f:
  70. json.dump(record, f, indent=2)
  71. f.write("\n")
  72. PY