interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

branch main Branches Tags History

hop / tools / release.sh

104 lines · 4553 bytes Raw Blame History
1#!/bin/sh
2# Builds a release that anyone can check. Run from a clean tree at the commit to release:
3# tools/release.sh [--same-as <zip sha256 from another checkout>]
4# Writes dist/Hop-<version>.zip, dist/SHA256SUMS and dist/RELEASE.json.
5# With --same-as the run fails unless this build's zip has exactly that sha256, and only then does
6# RELEASE.json say "reproducible": true.
7# The build is signed ad-hoc (no private key is involved), file times inside the zip are the commit time,
8# and files are zipped in a fixed order, so the same commit built with the same compiler and SDK gives
9# the same zip and the same executable, byte for byte. Nothing is uploaded.
10set -eu
11cd "$(dirname "$0")/.."
12export LC_ALL=C TZ=UTC
13umask 022
14
15SAME_AS=""
16if [ "${1:-}" = "--same-as" ] && [ $# -eq 2 ]; then SAME_AS=$2
17elif [ $# -ne 0 ]; then echo "usage: tools/release.sh [--same-as <zip sha256>]" >&2; exit 2; fi
18
19if [ -n "$(git status --porcelain)" ]; then
20 echo "release.sh: the tree has uncommitted changes; commit or remove them first" >&2
21 exit 2
22fi
23COMMIT=$(git rev-parse HEAD)
24TREE=$(git rev-parse 'HEAD^{tree}')
25VERSION=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' Resources/Info.plist)
26SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)
27export SOURCE_DATE_EPOCH ZERO_AR_DATE=1
28
29HOP_SIGN=adhoc ./build.sh
30
31DIST=dist
32ZIP="Hop-$VERSION.zip"
33rm -rf "$DIST"
34mkdir -p "$DIST/stage"
35cp -R build/Hop.app "$DIST/stage/Hop.app"
36# Same permissions and the same file time on every Mac; no extended attributes.
37chmod -R u=rwX,go=rX "$DIST/stage/Hop.app"
38xattr -cr "$DIST/stage/Hop.app" 2>/dev/null || true
39STAMP=$(date -u -r "$SOURCE_DATE_EPOCH" +%Y%m%d%H%M.%S)
40find "$DIST/stage/Hop.app" -exec touch -h -t "$STAMP" {} +
41codesign --verify --strict "$DIST/stage/Hop.app"
42(cd "$DIST/stage" && find Hop.app -print | sort | zip -X -q -@ "../$ZIP")
43rm -rf "$DIST/stage"
44
45# Check the zip itself: unpack it and compare with what was built.
46CHECK=$(mktemp -d "${TMPDIR:-/tmp}/hop-release.XXXXXX")
47trap 'rm -rf "$CHECK"' EXIT
48/usr/bin/ditto -x -k "$DIST/$ZIP" "$CHECK"
49codesign --verify --strict "$CHECK/Hop.app"
50sha() { shasum -a 256 "$1" | cut -d' ' -f1; }
51EXE_SHA=$(sha build/Hop.app/Contents/MacOS/Hop)
52[ "$(sha "$CHECK/Hop.app/Contents/MacOS/Hop")" = "$EXE_SHA" ] || { echo "release.sh: the zipped executable differs from the built one" >&2; exit 1; }
53cmp -s LICENSE "$CHECK/Hop.app/Contents/Resources/LICENSE" || { echo "release.sh: the zip does not carry the licence text" >&2; exit 1; }
54ZIP_SHA=$(sha "$DIST/$ZIP")
55ZIP_BYTES=$(wc -c < "$DIST/$ZIP" | tr -d ' ')
56CDHASH=$(codesign -dvvv "$CHECK/Hop.app" 2>&1 | sed -n 's/^CDHash=//p')
57
58REPRO=false
59REPRO_NOTE="not checked in this run"
60if [ -n "$SAME_AS" ]; then
61 if [ "$SAME_AS" != "$ZIP_SHA" ]; then
62 echo "release.sh: this build's zip is $ZIP_SHA, not $SAME_AS; the build did not reproduce" >&2
63 exit 1
64 fi
65 REPRO=true
66 REPRO_NOTE="this zip has the same sha256 as a build of the same commit in a separate checkout"
67fi
68
69(cd "$DIST" && shasum -a 256 "$ZIP" > SHA256SUMS)
70
71esc() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'; }
72cat > "$DIST/RELEASE.json" <<EOF
73{
74 "name": "Hop",
75 "version": "$(esc "$VERSION")",
76 "source_commit": "$COMMIT",
77 "tree": "$TREE",
78 "zip": "$ZIP",
79 "zip_sha256": "$ZIP_SHA",
80 "zip_bytes": $ZIP_BYTES,
81 "executable": "Hop.app/Contents/MacOS/Hop",
82 "executable_sha256": "$EXE_SHA",
83 "signing": "ad-hoc",
84 "cdhash": "$CDHASH",
85 "arch": "arm64",
86 "minimum_macos": "$(esc "$(/usr/libexec/PlistBuddy -c 'Print :LSMinimumSystemVersion' Resources/Info.plist)")",
87 "compiler": "$(esc "$(swiftc --version 2>&1 | head -n 1)")",
88 "c_compiler": "$(esc "$(clang --version 2>&1 | head -n 1)")",
89 "build_macos": "$(esc "$(sw_vers -productVersion) ($(sw_vers -buildVersion))")",
90 "sdk": "$(esc "$(xcrun --show-sdk-version 2>/dev/null || echo unknown)")",
91 "source_date_epoch": $SOURCE_DATE_EPOCH,
92 "build_date": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
93 "reproducible": $REPRO,
94 "reproducible_note": "$REPRO_NOTE",
95 "how_to_reproduce": "git checkout $COMMIT && tools/release.sh, with the compiler and sdk listed here; then compare the sha256 of dist/$ZIP with zip_sha256"
96}
97EOF
98# Read it back the way install.sh does, so a malformed file never ships.
99[ "$(plutil -extract zip_sha256 raw -o - "$DIST/RELEASE.json")" = "$ZIP_SHA" ] || { echo "release.sh: RELEASE.json does not read back" >&2; exit 1; }
100
101echo "release $VERSION at $COMMIT"
102echo " $ZIP_SHA $DIST/$ZIP"
103echo " $EXE_SHA Hop.app/Contents/MacOS/Hop"
104echo " wrote $DIST/SHA256SUMS and $DIST/RELEASE.json"