Files
byre/mac/release.sh
T

91 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
set -eu
mac=$(cd "$(dirname "$0")" && pwd)
root=$(dirname "$mac")
repo=misc/byre
api=https://g.fc.run/api/v1/repos/$repo
sparkle_version=2.10.0
sparkle=$HOME/Library/Caches/byre/sparkle-$sparkle_version
identity="Developer ID Application"
if [ -n "$(git -C "$root" status --porcelain)" ]; then
echo "release: the tree has uncommitted changes" >&2
exit 1
fi
tag=$(git -C "$root" describe --tags --exact-match HEAD)
version=${tag#v}
git -C "$root" fetch origin "refs/tags/$tag"
if [ "$(git -C "$root" rev-parse "FETCH_HEAD^{commit}")" != "$(git -C "$root" rev-parse HEAD)" ]; then
echo "release: $tag on origin is not HEAD" >&2
exit 1
fi
token=$(security find-generic-password -s byre-release -w)
if [ ! -x "$sparkle/bin/sign_update" ]; then
mkdir -p "$sparkle"
curl -fsSL "https://github.com/sparkle-project/Sparkle/releases/download/$sparkle_version/Sparkle-$sparkle_version.tar.xz" | tar -xJ -C "$sparkle"
fi
"$mac/bundle.sh"
app=$mac/.build/byre.app
out=$mac/.build/release/$version
rm -rf "$out"
mkdir -p "$out"
ditto -c -k --keepParent "$app" "$out/byre.zip"
xcrun notarytool submit "$out/byre.zip" --keychain-profile byre-notary --wait
xcrun stapler staple "$app"
rm "$out/byre.zip"
dmg=byre-$version.dmg
stage=$out/stage
mkdir "$stage"
ditto "$app" "$stage/byre.app"
ln -s /Applications "$stage/Applications"
hdiutil create -volname byre -srcfolder "$stage" -format UDZO "$out/$dmg"
rm -rf "$stage"
codesign --force --timestamp --sign "$identity" "$out/$dmg"
xcrun notarytool submit "$out/$dmg" --keychain-profile byre-notary --wait
xcrun stapler staple "$out/$dmg"
(cd "$out" && shasum -a 256 "$dmg" > "$dmg.sha256")
build=$(plutil -extract CFBundleVersion raw "$app/Contents/Info.plist")
minimum=$(plutil -extract LSMinimumSystemVersion raw "$app/Contents/Info.plist")
signature=$("$sparkle/bin/sign_update" --account byre "$out/$dmg")
cat > "$out/appcast.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
<channel>
<title>byre</title>
<item>
<title>byre $version</title>
<pubDate>$(LC_ALL=C date -u "+%a, %d %b %Y %H:%M:%S +0000")</pubDate>
<sparkle:version>$build</sparkle:version>
<sparkle:shortVersionString>$version</sparkle:shortVersionString>
<sparkle:minimumSystemVersion>$minimum</sparkle:minimumSystemVersion>
<enclosure url="https://g.fc.run/$repo/releases/download/$tag/$dmg" type="application/octet-stream" $signature/>
</item>
</channel>
</rss>
EOF
previous=$(git -C "$root" describe --tags --abbrev=0 "$tag^" || true)
if [ -n "$previous" ]; then
notes=$(git -C "$root" log --format='- %s' "$previous..$tag")
else
notes="First release."
fi
request=$out/release.json
plutil -create xml1 "$request"
plutil -insert tag_name -string "$tag" "$request"
plutil -insert name -string "byre $version" "$request"
plutil -insert body -string "$notes" "$request"
plutil -insert draft -bool true "$request"
plutil -convert json "$request"
id=$(curl -fsS -X POST -H "Authorization: token $token" -H "Content-Type: application/json" --data-binary "@$request" "$api/releases" | plutil -extract id raw -)
for file in "$dmg" "$dmg.sha256" appcast.xml; do
curl -fsS -o /dev/null -H "Authorization: token $token" -F "attachment=@$out/$file" "$api/releases/$id/assets?name=$file"
done
curl -fsS -o /dev/null -X PATCH -H "Authorization: token $token" -H "Content-Type: application/json" --data '{"draft":false}' "$api/releases/$id"
echo "https://g.fc.run/$repo/releases/tag/$tag"