hop
Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.
Brought by drakestapleton
| 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. |
| 10 | set -eu |
| 11 | cd "$(dirname "$0")/.." |
| 12 | export LC_ALL=C TZ=UTC |
| 13 | umask 022 |
| 14 | |
| 15 | SAME_AS="" |
| 16 | if [ "${1:-}" = "--same-as" ] && [ $# -eq 2 ]; then SAME_AS=$2 |
| 17 | elif [ $# -ne 0 ]; then echo "usage: tools/release.sh [--same-as <zip sha256>]" >&2; exit 2; fi |
| 18 | |
| 19 | if [ -n "$(git status --porcelain)" ]; then |
| 20 | echo "release.sh: the tree has uncommitted changes; commit or remove them first" >&2 |
| 21 | exit 2 |
| 22 | fi |
| 23 | COMMIT=$(git rev-parse HEAD) |
| 24 | TREE=$(git rev-parse 'HEAD^{tree}') |
| 25 | VERSION=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' Resources/Info.plist) |
| 26 | SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) |
| 27 | export SOURCE_DATE_EPOCH ZERO_AR_DATE=1 |
| 28 | |
| 29 | HOP_SIGN=adhoc ./build.sh |
| 30 | |
| 31 | DIST=dist |
| 32 | ZIP="Hop-$VERSION.zip" |
| 33 | rm -rf "$DIST" |
| 34 | mkdir -p "$DIST/stage" |
| 35 | cp -R build/Hop.app "$DIST/stage/Hop.app" |
| 36 | # Same permissions and the same file time on every Mac; no extended attributes. |
| 37 | chmod -R u=rwX,go=rX "$DIST/stage/Hop.app" |
| 38 | xattr -cr "$DIST/stage/Hop.app" 2>/dev/null || true |
| 39 | STAMP=$(date -u -r "$SOURCE_DATE_EPOCH" +%Y%m%d%H%M.%S) |
| 40 | find "$DIST/stage/Hop.app" -exec touch -h -t "$STAMP" {} + |
| 41 | codesign --verify --strict "$DIST/stage/Hop.app" |
| 42 | (cd "$DIST/stage" && find Hop.app -print | sort | zip -X -q -@ "../$ZIP") |
| 43 | rm -rf "$DIST/stage" |
| 44 | |
| 45 | # Check the zip itself: unpack it and compare with what was built. |
| 46 | CHECK=$(mktemp -d "${TMPDIR:-/tmp}/hop-release.XXXXXX") |
| 47 | trap 'rm -rf "$CHECK"' EXIT |
| 48 | /usr/bin/ditto -x -k "$DIST/$ZIP" "$CHECK" |
| 49 | codesign --verify --strict "$CHECK/Hop.app" |
| 50 | sha() { shasum -a 256 "$1" | cut -d' ' -f1; } |
| 51 | EXE_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; } |
| 53 | cmp -s LICENSE "$CHECK/Hop.app/Contents/Resources/LICENSE" || { echo "release.sh: the zip does not carry the licence text" >&2; exit 1; } |
| 54 | ZIP_SHA=$(sha "$DIST/$ZIP") |
| 55 | ZIP_BYTES=$(wc -c < "$DIST/$ZIP" | tr -d ' ') |
| 56 | CDHASH=$(codesign -dvvv "$CHECK/Hop.app" 2>&1 | sed -n 's/^CDHash=//p') |
| 57 | |
| 58 | REPRO=false |
| 59 | REPRO_NOTE="not checked in this run" |
| 60 | if [ -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" |
| 67 | fi |
| 68 | |
| 69 | (cd "$DIST" && shasum -a 256 "$ZIP" > SHA256SUMS) |
| 70 | |
| 71 | esc() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'; } |
| 72 | cat > "$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 | } |
| 97 | EOF |
| 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 | |
| 101 | echo "release $VERSION at $COMMIT" |
| 102 | echo " $ZIP_SHA $DIST/$ZIP" |
| 103 | echo " $EXE_SHA Hop.app/Contents/MacOS/Hop" |
| 104 | echo " wrote $DIST/SHA256SUMS and $DIST/RELEASE.json" |