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.
77 lines
3.3 KiB
Shell
Executable file
77 lines
3.3 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
# deploy-site.sh <dev|production> <dir>: deploys the site Worker from a
|
|
# verified Build Output artifact (<dir>, site/.cloudflare/output from Site's
|
|
# build job) with the cf CLI pinned in cf/package-lock.json, which the
|
|
# workflow installs (npm ci --ignore-scripts) before the token is in reach.
|
|
#
|
|
# The artifact was built from repository code without secrets, so everything
|
|
# in it is untrusted. The Worker's code and assets may change freely, but the
|
|
# config cf deploys must name exactly this mode's Worker, routes, and
|
|
# bindings: the deploy token can write every Worker on the account, and a
|
|
# binding grants the Worker access to its resource. Any other key, Worker, or
|
|
# Container is refused; changing them means changing this script.
|
|
. "$(dirname "$0")/lib.sh"
|
|
|
|
mode=$1
|
|
case "$mode" in
|
|
dev)
|
|
worker=hex-dev-site host=dev.anoma.ly
|
|
;;
|
|
production)
|
|
worker=hex-production-site host=anoma.ly
|
|
;;
|
|
*) die "Unknown site mode: $mode" ;;
|
|
esac
|
|
# The frozen 2.3.1 files are the only bucket content left, the same for both
|
|
# environments, and the Worker only reads them; CI holds no R2 credential.
|
|
bucket=hex-production-files
|
|
: "${CLOUDFLARE_API_TOKEN:?Set CLOUDFLARE_API_TOKEN}"
|
|
: "${CLOUDFLARE_ACCOUNT_ID:?Set CLOUDFLARE_ACCOUNT_ID}"
|
|
|
|
src=$(cd "$2" && pwd)
|
|
release=$(cd "$(dirname "$0")" && pwd)
|
|
|
|
# Only the Build Output files cf reads; nothing else is copied to where cf runs.
|
|
unexpected=$(cd "$src" && find . ! -type d ! -type f -o -type f ! -path ./SHA256SUMS \
|
|
! -path ./v0/config.json \
|
|
! -path ./v0/workers/default/worker.config.json \
|
|
! -path './v0/workers/default/bundle/*' \
|
|
! -path './v0/workers/default/assets/*')
|
|
[ -z "$unexpected" ] || die "Unexpected files in the site artifact: $unexpected"
|
|
|
|
jq -e --arg mode "$mode" '. == {buildContext: {isPreview: false, mode: $mode}}' \
|
|
"$src/v0/config.json" > /dev/null || die "The site's root config is not a $mode build"
|
|
|
|
jq -e --arg worker "$worker" --arg host "$host" --arg bucket "$bucket" '
|
|
(keys - ["name", "compatibilityDate", "compatibilityFlags", "assets", "triggers",
|
|
"workersDev", "previewUrls", "env", "manifest"]) == []
|
|
and .name == $worker
|
|
and (.compatibilityDate | type) == "string"
|
|
and ((.compatibilityFlags // []) | all(type == "string"))
|
|
and .assets == {runWorkerFirst: true}
|
|
and .triggers == [
|
|
{type: "fetch", pattern: "\($host)/hex", zone: "anoma.ly"},
|
|
{type: "fetch", pattern: "\($host)/hex/*", zone: "anoma.ly"}
|
|
]
|
|
and .workersDev == false
|
|
and .previewUrls == false
|
|
and .env == {
|
|
ASSETS: {type: "assets"},
|
|
FILES: {type: "r2", name: $bucket},
|
|
CANONICAL_HOST: {type: "text", value: $host}
|
|
}
|
|
and (.manifest | keys) == ["mainModule", "modules", "type"]
|
|
and (.manifest.mainModule | test("^[A-Za-z0-9._-]+$"))
|
|
and .manifest.modules == {}
|
|
' "$src/v0/workers/default/worker.config.json" > /dev/null ||
|
|
die "The site's Worker config is not the $mode site Worker (.github/release/deploy-site.sh)"
|
|
|
|
work=$(mktemp -d)
|
|
mkdir -p "$work/.cloudflare/output/v0/workers/default"
|
|
cp "$src/v0/config.json" "$work/.cloudflare/output/v0/"
|
|
cp -R "$src/v0/workers/default/." "$work/.cloudflare/output/v0/workers/default/"
|
|
|
|
cf="$release/cf/node_modules/.bin/cf"
|
|
[ -x "$cf" ] || die "Install the pinned cf CLI first: npm ci --ignore-scripts in .github/release/cf"
|
|
cd "$work"
|
|
"$cf" deploy --prebuilt --mode "$mode"
|