| new file mode 100755 |
| index 0000000..dedab93 |
| --- /dev/null |
| +++ b/native/scripts/release-mac.sh |
| @@ -0,0 +1,152 @@ |
| +#!/bin/zsh |
| +# Base for the Mac, released: a release build set in Timeless Sans, signed |
| +# with Developer ID (Base's profile embedded), notarized, stapled, checked |
| +# by Gatekeeper, then published to the Sparkle feed on |
| +# oficina/native-releases (base/appcast.xml) with the archive as a release |
| +# asset. Adapted from release-equipo-0.1.5.sh (2026-11-19). |
| +# |
| +# native/scripts/release-mac.sh VERSION BUILD # the plan |
| +# native/scripts/release-mac.sh VERSION BUILD --publish # do it |
| +# |
| +# The plan (the default) checks what it can without signing (a clean tree |
| +# at a pushed commit, the pinned Timeless Sans, the configuration, the |
| +# Sparkle tools and the publisher) and prints every command it would run. |
| +# --publish runs them: the signing identity, Sparkle key, notary profile |
| +# and Base's Developer ID profile (Paul's portal steps) must be on this |
| +# Mac. Safe to rerun: a notarized release already in the record directory |
| +# is reused, and the publisher refuses a build the feed already lists. |
| +set -e -u -o pipefail |
| +setopt no_nomatch |
| + |
| +VERSION=${1:?usage: release-mac.sh VERSION BUILD [--publish]} |
| +BUILD=${2:?usage: release-mac.sh VERSION BUILD [--publish]} |
| +PUBLISH=0 |
| +[[ ${3:-} == --publish ]] && PUBLISH=1 |
| +[[ -z ${3:-} || $PUBLISH == 1 ]] || { print "usage: release-mac.sh VERSION BUILD [--publish]" >&2; exit 2 } |
| + |
| +IDENTITY='Developer ID Application: Team Tito Limited (9U4A84C4WK)' |
| +TEAM=9U4A84C4WK |
| +NOTARY_PROFILE=${NOTARY_PROFILE:-slopbox-notary} |
| +SPARKLE_ACCOUNT=oficina |
| +NATIVE=${0:A:h:h} |
| +REPO=${NATIVE:h} |
| +CONFIG=$NATIVE/mac-updates.json |
| +TOOLS=$NATIVE/apple/.build/checkouts/native/tools |
| +SPARKLE_BIN=$NATIVE/apple/.build/artifacts/sparkle/Sparkle/bin |
| +APP="$NATIVE/build/Oficina Base.app" |
| +OFICINA=$HOME/amadan.net/oficina |
| +RECORD=$OFICINA/sparkle-worktrees/releases/base-$VERSION-$BUILD |
| +ARTIFACTS=$OFICINA/sparkle-worktrees/native-releases |
| +AGENT_HOME=$HOME/.amadan-claude-agent |
| +AGENT_EMAIL='claude~paul@keymail.dev' |
| +umask 077 |
| +TMP=$(mktemp -d "${TMPDIR:-/tmp}/base-release.XXXXXX") |
| +PAT_ID="" |
| + |
| +say() { print -r -- " $*" } |
| +step() { print -P "\n%B%F{cyan}==> $*%f%b" } |
| +die() { print -P "%F{red}error:%f $*" >&2; exit 1 } |
| +run() { print -r -- " + ${(j: :)${(q-)@}}"; [[ $PUBLISH == 0 ]] || "$@" } |
| +agent_amadan() { env AMADAN_HOME="$AGENT_HOME" amadan "$@" } |
| +agent_git() { |
| + env AMADAN_HOME="$AGENT_HOME" GIT_ASKPASS="$TMP/askpass" GIT_TERMINAL_PROMPT=0 \ |
| + GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=credential.helper GIT_CONFIG_VALUE_0= \ |
| + GIT_AUTHOR_NAME=Claude GIT_AUTHOR_EMAIL="$AGENT_EMAIL" \ |
| + GIT_COMMITTER_NAME=Claude GIT_COMMITTER_EMAIL="$AGENT_EMAIL" "$@" |
| +} |
| +on_exit() { |
| + local rc=$? |
| + if [[ -n $PAT_ID ]]; then agent_amadan tokens revoke "$PAT_ID" >/dev/null && say "revoked PAT $PAT_ID" || print -P "%F{red}REVOKE PAT $PAT_ID BY HAND%f" >&2; fi |
| + rm -rf "$TMP" |
| + (( rc == 0 )) || print -P "%F{red}FAILED (exit $rc)%f" >&2 |
| +} |
| +trap on_exit EXIT |
| + |
| +[[ $PUBLISH == 1 ]] && say "publishing Base $VERSION ($BUILD)" || say "the plan for Base $VERSION ($BUILD); --publish runs it" |
| +[[ $VERSION == <->.<->.<-> ]] || die "VERSION is not x.y.z" |
| +[[ $BUILD == <-> && $BUILD -ge 1 ]] || die "BUILD is not a positive integer" |
| + |
| +step "The tree: clean, at a pushed commit" |
| +COMMIT=$(git -C "$REPO" rev-parse HEAD) |
| +if [[ -n $(git -C "$REPO" status --porcelain) ]]; then |
| + [[ $PUBLISH == 1 ]] && die "$REPO has local changes" || say "WARNING: local changes (--publish refuses them)" |
| +fi |
| +if ! git -C "$REPO" branch -r --contains "$COMMIT" | grep -q .; then |
| + [[ $PUBLISH == 1 ]] && die "$COMMIT is on no remote branch" || say "WARNING: $COMMIT is on no remote branch (--publish refuses it)" |
| +fi |
| +say "commit $COMMIT" |
| + |
| +step "Timeless Sans, the configuration, the Sparkle tools and the publisher" |
| +"$REPO/hack/fonts.sh" check |
| +python3 -c 'import json,sys; c=json.load(open(sys.argv[1])); assert c["bundle_id"]=="works.oficina.base", c["bundle_id"]; print(" config:", c["feed_url"])' "$CONFIG" |
| +swift package --package-path "$NATIVE/apple" resolve >/dev/null |
| +[[ -x $SPARKLE_BIN/sign_update && -f $TOOLS/release_mac.py && -f $TOOLS/publish_mac_update.py ]] || die "Sparkle tools or the kit's release tools missing" |
| +say "all present" |
| + |
| +step "Signing: Developer ID, Sparkle key, notary profile, Base's profile" |
| +profile=${$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["provisioning_profile"])' "$CONFIG")/#\~/$HOME} |
| +if [[ $PUBLISH == 1 ]]; then |
| + [[ $(security find-identity -v -p codesigning) == *"\"$IDENTITY\""* ]] || die "no '$IDENTITY'" |
| + key=$("$SPARKLE_BIN/generate_keys" --account "$SPARKLE_ACCOUNT" -p) |
| + [[ $key == $(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["public_ed_key"])' "$CONFIG") ]] || die "Sparkle key does not match mac-updates.json" |
| + xcrun notarytool history --keychain-profile "$NOTARY_PROFILE" >/dev/null || die "notary profile did not authenticate" |
| + [[ -f $profile ]] || die "no Developer ID profile at $profile (Paul's portal step)" |
| + say "all present" |
| +else |
| + say "checked only with --publish: '$IDENTITY', the Sparkle key ($SPARKLE_ACCOUNT), notary profile $NOTARY_PROFILE" |
| + [[ -f $profile ]] && say "Developer ID profile present" || say "WARNING: no Developer ID profile at $profile yet (Paul's portal step)" |
| +fi |
| + |
| +if [[ -f $RECORD/release.json ]]; then |
| + step "Reusing the notarized release in $RECORD" |
| +else |
| + step "Build Oficina Base.app $VERSION ($BUILD), release, Developer ID" |
| + run "$NATIVE/scripts/build-mac.sh" --configuration release --version "$VERSION" --build "$BUILD" --sign-identity "$IDENTITY" |
| + if [[ $PUBLISH == 1 ]]; then |
| + [[ $(plutil -extract CFBundleShortVersionString raw -o - "$APP/Contents/Info.plist") == $VERSION ]] || die "version mismatch" |
| + [[ $(plutil -extract CFBundleVersion raw -o - "$APP/Contents/Info.plist") == $BUILD ]] || die "build mismatch" |
| + [[ $(plutil -extract CFBundleIdentifier raw -o - "$APP/Contents/Info.plist") == works.oficina.base ]] || die "bundle id mismatch" |
| + fi |
| + step "Sign inside out, notarize, staple, Gatekeeper, Sparkle archive" |
| + run python3 "$TOOLS/release_mac.py" "$APP" --config "$CONFIG" --sparkle-tools "$SPARKLE_BIN" \ |
| + --identity "$IDENTITY" --team "$TEAM" --notary-profile "$NOTARY_PROFILE" --output "$RECORD" |
| +fi |
| + |
| +step "Smoke test: the stapled app passes Gatekeeper, with Oficina ID's grants" |
| +SMOKE=$TMP/smoke; mkdir -p "$SMOKE" |
| +zip="$RECORD/works.oficina.base-$BUILD.zip" |
| +run ditto -x -k "$zip" "$SMOKE" |
| +run xcrun stapler validate "$SMOKE/Oficina Base.app" |
| +run spctl --assess --type execute -vv "$SMOKE/Oficina Base.app" |
| +if [[ $PUBLISH == 1 ]]; then |
| + [[ -f "$SMOKE/Oficina Base.app/Contents/embedded.provisionprofile" ]] || die "no embedded provisioning profile" |
| + [[ -f "$SMOKE/Oficina Base.app/Contents/Resources/BaseNative_BaseKit.bundle/Fonts/TimelessSansVF.woff2" ]] || die "Timeless Sans is not in the bundle" |
| + ents=$(codesign -d --entitlements - --xml "$SMOKE/Oficina Base.app" 2>/dev/null | plutil -convert json -o - -) |
| + for want in 9U4A84C4WK.works.oficina.base 9U4A84C4WK.works.oficina.id 9U4A84C4WK.works.oficina webcredentials:id.oficina.works; do |
| + [[ $ents == *"\"$want\""* ]] || die "entitlement $want missing" |
| + done |
| + say "entitlements, embedded profile and Timeless Sans present" |
| +else |
| + say "(checks the embedded profile, Timeless Sans in the bundle, and Base's four entitlements)" |
| +fi |
| + |
| +step "Publish: plan, then publish as the claude agent" |
| +if [[ $PUBLISH == 1 ]]; then |
| + [[ $(agent_amadan auth whoami) == $AGENT_EMAIL ]] || die "agent credential is not $AGENT_EMAIL" |
| + [[ -d $ARTIFACTS/.git || -f $ARTIFACTS/.git ]] || die "no native-releases checkout at $ARTIFACTS" |
| + [[ -d $ARTIFACTS/base ]] || die "native-releases has no base/ yet (an operator step)" |
| + LABEL=base-$VERSION-$BUILD-$(date +%Y%m%d-%H%M%S) |
| + agent_amadan tokens create -label "$LABEL" | sed -n 's/^New token: //p' > "$TMP/pat" |
| + [[ -s $TMP/pat ]] || die "could not read the new token" |
| + PAT_ID=$(agent_amadan tokens list | awk -F'\t' -v l="$LABEL" '$2==l{print $1}') |
| + [[ $PAT_ID == <-> ]] || die "no id for token $LABEL; revoke it by hand" |
| + print -r -- '#!/bin/sh |
| +case "$1" in Username*) echo claude ;; *) cat "'"$TMP/pat"'" ;; esac' > "$TMP/askpass"; chmod 700 "$TMP/askpass" |
| +fi |
| +run agent_git git -C "$ARTIFACTS" pull -q --ff-only origin main |
| +run agent_git python3 "$TOOLS/publish_mac_update.py" "$RECORD" --config "$CONFIG" --repo "$ARTIFACTS" --sparkle-tools "$SPARKLE_BIN" |
| +run agent_git python3 "$TOOLS/publish_mac_update.py" "$RECORD" --config "$CONFIG" --repo "$ARTIFACTS" --sparkle-tools "$SPARKLE_BIN" --publish |
| + |
| +step "Done" |
| +say "feed: https://raw.amadan.net/oficina/native-releases/main/base/appcast.xml" |
| +[[ $PUBLISH == 1 ]] || say "nothing was built, signed or published: this was the plan" |