mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
The site build now copies install-linux.sh, install-windows.ps1, and packaging/macos/legacy-appcast.xml into its Worker assets, so the same Worker serves them at /hex/files with the Content-Type and Cache-Control the bucket objects had. The Installers and Legacy appcast workflows, r2-put.sh, and their R2 write credential are gone. The dev notes move to the one-commit dev-notes branch, published by Release's dev-notes job with GITHUB_TOKEN only; the Worker proxies that file at /hex/files/dev-notes.json (falling back to the bucket copy until the first dev release creates the branch) and renders /hex/dev from it. Both site Workers now bind hex-production-files, read-only in code, for the frozen 2.3.1 feeds and artifacts, which lets hex-dev-files go. The Site build runs the installer test and appcast check the removed workflows ran, and the verify job compares the served bytes.
68 lines
3.8 KiB
Shell
68 lines
3.8 KiB
Shell
#!/usr/bin/env bash
|
|
# publish-dev-notes.sh <dev-notes.json> <version> <commit>: checks the dev
|
|
# channel's notes, written without secrets by scripts/release-dev-notes.sh,
|
|
# and publishes them as dev-notes.json on the one-commit `dev-notes` branch.
|
|
# The site Worker serves that file at
|
|
# https://anoma.ly/hex/files/dev-notes.json and renders
|
|
# https://anoma.ly/hex/dev from it, so a new dev build shows without a site
|
|
# deploy and no job needs a bucket credential.
|
|
#
|
|
# The file is untrusted data: the site renders it and the app shows it, so it
|
|
# must be the expected shape, put this build first, and link only to this
|
|
# repository's pull requests and commits. The branch is replaced, not
|
|
# appended to, so its history never grows.
|
|
. "$(dirname "$0")/lib.sh"
|
|
|
|
[ $# -eq 3 ] || die "Usage: publish-dev-notes.sh <dev-notes.json> <version> <commit>"
|
|
file=$1 version=$2 commit=$3
|
|
[ -f "$file" ] || die "$file does not exist."
|
|
: "${GH_TOKEN:?Set GH_TOKEN}"
|
|
: "${GITHUB_REPOSITORY:?Set GITHUB_REPOSITORY}"
|
|
repository=$GITHUB_REPOSITORY
|
|
branch=dev-notes
|
|
path=dev-notes.json
|
|
# One JSON document, re-emitted by jq: what is published is exactly what was
|
|
# checked, valid UTF-8 without duplicate keys.
|
|
canonical=$(mktemp)
|
|
trap 'rm -f "$canonical"' EXIT
|
|
jq -se 'length == 1' "$file" > /dev/null || die "The dev notes are not one JSON document."
|
|
jq -c '.' "$file" > "$canonical" || die "The dev notes are not JSON."
|
|
[ "$(wc -c < "$canonical")" -le 200000 ] || die "The dev notes are over 200 KB."
|
|
jq -e --arg version "$version" --arg commit "$commit" '
|
|
def text($max): type == "string" and length > 0 and length <= $max and all(explode[]; . >= 32 and (. < 127 or . > 159));
|
|
(keys == ["builds", "schema"]) and .schema == 1
|
|
and (.builds | type == "array" and length >= 1 and length <= 40)
|
|
and .builds[0].version == $version and .builds[0].commit == $commit
|
|
and ([.builds[].version] | length == (unique | length))
|
|
and all(.builds[];
|
|
(keys == ["commit", "items", "published_at", "version"])
|
|
and (.version | type == "string" and test("^0\\.0\\.0-dev-[0-9]+$"))
|
|
and (.commit | type == "string" and test("^[0-9a-f]{40}$"))
|
|
and (.published_at | type == "string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"))
|
|
and (.items | type == "array" and length <= 40)
|
|
and all(.items[];
|
|
(keys == ["title", "url"])
|
|
and (.title | text(200))
|
|
and (.url | type == "string"
|
|
and test("^https://github\\.com/anomalyco/hex/(pull/[0-9]{1,7}|commit/[0-9a-f]{40})$"))))
|
|
' "$canonical" > /dev/null || die "The dev notes are not the expected shape for $version ($commit)."
|
|
|
|
# Replace the branch with one commit that has no parent, so the repository
|
|
# keeps the current file and no history.
|
|
existing=$(gh api "repos/$repository/git/ref/heads/$branch" --jq .object.sha 2> /dev/null || true)
|
|
parents='[]'
|
|
[ -z "$existing" ] || parents=$(jq -cn --arg sha "$existing" '[$sha]')
|
|
blob=$(jq -cn --arg content "$(base64 -w0 < "$canonical")" '{content: $content, encoding: "base64"}' |
|
|
gh api "repos/$repository/git/blobs" --method POST --input - --jq .sha)
|
|
tree=$(jq -cn --arg blob "$blob" --arg path "$path" \
|
|
'{tree: [{path: $path, mode: "100644", type: "blob", sha: $blob}]}' |
|
|
gh api "repos/$repository/git/trees" --method POST --input - --jq .sha)
|
|
published=$(jq -cn --arg message "Dev notes for $version" --arg tree "$tree" --argjson parents "$parents" \
|
|
'{message: $message, tree: $tree, parents: $parents}' |
|
|
gh api "repos/$repository/git/commits" --method POST --input - --jq .sha)
|
|
if [ -n "$existing" ]; then
|
|
gh api "repos/$repository/git/refs/heads/$branch" --method PATCH -f sha="$published" -F force=true > /dev/null
|
|
else
|
|
gh api "repos/$repository/git/refs" --method POST -f ref="refs/heads/$branch" -f sha="$published" > /dev/null
|
|
fi
|
|
echo "Published the notes for $version: https://anoma.ly/hex/dev#$version"
|