diff options
Diffstat (limited to 'mise.toml')
| -rw-r--r-- | mise.toml | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..2bc1323 --- /dev/null +++ b/mise.toml @@ -0,0 +1,205 @@ +[tools] +zig = "0.16.0" + +# The plain tasks build against the libpantograph revision pinned in build.zig.zon; +# the :local ones against the checkout beside this repo. +[tasks.build] +description = "Build zig-out/Write_Away.app" +run = "zig build" + +[tasks."build:local"] +description = "Build zig-out/Write_Away.app against the sibling libpantograph checkout" +run = "zig build --fork=../libpantograph" + +[tasks.run] +description = "Run the editor (mise run run -- file.md)" +run = "zig build run --" + +[tasks.test] +description = "Run the checks" +run = "zig build test" + +[tasks."test:local"] +description = "Run the checks against the sibling libpantograph checkout" +run = "zig build test --fork=../libpantograph" + +[tasks."test:release-task"] +description = "Test release publication against a local fake Forgejo" +run = "sh scripts/test-release-task.sh" + +[tasks."build:release"] +description = "Build the signed (ad hoc), zipped app and its checksum in zig-out/release" +run = ''' +set -eu +VER="$(sed -n 's/^ \.version = "\([^"]*\)",$/\1/p' build.zig.zon)" +[ -n "$VER" ] || { echo "could not read version from build.zig.zon" >&2; exit 1; } +OUT=zig-out/release +rm -rf "$OUT" +zig build -Doptimize=ReleaseSafe --prefix "$OUT" +# Zig signs the executable alone. The bundle needs a seal of its own, or a +# downloaded copy is reported as damaged. +codesign --force --sign - "$OUT/Write_Away.app" +ditto -c -k --keepParent "$OUT/Write_Away.app" "$OUT/Write_Away-$VER-macos-arm64.zip" +rm -rf "$OUT/Write_Away.app" +cd "$OUT" +shasum -a 256 ./*.zip | sed 's#\./##' > SHA256SUMS +''' + +[tasks."check:release"] +description = "Check the release zip: checksum, signature, version, and the app's own checks" +run = ''' +set -eu +VER="$(sed -n 's/^ \.version = "\([^"]*\)",$/\1/p' build.zig.zon)" +TMP="$(mktemp -d)" +trap 'rm -rf "$TMP"' 0 +( + cd zig-out/release + shasum -a 256 -c SHA256SUMS +) +ditto -x -k "zig-out/release/Write_Away-$VER-macos-arm64.zip" "$TMP" +APP="$TMP/Write_Away.app/Contents" +BIN="$APP/MacOS/write_away" +codesign --verify --deep --strict "$TMP/Write_Away.app" +GOT="$(plutil -extract CFBundleShortVersionString raw "$APP/Info.plist")" +[ "$GOT" = "$VER" ] || { echo "Info.plist says $GOT, build.zig.zon says $VER" >&2; exit 1; } +[ "$(lipo -archs "$BIN")" = arm64 ] || { echo "not an arm64 binary" >&2; exit 1; } +MIN="$(plutil -extract LSMinimumSystemVersion raw "$APP/Info.plist")" +GOT="$(otool -l "$BIN" | awk '$1 == "minos" { print $2 }')" +[ "$GOT.0" = "$MIN" ] || { echo "the binary needs macOS $GOT, Info.plist says $MIN" >&2; exit 1; } +# Outside the bundle, so it cannot reach the installed app's preferences. +cp "$BIN" "$TMP/write_away" +WRITE_AWAY_SELFTEST=1 "$TMP/write_away" +''' + +[tasks.version] +description = "Rewrite build.zig.zon for a new version" +usage = 'arg "<version>" help="x.y.z"' +run = ''' +set -eu +VERSION="$usage_version" +if ! printf '%s\n' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "usage: mise run version <x.y.z>" >&2 + exit 1 +fi +sed -i '' "s/^ \.version = \"[^\"]*\",$/ .version = \"$VERSION\",/" build.zig.zon +if ! grep -Fqx " .version = \"$VERSION\"," build.zig.zon; then + echo "could not rewrite .version in build.zig.zon" >&2 + exit 1 +fi +echo "wrote .version = \"$VERSION\" -- commit it, then: mise run release" +''' + +[tasks."pin:libpanto"] +description = "Pin libpantograph to a revision (default: the sibling checkout's main@codeberg)" +usage = 'arg "[revision]" default="main@codeberg"' +run = ''' +set -eu +REV="$(jj log -R ../libpantograph -r "$usage_revision" --no-graph -T commit_id)" +zig fetch --save=libpantograph "git+https://codeberg.org/teepark/libpantograph.git#$REV" +''' + +[tasks.release] +description = "Test, build, tag, push the tag, and publish on Codeberg" +run = ''' +set -eu +: "${CODEBERG_TOKEN:?set CODEBERG_TOKEN in mise.local.toml}" + +VER="$(sed -n 's/^ \.version = "\([^"]*\)",$/\1/p' build.zig.zon)" +[ -n "$VER" ] || { echo "could not read version from build.zig.zon" >&2; exit 1; } +TAG="v$VER" + +# The working copy is what gets built, so it must be exactly what gets tagged. +if [ -n "$(jj diff -r @ --name-only)" ]; then + echo "the working copy has changes -- commit them, or jj new main" >&2 + exit 1 +fi +REV="$(jj log --no-graph -r 'main & @-' -T commit_id)" +[ -n "$REV" ] || { echo "main is not @-" >&2; exit 1; } +# A tag already on this commit is a release that failed partway: carry on with it. +TAGGED="$(jj log --no-graph -r "tags(exact:'$TAG')" -T commit_id)" +if [ -n "$TAGGED" ] && [ "$TAGGED" != "$REV" ]; then + echo "$TAG is already on another commit -- bump the version first" >&2 + exit 1 +fi +REMOTES="$(jj git remote list | awk '{ print $1 }')" +printf '%s\n' "$REMOTES" | grep -Fqx codeberg || { echo "no remote named codeberg" >&2; exit 1; } + +# One command per line: under `set -e` a failure inside an `&&` chain does +# not exit, and a failed build must never reach the tag below. +mise run test +mise run build:release +mise run check:release + +if [ -n "${DRY_RUN:-}" ]; then + echo "DRY_RUN set; stopping before tag/push/publish" + exit 0 +fi + +[ -n "$TAGGED" ] || jj tag set "$TAG" -r "$REV" +for r in $REMOTES; do + # jj tracks a new tag by itself on the first remote only, and refuses the others. + jj tag track "$TAG@$r" + jj git push --remote "$r" --tag "exact:$TAG" +done + +mise run release:publish +''' + +[tasks."release:publish"] +description = "Create a draft Codeberg release, upload the zip and checksum, then publish it" +run = ''' +set -eu +: "${CODEBERG_TOKEN:?set CODEBERG_TOKEN in mise.local.toml}" + +VER="$(sed -n 's/^ \.version = "\([^"]*\)",$/\1/p' build.zig.zon)" +[ -n "$VER" ] || { echo "could not read version from build.zig.zon" >&2; exit 1; } +TAG="v$VER" +API="${WRITE_AWAY_API:-}" +if [ -z "$API" ]; then + REPO="$(jj git remote list | sed -n 's#^codeberg .*codeberg\.org[:/]\(.*\)$#\1#p' | sed 's#\.git$##')" + [ -n "$REPO" ] || { echo "no codeberg.org remote named codeberg" >&2; exit 1; } + API="https://codeberg.org/api/v1/repos/$REPO" +fi +# Both assets must exist before anything is created. +ZIP="zig-out/release/Write_Away-$VER-macos-arm64.zip" +SUMS="zig-out/release/SHA256SUMS" +for f in "$ZIP" "$SUMS"; do + [ -f "$f" ] || { echo "missing release asset: $f" >&2; exit 1; } +done + +BODY="$(mktemp)" +trap 'rm -f "$BODY"' 0 +# call <expected status> <curl args...>: leaves the response in $BODY. +call() { + WANT="$1" + shift + STATUS="$(curl -sS -o "$BODY" -w '%{http_code}' -H "Authorization: token $CODEBERG_TOKEN" "$@")" + case " $WANT " in + *" $STATUS "*) ;; + *) echo "HTTP $STATUS, expected $WANT: $(cat "$BODY")" >&2; exit 1 ;; + esac +} + +# A published release is never touched. A draft is what a failed run left +# behind: its assets may be from another build, so start it over. +call "200 404" "$API/releases/tags/$TAG" +if [ "$STATUS" = 200 ]; then + if [ "$(jq .draft "$BODY")" != true ]; then + echo "$TAG is already published" >&2 + exit 1 + fi + call 204 -X DELETE "$API/releases/$(jq -er .id "$BODY")" +fi + +call 201 -H "Content-Type: application/json" \ + -d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"draft\":true,\"prerelease\":false}" "$API/releases" +ID="$(jq -er .id "$BODY")" +for f in "$ZIP" "$SUMS"; do + call 201 -F "attachment=@$f" "$API/releases/$ID/assets?name=$(basename "$f")" +done +call 200 -X PATCH -H "Content-Type: application/json" -d '{"draft":false}' "$API/releases/$ID" + +call 200 "$API/releases/latest" +[ "$(jq -r .tag_name "$BODY")" = "$TAG" ] || { echo "published, but the latest release is not $TAG" >&2; exit 1; } +jq -r .html_url "$BODY" +''' |
