#!/bin/sh set -eu mac=$(cd "$(dirname "$0")" && pwd) root=$(dirname "$mac") repo=ai/byre api=https://g.fc.run/api/v1/repos/$repo 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) CLOUDFLARE_API_TOKEN=$(security find-generic-password -s byre-cloudflare -w) CLOUDFLARE_ACCOUNT_ID=96e4d3199efaa07ddc5c33e0e2d59c01 export CLOUDFLARE_API_TOKEN CLOUDFLARE_ACCOUNT_ID notes=$(cat "$1") "$mac/package.sh" out=$mac/.build/release/$version dmg=byre-$version.dmg put() { npx --yes wrangler@4.151.2 r2 object put "byre/$1" --remote --file "$out/$2" --content-type "$3" --cache-control "$4" } put "$dmg" "$dmg" application/x-apple-diskimage "public, max-age=31536000, immutable" put "$dmg.sha256" "$dmg.sha256" text/plain "public, max-age=31536000, immutable" put byre.dmg "$dmg" application/x-apple-diskimage "public, max-age=300" put appcast.xml appcast.xml application/xml "public, max-age=300" curl -fsS -o /dev/null -X POST -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" -H "Content-Type: application/json" --data '{"files":["https://dl.byre.run/byre.dmg","https://dl.byre.run/appcast.xml"]}' https://api.cloudflare.com/client/v4/zones/b53a5f8cb60313ba6789aba3559cb4b8/purge_cache 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"; 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"