Commit ab4daf2f46

ab4daf2f465b8121727828605fdcdeb218063c99

parent: 3fc43c031f

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-07 14:13 UTC

Add shared release-ios.sh and render-header.sh

Layout: unified · split

README.md added +31
@@ -0,0 +1,31 @@
1# appstore-kit
2
3Scripts shared by the iOS apps. Check it out beside the apps (`~/git/krz/appstore-kit`) or
4point `APPSTORE_KIT` at it.
5
6## release-ios.sh
7
8Archives an app, checks the archive's version and build against the project, and exports or
9uploads it to App Store Connect. Each app's `scripts/release-ios.sh` sets its options and
10sources this file; the options are listed at the top of it. Run from a clean `main`.
11
12```sh
13#!/bin/sh
14PUBLISH="${MOONRISE_PUBLISH:-1}"
15name=Moonrise
16project=App/Moonrise.xcodeproj
17scheme=Moonrise
18spec=App/project.yml
19. "${APPSTORE_KIT:-$(dirname "$0")/../../appstore-kit}/release-ios.sh"
20```
21
22Extra checks go in a `preflight()` function defined before the `.` line.
23
24## render-header.sh
25
26Renders the product page headers, `header-21x9.png` and `header-16x9.png`, from an app's
27`AppStore/header.conf` and its `screenshots/iphone-6.9` images. Needs Chromium and ImageMagick.
28
29```sh
30../appstore-kit/render-header.sh App/AppStore
31```
release-ios.sh added +117
@@ -0,0 +1,117 @@
1#!/bin/sh
2# Archives an iOS app and uploads it to App Store Connect, signed automatically with the team's
3# distribution certificate through the Apple ID signed in to Xcode. The upload shows in TestFlight
4# once processed and can then be picked for a submission.
5#
6# Sourced by each app's scripts/release-ios.sh, which sets these first:
7# name the app's name, for messages
8# project the .xcodeproj, relative to the repository root
9# scheme the scheme to archive
10# spec optional: XcodeGen's project.yml. The project is generated from it first, and
11# the version is read from it rather than from the project file.
12# build_number commits (default): the commit count, passed to xcodebuild;
13# committed: CURRENT_PROJECT_VERSION as committed
14# team the team ID (default ZCNAX3VL9D)
15# allow_untracked 1 lets untracked files through the clean-tree check (default 0)
16# and may define preflight(), run with $version, $build and $publish set, before archiving.
17#
18# PUBLISH=0 archives and exports the .ipa to .build/ios-release without uploading. Wrappers set
19# PUBLISH from their own variable, such as MOONRISE_PUBLISH.
20set -eu
21
22cd "$(git -C "$(dirname "$0")" rev-parse --show-toplevel)"
23publish="${PUBLISH:-1}"
24team="${team:-ZCNAX3VL9D}"
25build_number="${build_number:-commits}"
26spec="${spec:-}"
27
28fail() {
29 echo "release-ios: $1" >&2
30 exit 1
31}
32
33# One value across all targets and configurations, or the archive would disagree with itself
34# depending on which target you read.
35setting() {
36 if [ -n "$spec" ]; then
37 values="$(sed -n "s/.*$1: \"*\([^\"]*\)\"*$/\1/p" "$spec" | sort -u)"
38 else
39 values="$(sed -n "s/.*$1 = \(.*\);/\1/p" "$project/project.pbxproj" | sort -u)"
40 fi
41 [ -n "$values" ] || fail "no $1 in ${spec:-$project}"
42 [ "$(printf '%s\n' "$values" | wc -l | tr -d ' ')" = 1 ] || fail "$1 differs across targets: $(printf '%s' "$values" | tr '\n' ' ')"
43 printf '%s' "$values"
44}
45
46if [ "$publish" != 0 ]; then
47 if [ "${allow_untracked:-0}" = 1 ]; then untracked=no; else untracked=normal; fi
48 [ -z "$(git status --porcelain --untracked-files=$untracked)" ] || fail "the working tree has changes"
49 [ "$(git branch --show-current)" = main ] || fail "release from main"
50fi
51
52version="$(setting MARKETING_VERSION)"
53case "$build_number" in
54 commits) build="$(git rev-list --count HEAD)" ;;
55 committed) build="$(setting CURRENT_PROJECT_VERSION)" ;;
56 *) fail "build_number is commits or committed, not $build_number" ;;
57esac
58
59if command -v preflight >/dev/null; then preflight; fi
60
61if [ -n "$spec" ]; then
62 command -v xcodegen >/dev/null || fail "install XcodeGen: brew install xcodegen"
63 (cd "$(dirname "$spec")" && xcodegen generate --quiet)
64fi
65
66echo "==> $name $version ($build)"
67out=.build/ios-release
68rm -rf "${out:?}"
69mkdir -p "$out"
70archive="$out/$scheme.xcarchive"
71if [ -z "$spec" ]; then
72 # xcodebuild rewrites the project file in its own key order; the copy puts it back as it was.
73 cp "$project/project.pbxproj" "$out/project.pbxproj"
74 trap 'cp "$out/project.pbxproj" "$project/project.pbxproj"' EXIT
75fi
76xcodebuild archive -project "$project" -scheme "$scheme" -configuration Release \
77 -destination 'generic/platform=iOS' -archivePath "$archive" -derivedDataPath "$out/DerivedData" \
78 -allowProvisioningUpdates -quiet MARKETING_VERSION="$version" CURRENT_PROJECT_VERSION="$build"
79
80# The project file is not the product: check what was built.
81set -- "$archive"/Products/Applications/*.app
82plist="$1/Info.plist"
83built_version="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$plist")"
84built_build="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$plist")"
85[ "$built_version" = "$version" ] || fail "archive is $built_version, expected $version"
86[ "$built_build" = "$build" ] || fail "archive is build $built_build, expected $build"
87
88if [ "$publish" = 0 ]; then destination=export; else destination=upload; fi
89cat > "$out/ExportOptions.plist" <<PLIST
90<?xml version="1.0" encoding="UTF-8"?>
91<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
92<plist version="1.0">
93<dict>
94 <key>method</key>
95 <string>app-store-connect</string>
96 <key>destination</key>
97 <string>$destination</string>
98 <key>teamID</key>
99 <string>$team</string>
100 <key>signingStyle</key>
101 <string>automatic</string>
102 <key>manageAppVersionAndBuildNumber</key>
103 <false/>
104 <key>uploadSymbols</key>
105 <true/>
106</dict>
107</plist>
108PLIST
109echo "==> $destination"
110xcodebuild -exportArchive -archivePath "$archive" -exportOptionsPlist "$out/ExportOptions.plist" \
111 -exportPath "$out/export" -allowProvisioningUpdates -quiet
112
113if [ "$publish" = 0 ]; then
114 echo "Exported $(ls "$out"/export/*.ipa): $name $version ($build), not uploaded"
115else
116 echo "Uploaded $name $version ($build) to App Store Connect; it shows in TestFlight once processed"
117fi
render-header.sh added +63
@@ -0,0 +1,63 @@
1#!/bin/sh
2# Renders an app's product page header: three iPhone screenshots fanned over a background, as
3# header-21x9.png (3840x1646) and header-16x9.png (5244x2950), with headless Chromium and the
4# alpha channel removed.
5# Usage: render-header.sh <AppStore directory>
6# The directory holds screenshots/iphone-6.9/ and header.conf, which sets:
7# background the CSS background
8# left center right the screenshots' names in screenshots/iphone-6.9, without .png
9# extra_css optional: CSS after the shared rules
10# CHROMIUM the Chromium binary (default /Applications/Chromium.app/Contents/MacOS/Chromium)
11set -eu
12
13dir="$(cd "${1:?usage: render-header.sh <AppStore directory>}" && pwd)"
14extra_css=
15. "$dir/header.conf"
16chromium="${CHROMIUM:-/Applications/Chromium.app/Contents/MacOS/Chromium}"
17page="$dir/.header.html"
18trap 'rm -f "$page"' EXIT
19
20cat > "$page" <<HTML
21<!doctype html>
22<html>
23<head>
24<meta charset="utf-8">
25<style>
26 :root { --u: 1px; --top: 180px; }
27 * { box-sizing: border-box; }
28 html, body { margin: 0; width: 3840px; height: 1646px; overflow: hidden; }
29 body { position: relative; background: $background; }
30 .iphone {
31 position: absolute; left: 50%; top: var(--top);
32 width: calc(860 * var(--u)); height: calc(1868 * var(--u));
33 padding: calc(24 * var(--u)); border-radius: calc(140 * var(--u)); background: #0c0c12;
34 box-shadow: 0 calc(50 * var(--u)) calc(120 * var(--u)) rgba(0, 0, 0, 0.5);
35 }
36 .iphone img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top; border-radius: calc(116 * var(--u)); }
37 .center { transform: translateX(-50%); z-index: 2; }
38 .left { transform: translate(calc(-50% - 760 * var(--u)), calc(120 * var(--u))) rotate(-8deg); }
39 .right { transform: translate(calc(-50% + 760 * var(--u)), calc(120 * var(--u))) rotate(8deg); }
40
41 /* 16:9, 5244x2950. */
42 html.wide { --u: 1.6px; --top: 420px; }
43 html.wide, .wide body { width: 5244px; height: 2950px; }
44$extra_css
45</style>
46<script>if (location.hash === "#wide") document.documentElement.className = "wide";</script>
47</head>
48<body>
49 <div class="iphone left"><img src="screenshots/iphone-6.9/$left.png"></div>
50 <div class="iphone right"><img src="screenshots/iphone-6.9/$right.png"></div>
51 <div class="iphone center"><img src="screenshots/iphone-6.9/$center.png"></div>
52</body>
53</html>
54HTML
55
56render() {
57 "$chromium" --headless --hide-scrollbars --force-device-scale-factor=1 --window-size="$2" \
58 --screenshot="$dir/$1" "file://$page$3" 2>/dev/null
59 magick "$dir/$1" -alpha off "PNG24:$dir/$1"
60 echo "wrote $dir/$1"
61}
62render header-21x9.png 3840,1646 ""
63render header-16x9.png 5244,2950 "#wide"