oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1#!/bin/zsh
2# Base for the Mac, released: a release build set in Timeless Sans, signed
3# with Developer ID (Base's profile embedded), notarized, stapled, checked
4# by Gatekeeper, then published to the Sparkle feed on
5# oficina/native-releases (base/appcast.xml) with the archive as a release
6# asset. Adapted from release-equipo-0.1.5.sh (2026-11-19).
7#
8# native/scripts/release-mac.sh VERSION BUILD # the plan
9# native/scripts/release-mac.sh VERSION BUILD --publish # do it
10#
11# The plan (the default) checks what it can without signing (a clean tree
12# at a pushed commit, the pinned Timeless Sans, the configuration, the
13# Sparkle tools and the publisher) and prints every command it would run.
14# --publish runs them: the signing identity, Sparkle key, notary profile
15# and Base's Developer ID profile (Paul's portal steps) must be on this
16# Mac. Safe to rerun: a notarized release already in the record directory
17# is reused, and the publisher refuses a build the feed already lists.
18set -e -u -o pipefail
19setopt no_nomatch
20
21VERSION=${1:?usage: release-mac.sh VERSION BUILD [--publish]}
22BUILD=${2:?usage: release-mac.sh VERSION BUILD [--publish]}
23PUBLISH=0
24[[ ${3:-} == --publish ]] && PUBLISH=1
25[[ -z ${3:-} || $PUBLISH == 1 ]] || { print "usage: release-mac.sh VERSION BUILD [--publish]" >&2; exit 2 }
26
27IDENTITY='Developer ID Application: Team Tito Limited (9U4A84C4WK)'
28TEAM=9U4A84C4WK
29NOTARY_PROFILE=${NOTARY_PROFILE:-slopbox-notary}
30SPARKLE_ACCOUNT=oficina
31NATIVE=${0:A:h:h}
32REPO=${NATIVE:h}
33CONFIG=$NATIVE/mac-updates.json
34TOOLS=$NATIVE/apple/.build/checkouts/native/tools
35SPARKLE_BIN=$NATIVE/apple/.build/artifacts/sparkle/Sparkle/bin
36APP="$NATIVE/build/Oficina Base.app"
37OFICINA=$HOME/amadan.net/oficina
38RECORD=$OFICINA/sparkle-worktrees/releases/base-$VERSION-$BUILD
39ARTIFACTS=$OFICINA/sparkle-worktrees/native-releases
40AGENT_HOME=$HOME/.amadan-claude-agent
41AGENT_EMAIL='claude~paul@keymail.dev'
42umask 077
43TMP=$(mktemp -d "${TMPDIR:-/tmp}/base-release.XXXXXX")
44PAT_ID=""
45
46say() { print -r -- " $*" }
47step() { print -P "\n%B%F{cyan}==> $*%f%b" }
48die() { print -P "%F{red}error:%f $*" >&2; exit 1 }
49run() { print -r -- " + ${(j: :)${(q-)@}}"; [[ $PUBLISH == 0 ]] || "$@" }
50agent_amadan() { env AMADAN_HOME="$AGENT_HOME" amadan "$@" }
51agent_git() {
52 env AMADAN_HOME="$AGENT_HOME" GIT_ASKPASS="$TMP/askpass" GIT_TERMINAL_PROMPT=0 \
53 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=credential.helper GIT_CONFIG_VALUE_0= \
54 GIT_AUTHOR_NAME=Claude GIT_AUTHOR_EMAIL="$AGENT_EMAIL" \
55 GIT_COMMITTER_NAME=Claude GIT_COMMITTER_EMAIL="$AGENT_EMAIL" "$@"
56}
57on_exit() {
58 local rc=$?
59 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
60 rm -rf "$TMP"
61 (( rc == 0 )) || print -P "%F{red}FAILED (exit $rc)%f" >&2
62}
63trap on_exit EXIT
64
65[[ $PUBLISH == 1 ]] && say "publishing Base $VERSION ($BUILD)" || say "the plan for Base $VERSION ($BUILD); --publish runs it"
66[[ $VERSION == <->.<->.<-> ]] || die "VERSION is not x.y.z"
67[[ $BUILD == <-> && $BUILD -ge 1 ]] || die "BUILD is not a positive integer"
68
69step "The tree: clean, at a pushed commit"
70COMMIT=$(git -C "$REPO" rev-parse HEAD)
71if [[ -n $(git -C "$REPO" status --porcelain) ]]; then
72 [[ $PUBLISH == 1 ]] && die "$REPO has local changes" || say "WARNING: local changes (--publish refuses them)"
73fi
74if ! git -C "$REPO" branch -r --contains "$COMMIT" | grep -q .; then
75 [[ $PUBLISH == 1 ]] && die "$COMMIT is on no remote branch" || say "WARNING: $COMMIT is on no remote branch (--publish refuses it)"
76fi
77say "commit $COMMIT"
78
79step "Timeless Sans, the configuration, the Sparkle tools and the publisher"
80"$REPO/hack/fonts.sh" check
81python3 -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"
82swift package --package-path "$NATIVE/apple" resolve >/dev/null
83[[ -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"
84say "all present"
85
86step "Signing: Developer ID, Sparkle key, notary profile, Base's profile"
87profile=${$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["provisioning_profile"])' "$CONFIG")/#\~/$HOME}
88if [[ $PUBLISH == 1 ]]; then
89 [[ $(security find-identity -v -p codesigning) == *"\"$IDENTITY\""* ]] || die "no '$IDENTITY'"
90 key=$("$SPARKLE_BIN/generate_keys" --account "$SPARKLE_ACCOUNT" -p)
91 [[ $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"
92 xcrun notarytool history --keychain-profile "$NOTARY_PROFILE" >/dev/null || die "notary profile did not authenticate"
93 [[ -f $profile ]] || die "no Developer ID profile at $profile (Paul's portal step)"
94 say "all present"
95else
96 say "checked only with --publish: '$IDENTITY', the Sparkle key ($SPARKLE_ACCOUNT), notary profile $NOTARY_PROFILE"
97 [[ -f $profile ]] && say "Developer ID profile present" || say "WARNING: no Developer ID profile at $profile yet (Paul's portal step)"
98fi
99
100if [[ -f $RECORD/release.json ]]; then
101 step "Reusing the notarized release in $RECORD"
102else
103 step "Build Oficina Base.app $VERSION ($BUILD), release, Developer ID"
104 run "$NATIVE/scripts/build-mac.sh" --configuration release --version "$VERSION" --build "$BUILD" --sign-identity "$IDENTITY"
105 if [[ $PUBLISH == 1 ]]; then
106 [[ $(plutil -extract CFBundleShortVersionString raw -o - "$APP/Contents/Info.plist") == $VERSION ]] || die "version mismatch"
107 [[ $(plutil -extract CFBundleVersion raw -o - "$APP/Contents/Info.plist") == $BUILD ]] || die "build mismatch"
108 [[ $(plutil -extract CFBundleIdentifier raw -o - "$APP/Contents/Info.plist") == works.oficina.base ]] || die "bundle id mismatch"
109 fi
110 step "Sign inside out, notarize, staple, Gatekeeper, Sparkle archive"
111 run python3 "$TOOLS/release_mac.py" "$APP" --config "$CONFIG" --sparkle-tools "$SPARKLE_BIN" \
112 --identity "$IDENTITY" --team "$TEAM" --notary-profile "$NOTARY_PROFILE" --output "$RECORD"
113fi
114
115step "Smoke test: the stapled app passes Gatekeeper, with Oficina ID's grants"
116SMOKE=$TMP/smoke; mkdir -p "$SMOKE"
117zip="$RECORD/works.oficina.base-$BUILD.zip"
118run ditto -x -k "$zip" "$SMOKE"
119run xcrun stapler validate "$SMOKE/Oficina Base.app"
120run spctl --assess --type execute -vv "$SMOKE/Oficina Base.app"
121if [[ $PUBLISH == 1 ]]; then
122 [[ -f "$SMOKE/Oficina Base.app/Contents/embedded.provisionprofile" ]] || die "no embedded provisioning profile"
123 [[ -f "$SMOKE/Oficina Base.app/Contents/Resources/BaseNative_BaseKit.bundle/Contents/Resources/Fonts/TimelessSansVF.woff2" ]] || die "Timeless Sans is not in the bundle"
124 ents=$(codesign -d --entitlements - --xml "$SMOKE/Oficina Base.app" 2>/dev/null | plutil -convert json -o - -)
125 for want in 9U4A84C4WK.works.oficina.base 9U4A84C4WK.works.oficina.id 9U4A84C4WK.works.oficina webcredentials:id.oficina.works; do
126 [[ $ents == *"\"$want\""* ]] || die "entitlement $want missing"
127 done
128 say "entitlements, embedded profile and Timeless Sans present"
129else
130 say "(checks the embedded profile, Timeless Sans in the bundle, and Base's four entitlements)"
131fi
132
133step "Publish: plan, then publish as the claude agent"
134if [[ $PUBLISH == 1 ]]; then
135 [[ $(agent_amadan auth whoami) == $AGENT_EMAIL ]] || die "agent credential is not $AGENT_EMAIL"
136 [[ -d $ARTIFACTS/.git || -f $ARTIFACTS/.git ]] || die "no native-releases checkout at $ARTIFACTS"
137 [[ -d $ARTIFACTS/base ]] || die "native-releases has no base/ yet (an operator step)"
138 LABEL=base-$VERSION-$BUILD-$(date +%Y%m%d-%H%M%S)
139 agent_amadan tokens create -label "$LABEL" | sed -n 's/^New token: //p' > "$TMP/pat"
140 [[ -s $TMP/pat ]] || die "could not read the new token"
141 PAT_ID=$(agent_amadan tokens list | awk -F'\t' -v l="$LABEL" '$2==l{print $1}')
142 [[ $PAT_ID == <-> ]] || die "no id for token $LABEL; revoke it by hand"
143 print -r -- '#!/bin/sh
144case "$1" in Username*) echo claude ;; *) cat "'"$TMP/pat"'" ;; esac' > "$TMP/askpass"; chmod 700 "$TMP/askpass"
145fi
146run agent_git git -C "$ARTIFACTS" pull -q --ff-only origin main
147run agent_git python3 "$TOOLS/publish_mac_update.py" "$RECORD" --config "$CONFIG" --repo "$ARTIFACTS" --sparkle-tools "$SPARKLE_BIN"
148run agent_git python3 "$TOOLS/publish_mac_update.py" "$RECORD" --config "$CONFIG" --repo "$ARTIFACTS" --sparkle-tools "$SPARKLE_BIN" --publish
149
150step "Done"
151say "feed: https://raw.amadan.net/oficina/native-releases/main/base/appcast.xml"
152[[ $PUBLISH == 1 ]] || say "nothing was built, signed or published: this was the plan"
153