Files
lucisv/tools/publish_release.sh
Guoliang ChenandClaude Mythos 5.2 71d13b5fbe
ci / checks (push) Successful in 1m0s
ci / corpus (push) Successful in 18s
ci / linux (push) Successful in 6m4s
release / build-and-publish (push) Successful in 5m31s
Release 0.66.2: every source file names its author
Every tracked file that can carry a comment (880 of them) now opens with
"Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with
"Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love,
luciochen.com", in the file's own comment syntax. No behaviour change: the
diff outside the version bump and changelogs is comment lines only.

- tools/stamp_author.py: writes the lines; idempotent, `--check` lists
  what is missing. Headers go under a shebang and under Markdown front
  matter.
- Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON
  and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the
  LICENSE files (already carry the copyright line).
- tools/linux_check.sh: --help reads its header from line 3, now that the
  author line sits under the shebang.
- tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-24 12:11:09 -08:00

107 lines
4.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Author: Guoliang Chen, a Senior Digital Design Engineer
# Create (or reuse) the Gitea release for a tag and attach every artifact.
#
# Usage: tools/publish_release.sh <tag> <dist-dir>
#
# Written for the release workflow: expects the CI-provided environment
# (GITHUB_SERVER_URL, GITHUB_REPOSITORY, GITHUB_TOKEN) and a dist directory
# holding the artifacts plus RELEASE_NOTES.md (the release body; not
# attached). A tag containing "-" (v0.8.0-rc1) is marked prerelease.
# Re-running is safe: an existing release for the tag is reused, and an
# asset name that is already attached is skipped.
#
# Two things learned from the 0.29.0 / 0.30.0 releases (2026-09-02), whose
# uploads died with `curl: (56) ... error: 524` -- Cloudflare's origin-timeout
# page, because $GITHUB_SERVER_URL is the public host and every request goes
# through Cloudflare, which gives an origin 100 seconds to answer:
# * LUCISV_API_URL, when set (the workflow passes the repository's Actions
# variable of that name), is used for the API instead of
# $GITHUB_SERVER_URL -- a direct http://host:port the runner can reach
# without the proxy. The release link printed at the end still uses the
# public URL.
# * Every upload is retried (UPLOAD_ATTEMPTS, default 5, backing off), and
# before each retry the server is asked again what is attached: a 524 is
# Cloudflare giving up on the *response*, and the origin may well have
# finished storing the file. An asset present with the local file's
# size is treated as done; one present with a different size is deleted
# and sent again, so a truncated upload can never be published.
set -eu
[ $# -eq 2 ] || { echo "usage: $0 <tag> <dist-dir>" >&2; exit 2; }
tag=$1
dist=$2
for var in GITHUB_SERVER_URL GITHUB_REPOSITORY GITHUB_TOKEN; do
eval "[ -n \"\${$var:-}\" ]" || { echo "$var is not set" >&2; exit 2; }
done
notes="$dist/RELEASE_NOTES.md"
[ -s "$notes" ] || { echo "no release notes at $notes" >&2; exit 2; }
api="${LUCISV_API_URL:-$GITHUB_SERVER_URL}/api/v1/repos/$GITHUB_REPOSITORY"
[ -n "${LUCISV_API_URL:-}" ] && echo "using the direct API URL $LUCISV_API_URL"
attempts=${UPLOAD_ATTEMPTS:-5}
auth="Authorization: token $GITHUB_TOKEN"
prerelease=false
case $tag in *-*) prerelease=true ;; esac
# Reuse the release if a re-run already created it, else create it.
id=$(curl -sS -H "$auth" "$api/releases/tags/$tag" | jq -r '.id // empty')
if [ -n "$id" ]; then
echo "release for $tag exists (id $id), reusing"
else
payload=$(jq -n --arg tag "$tag" --rawfile body "$notes" --argjson pre "$prerelease" \
'{tag_name: $tag, name: $tag, body: $body, draft: false, prerelease: $pre}')
id=$(curl -sSf -X POST -H "$auth" -H 'Content-Type: application/json' \
-d "$payload" "$api/releases" | jq -r .id)
echo "created release $tag (id $id)"
fi
# What the server holds for this release, as "name size" lines.
attached_assets() {
curl -sS -H "$auth" "$api/releases/$id/assets" \
| jq -r '.[] | "\(.name) \(.size) \(.id)"'
}
# Attach one file, or confirm the server already has it whole. Returns 0
# once an asset with the file's name and size is on the server.
attach() {
f=$1
name=$(basename "$f")
size=$(wc -c < "$f" | tr -d ' ')
n=0
while :; do
have=$(attached_assets | awk -v n="$name" '$1 == n { print $2, $3 }')
if [ -n "$have" ]; then
have_size=${have%% *}
have_id=${have##* }
if [ "$have_size" = "$size" ]; then
[ $n -eq 0 ] && echo "already attached: $name" || echo "attached after retry: $name"
return 0
fi
echo "server holds $name at $have_size bytes, local is $size: deleting the partial upload" >&2
curl -sSf -X DELETE -H "$auth" "$api/releases/$id/assets/$have_id" >/dev/null || true
fi
n=$((n + 1))
[ $n -le "$attempts" ] || { echo "giving up on $name after $attempts attempts" >&2; return 1; }
[ $n -eq 1 ] && echo "attaching $name" || echo "attaching $name (attempt $n of $attempts)"
if curl -sSf -X POST -H "$auth" -F "attachment=@$f" \
"$api/releases/$id/assets?name=$name" >/dev/null; then
return 0
fi
# Back off before asking the server again; a proxy timeout says nothing
# about whether the origin finished.
sleep $((10 * n))
done
}
for f in "$dist"/*; do
[ -f "$f" ] || continue
[ "$(basename "$f")" = RELEASE_NOTES.md ] && continue
attach "$f"
done
echo "release $tag complete: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$tag"
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com