Repository navigation
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·199 lines (168 loc) · 5.96 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·199 lines (168 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
# Collect changesets — files with a YAML frontmatter starting with `---`.
shopt -s nullglob
PENDING=()
for file in .changeset/*.md; do
[ "$(head -n1 "$file")" = "---" ] || continue
PENDING+=("$file")
done
if [ ${#PENDING[@]} -eq 0 ]; then
echo "no pending changesets in .changeset/ — run ./changeset.sh first"
exit 1
fi
# Determine highest bump level across pending changesets.
BUMP=patch
for file in "${PENDING[@]}"; do
level=$(awk -F': *' '$1 == "bump" { print $2; exit }' "$file")
case "$level" in
major) BUMP=major; break ;;
minor) [ "$BUMP" = patch ] && BUMP=minor ;;
patch) ;;
*) echo "$file: unknown bump '$level'"; exit 1 ;;
esac
done
# Compute next version + build number.
CURRENT=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" Resources/Info.plist)
IFS='.' read -r MAJ MIN PAT <<< "$CURRENT"
case "$BUMP" in
major) MAJ=$((MAJ+1)); MIN=0; PAT=0 ;;
minor) MIN=$((MIN+1)); PAT=0 ;;
patch) PAT=$((PAT+1)) ;;
esac
NEXT="$MAJ.$MIN.$PAT"
BUILD=$(($(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" Resources/Info.plist)+1))
echo "==> $CURRENT -> $NEXT ($BUMP) build $BUILD"
# Concatenate bodies (text after the second `---`) into release notes.
extract_body() {
awk 'BEGIN{c=0} /^---$/{c++; next} c>=2' "$1"
}
NOTES=""
APPCAST_PARAGRAPHS=""
for file in "${PENDING[@]}"; do
body=$(extract_body "$file" | sed -e '/./,$!d' | awk '{lines=lines $0 "\n"} END{sub(/\n+$/, "", lines); print lines}')
[ -n "$body" ] || continue
NOTES+="$body"$'\n\n'
APPCAST_PARAGRAPHS+="<p>${body//$'\n'/<br>}</p>"
done
NOTES=${NOTES%$'\n\n'}
# Bump Info.plist.
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $NEXT" Resources/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD" Resources/Info.plist
# Prepend to CHANGELOG.md.
DATE=$(date "+%Y-%m-%d")
TMP=$(mktemp)
{
echo "## v$NEXT — $DATE"
echo
echo "$NOTES"
echo
if [ -f CHANGELOG.md ]; then
cat CHANGELOG.md
fi
} > "$TMP"
mv "$TMP" CHANGELOG.md
# Build + zip.
./build-app.sh release
ditto -c -k --keepParent cmdcmd.app cmdcmd.zip
SHA256=$(shasum -a 256 cmdcmd.zip | awk '{print $1}')
# Sign with Sparkle key from 1Password.
SPARKLE_KEY_REF="${SPARKLE_KEY_REF:-op://Private/cmdcmd Sparkle key/password}"
SIGN_OUT=$(op read "$SPARKLE_KEY_REF" | .build/artifacts/sparkle/Sparkle/bin/sign_update -f - cmdcmd.zip)
SIZE=$(stat -f%z cmdcmd.zip)
ED_SIG=$(printf '%s' "$SIGN_OUT" | sed -E 's/.*edSignature="([^"]+)".*/\1/')
PUBDATE=$(date -u "+%a, %d %b %Y %H:%M:%S +0000")
# Generate appcast.xml.
cat > appcast.xml <<EOF
<?xml version="1.0" standalone="yes"?>
<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" version="2.0">
<channel>
<title>cmdcmd</title>
<link>https://raw.githubusercontent.com/peterp/cmdcmd/main/appcast.xml</link>
<description>cmdcmd updates</description>
<language>en</language>
<item>
<title>v$NEXT</title>
<sparkle:version>$BUILD</sparkle:version>
<sparkle:shortVersionString>$NEXT</sparkle:shortVersionString>
<sparkle:minimumSystemVersion>14.0</sparkle:minimumSystemVersion>
<description><![CDATA[${APPCAST_PARAGRAPHS}]]></description>
<pubDate>$PUBDATE</pubDate>
<enclosure url="https://github.com/peterp/cmdcmd/releases/download/v$NEXT/cmdcmd.zip"
sparkle:edSignature="$ED_SIG"
length="$SIZE"
type="application/octet-stream" />
</item>
</channel>
</rss>
EOF
# Consume changesets.
git rm -f "${PENDING[@]}" >/dev/null
# Commit + tag + push.
git add Resources/Info.plist appcast.xml CHANGELOG.md
git commit -m "Release v$NEXT"
git tag -a "v$NEXT" -m "v$NEXT"
git push origin main
git push origin "v$NEXT"
# GitHub release.
RELEASE_BODY="## What's new
$NOTES
## Install
Homebrew: \`brew install --cask peterp/tap/cmdcmd\`
Manual:
1. Download \`cmdcmd.zip\` and unzip.
2. Drag \`cmdcmd.app\` to \`/Applications\`.
3. Strip quarantine: \`xattr -dr com.apple.quarantine /Applications/cmdcmd.app\` (or System Settings → Privacy & Security → Open Anyway after the first failed launch).
4. Grant Screen Recording + Accessibility on first launch.
Existing v0.1.3+ users will be offered this update automatically via Sparkle.
Requires macOS 14+. Apple-silicon build."
gh release create "v$NEXT" cmdcmd.zip --title "v$NEXT" --notes "$RELEASE_BODY"
# Update Homebrew tap.
if [ "${SKIP_HOMEBREW_TAP:-0}" = "1" ]; then
echo "Skipping Homebrew tap update."
else
TAP_REPO="${TAP_REPO:-peterp/homebrew-tap}"
TAP_DIR=$(mktemp -d)
cleanup_tap() { rm -rf "$TAP_DIR"; }
trap cleanup_tap EXIT
gh repo clone "$TAP_REPO" "$TAP_DIR" -- --quiet
mkdir -p "$TAP_DIR/Casks"
cat > "$TAP_DIR/Casks/cmdcmd.rb" <<EOF
cask "cmdcmd" do
version "$NEXT"
sha256 "$SHA256"
url "https://github.com/peterp/cmdcmd/releases/download/v#{version}/cmdcmd.zip"
name "cmdcmd"
desc "Keyboard-first window switcher"
homepage "https://github.com/peterp/cmdcmd"
auto_updates true
depends_on arch: :arm64
depends_on macos: ">= :sonoma"
app "cmdcmd.app"
postflight do
system_command "/usr/bin/xattr",
args: ["-dr", "com.apple.quarantine", "#{appdir}/cmdcmd.app"]
end
uninstall quit: "com.p4p8.cmdcmd"
zap trash: [
"~/Library/Application Support/cmdcmd",
"~/Library/Preferences/com.p4p8.cmdcmd.plist",
]
end
EOF
(
cd "$TAP_DIR"
git config user.name "${TAP_GIT_NAME:-github-actions[bot]}"
git config user.email "${TAP_GIT_EMAIL:-github-actions[bot]@users.noreply.github.com}"
git add Casks/cmdcmd.rb
if git diff --cached --quiet; then
echo "Homebrew tap already up to date."
else
git commit -m "Update cmdcmd to $NEXT"
git push
echo "Updated Homebrew tap $TAP_REPO."
fi
)
fi
echo "Released v$NEXT."