A deploy-uom job after the release, on uom-deploy-runner (the runner the website's own deploy uses). It asks the running core whether it can load the release (coreApi against MODULE_API_VERSION) and warns and changes nothing if not; otherwise it rewrites the uo entry of MODULES in the site's .env in place, recreates only the app container, and waits for core to register the new version, rolling back to the previous one if it does not. A redeploy dispatch input publishes nothing and rolls the newest release out again, for a deploy that was skipped until the site's core caught up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014HJEmd5sBSpNXicS4gmT1t
691 lines
36 KiB
YAML
691 lines
36 KiB
YAML
# Build and publish the installable bundle: `module-uo-<version>.tar.gz` plus the
|
|
# manifest carrying its sha256 (docs/website/MODULE_SYSTEM.md §2.3, §2.5).
|
|
#
|
|
# ── What a release IS here ──────────────────────────────────────────────────
|
|
#
|
|
# **An operator never builds anything** (MODULE_SYSTEM.md §1.14 — the constraint
|
|
# the whole module system is shaped around). So a release is not source: it is the
|
|
# directory core's loader expects to find at `modules/uo/`, already assembled —
|
|
# the prebuilt client chunk, the one runtime dependency installed, the schema
|
|
# fragment and the OpenAPI fragment — packed as it will be unpacked. Phase 4's
|
|
# admin install downloads the tarball, verifies it against the `sha256` in the
|
|
# manifest, and unpacks it onto the volume. Nothing runs `npm` on the way.
|
|
#
|
|
# ── The version is DERIVED, and the declaration is a floor ──────────────────
|
|
#
|
|
# This file used to release only when a merge to `main` left `module.json` at a
|
|
# version with no release yet — the version DECLARED, never computed, on the
|
|
# argument that two sources for one number is how they drift. That was true and
|
|
# it was still the wrong trade: it makes every bundle cost a second reviewed PR
|
|
# whose entire content is a number, and between 2026-08-12 and 2026-08-19 it cost
|
|
# this repo *every* bundle — v0.3.0 was the only release while nine phases of
|
|
# Teams work landed, because nothing in them touched that line.
|
|
#
|
|
# So the engine `link` and `installer` already run is adopted here (MODULE_SYSTEM
|
|
# §2.7.1, decision 19 as amended):
|
|
#
|
|
# feat!: / BREAKING CHANGE -> major feat: -> minor fix|perf: -> patch
|
|
# nothing releasable -> no release is cut
|
|
# (first ever run, no tag) -> releases what module.json declares
|
|
#
|
|
# **The declared version is kept as a floor, not deleted.** If `module.json` names
|
|
# a version above the newest tag, that version releases — which is the old model
|
|
# exactly, surviving as the special case it always was. Raising it by hand is
|
|
# still how you say "this one is a minor, whatever the subjects imply", and it is
|
|
# still the natural place to move when a `coreApi` bump forces the question. What
|
|
# no longer happens is a merge full of `feat:` producing nothing.
|
|
#
|
|
# The number that ships is therefore the TAG, and CI writes it into the
|
|
# `module.json` inside the bundle at assembly time. The committed `module.json` is
|
|
# a floor and a starting point, not a record of the last release — `link` reached
|
|
# the same arrangement with `Cargo.toml`, for the same reason: a release engine
|
|
# that has to commit a bump back to `main` stops working the day someone protects
|
|
# the branch, and this one is protected.
|
|
#
|
|
# ── The backdoor ────────────────────────────────────────────────────────────
|
|
#
|
|
# `workflow_dispatch` publishes on demand, for the case the rules above cannot
|
|
# reach: `module.json` changed in a way worth shipping — a widened `coreApi`, a
|
|
# new mount, a capability — with no releasable code behind it. Leave `version`
|
|
# blank to bump the newest tag by `bump` (default `patch`), or name an exact
|
|
# version to publish that. A dispatch releases even when nothing in the log is
|
|
# releasable; that is the entire point of pressing the button.
|
|
#
|
|
# Re-running on a version that is already released is a no-op, so a rerun after an
|
|
# unrelated failure is safe. A tag that exists with no release behind it is NOT a
|
|
# no-op — see the recovery branch in the plan step.
|
|
#
|
|
# This workflow still never writes to a branch. It tags and publishes, so `main`
|
|
# needs no push exception.
|
|
#
|
|
# ── And then the uom site ────────────────────────────────────────────────────
|
|
#
|
|
# A published release is rolled onto the uom site by the `deploy-uom` job at the
|
|
# bottom, the module's twin of `website`'s `build-images.yml` deploy. Dispatching
|
|
# with `redeploy = true` publishes nothing and rolls the newest release out
|
|
# again — for a deploy that was skipped because the site's core was too old.
|
|
#
|
|
# Prerequisites (Settings → Actions → Secrets on RunicGateway/Module-uo):
|
|
# REGISTRY_TOKEN — Gitea access token with `write:repository`, to push the tag
|
|
# and create the release.
|
|
|
|
name: Release
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: 'Exact version to publish (e.g. 0.4.1). Blank = bump the newest tag by the level below.'
|
|
required: false
|
|
default: ''
|
|
bump:
|
|
description: 'Bump level when version is blank: patch | minor | major'
|
|
required: false
|
|
default: 'patch'
|
|
redeploy:
|
|
description: 'true = publish nothing; just roll the uom site onto the newest release'
|
|
required: false
|
|
default: 'false'
|
|
|
|
concurrency:
|
|
group: release-module-uo
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
GITEA_HOST: gitea.whitlocktech.com
|
|
REPO: RunicGateway/Module-uo
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
# Read by `deploy-uom` below: whether there is something to roll out, and which.
|
|
outputs:
|
|
deploy: ${{ steps.plan.outputs.deploy }}
|
|
version: ${{ steps.plan.outputs.version }}
|
|
steps:
|
|
# Full history: the plan step reads every tag and every subject since the
|
|
# newest one, and a shallow clone has neither.
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
|
|
- name: Plan the release (version + changelog)
|
|
id: plan
|
|
env:
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
EVENT: ${{ github.event_name }}
|
|
IN_VERSION: ${{ github.event.inputs.version }}
|
|
IN_BUMP: ${{ github.event.inputs.bump }}
|
|
IN_REDEPLOY: ${{ github.event.inputs.redeploy }}
|
|
run: |
|
|
set -euo pipefail
|
|
mkdir -p dist
|
|
git fetch --tags --force >/dev/null 2>&1 || true
|
|
|
|
DECLARED="$(node -p "require('./module.json').version")"
|
|
LAST_TAG="$(git describe --tags --match 'v*' --abbrev=0 2>/dev/null || true)"
|
|
CURRENT="${LAST_TAG#v}"
|
|
RANGE="${LAST_TAG:+${LAST_TAG}..}HEAD"
|
|
echo "module.json declares ${DECLARED}; newest tag is ${LAST_TAG:-<none>}"
|
|
|
|
# The redeploy button: publish nothing, hand the newest tag to
|
|
# `deploy-uom`. For a deploy that was skipped (core too old) or failed,
|
|
# once whatever stopped it is fixed — a plain re-run of the workflow
|
|
# would find that version already released and deploy nothing.
|
|
if [ "${EVENT:-}" = workflow_dispatch ] && [ "${IN_REDEPLOY:-false}" = true ]; then
|
|
if [ -z "$CURRENT" ]; then
|
|
echo "::error::Redeploy asked for, but there is no release to deploy."
|
|
exit 1
|
|
fi
|
|
echo "dispatch: redeploying ${LAST_TAG} to the uom site, publishing nothing"
|
|
{
|
|
echo "version=${CURRENT}"
|
|
echo "tag=${LAST_TAG}"
|
|
echo "release=false"
|
|
echo "reuse_tag=false"
|
|
echo "bump=none"
|
|
echo "deploy=true"
|
|
} >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
SUBJECTS="$(git log --no-merges --format='%s' $RANGE || true)"
|
|
BODIES="$(git log --no-merges --format='%B' $RANGE || true)"
|
|
|
|
BUMP=none
|
|
if echo "$BODIES" | grep -qE 'BREAKING[ -]CHANGE' ; then BUMP=major; fi
|
|
if echo "$SUBJECTS" | grep -qE '^[a-z]+(\([^)]+\))?!:' ; then BUMP=major; fi
|
|
if [ "$BUMP" = none ] && echo "$SUBJECTS" | grep -qE '^feat(\([^)]+\))?:' ; then BUMP=minor; fi
|
|
if [ "$BUMP" = none ] && echo "$SUBJECTS" | grep -qE '^(fix|perf)(\([^)]+\))?:' ; then BUMP=patch; fi
|
|
|
|
bump() { # <x.y.z> <major|minor|patch> -> bumped
|
|
IFS=. read -r MA MI PA <<< "$1"
|
|
case "$2" in
|
|
major) echo "$((MA+1)).0.0" ;;
|
|
minor) echo "${MA}.$((MI+1)).0" ;;
|
|
patch) echo "${MA}.${MI}.$((PA+1))" ;;
|
|
esac
|
|
}
|
|
|
|
# `sort -V` orders version strings, so the higher of two is its last
|
|
# line. Used rather than a hand-rolled field compare because 0.10.0 vs
|
|
# 0.9.0 is exactly the comparison a string sort gets wrong.
|
|
higher() { printf '%s\n%s\n' "$1" "$2" | sort -V | tail -1; }
|
|
|
|
rank() { case "$1" in major) echo 3 ;; minor) echo 2 ;; patch) echo 1 ;; *) echo 0 ;; esac; }
|
|
bigger_bump() { if [ "$(rank "$1")" -ge "$(rank "$2")" ]; then echo "$1"; else echo "$2"; fi; }
|
|
|
|
VERSION=""
|
|
if [ -n "${IN_VERSION:-}" ]; then
|
|
# The backdoor's exact form. Deliberately unvalidated against the log:
|
|
# a human typed it, and the already-released check below is the only
|
|
# guard that matters.
|
|
VERSION="${IN_VERSION}"
|
|
echo "dispatch: publishing the requested version ${VERSION}"
|
|
else
|
|
LEVEL="$BUMP"
|
|
# A dispatch with nothing releasable in the log still releases — that
|
|
# is what the button is for. Where the log DOES say something, the
|
|
# larger of the two wins rather than the input: pressing the button on
|
|
# a log full of `feat:` without touching the dropdown would otherwise
|
|
# publish its `patch` default over a minor's worth of work, and a
|
|
# version that undersells its own contents cannot be taken back.
|
|
if [ "${EVENT:-}" = workflow_dispatch ]; then
|
|
LEVEL="$(bigger_bump "$LEVEL" "${IN_BUMP:-patch}")"
|
|
if [ "$BUMP" = none ]; then
|
|
echo "dispatch: nothing releasable in the log, bumping ${LEVEL} anyway"
|
|
elif [ "$LEVEL" != "$BUMP" ]; then
|
|
echo "dispatch: the log says ${BUMP}, the run asked for ${LEVEL} — taking ${LEVEL}"
|
|
fi
|
|
fi
|
|
|
|
if [ -z "$CURRENT" ]; then
|
|
VERSION="$DECLARED" # first ever release: ship what is declared
|
|
elif [ "$LEVEL" != none ]; then
|
|
VERSION="$(bump "$CURRENT" "$LEVEL")"
|
|
fi
|
|
|
|
# The floor. A `module.json` above the newest tag releases at that
|
|
# version even when the log says nothing and even when the log says
|
|
# patch — which is the pre-2026-08-19 model, kept as a special case.
|
|
if [ -n "$CURRENT" ] && [ "$DECLARED" != "$CURRENT" ] \
|
|
&& [ "$(higher "$DECLARED" "$CURRENT")" = "$DECLARED" ]; then
|
|
if [ -z "$VERSION" ] || [ "$(higher "$DECLARED" "$VERSION")" = "$DECLARED" ]; then
|
|
echo "module.json declares ${DECLARED}, above both ${CURRENT} and the derived version — releasing that."
|
|
VERSION="$DECLARED"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
RELEASE=true
|
|
if [ -z "$VERSION" ]; then
|
|
RELEASE=false
|
|
VERSION="$CURRENT"
|
|
echo "Nothing releasable since ${LAST_TAG} (no feat/fix/perf/breaking subject) — standing down."
|
|
fi
|
|
|
|
# An existing tag is NOT automatically "nothing to do". A tag with no
|
|
# release behind it means a previous run tagged and then died before
|
|
# publishing — which is what happened on servuo-plugins' first release,
|
|
# where absent secrets took the release API call to 401 after the tag
|
|
# had already been pushed. Standing down on the tag alone makes that
|
|
# state permanent. Note this deliberately OVERRIDES the RELEASE=false
|
|
# above: with the tag in place there is nothing releasable after it, so
|
|
# the normal path would stand down, which is why it could never
|
|
# self-heal. Anything other than 200/404 — a network failure, a bad
|
|
# token — is not evidence of absence, and guessing "no" would publish
|
|
# over a good release, so refuse instead.
|
|
REUSE_TAG=false
|
|
if [ -n "$VERSION" ] && git rev-parse -q --verify "refs/tags/v${VERSION}" >/dev/null; then
|
|
CI_TOKEN="$(printf '%s' "${REGISTRY_TOKEN:-}" | tr -d '\r\n')"
|
|
REL_HTTP="$(curl -s -o /dev/null -w '%{http_code}' \
|
|
-H "Authorization: token ${CI_TOKEN}" \
|
|
"https://${GITEA_HOST}/api/v1/repos/${REPO}/releases/tags/v${VERSION}" || echo 000)"
|
|
case "$REL_HTTP" in
|
|
200) echo "v${VERSION} is already released — nothing to do."; RELEASE=false ;;
|
|
404) echo "::warning::Tag v${VERSION} exists but has no release — a previous run failed after tagging. Reusing the tag and publishing the release it is missing."
|
|
REUSE_TAG=true; RELEASE=true ;;
|
|
*) echo "::error::Could not determine whether v${VERSION} is released (HTTP ${REL_HTTP}). Refusing to guess."; exit 1 ;;
|
|
esac
|
|
fi
|
|
|
|
# Changelog range. A recovery run has nothing after the tag, so
|
|
# summarize what the tag itself contains rather than emitting an empty
|
|
# list: the range that produced it, i.e. previous-tag..this-tag.
|
|
if [ "$REUSE_TAG" = true ]; then
|
|
PREV_TAG="$(git describe --tags --match 'v*' --abbrev=0 "v${VERSION}^" 2>/dev/null || true)"
|
|
CL_RANGE="${PREV_TAG:+${PREV_TAG}..}v${VERSION}"
|
|
SINCE="$PREV_TAG"
|
|
else
|
|
CL_RANGE="$RANGE"
|
|
SINCE="$LAST_TAG"
|
|
fi
|
|
CL_SUBJECTS="$(git log --no-merges --format='%s' $CL_RANGE || true)"
|
|
|
|
{
|
|
echo "## module-uo v${VERSION}"
|
|
echo
|
|
echo "Install from the website's Admin → Modules screen by pasting the URL of"
|
|
echo "\`module-uo-${VERSION}.json\`, or unpack the tarball onto the modules volume"
|
|
echo "as \`modules/uo/\`. Requires a core whose \`MODULE_API_VERSION\` satisfies"
|
|
echo "\`$(node -p "require('./module.json').coreApi")\`."
|
|
echo
|
|
FEATS="$(echo "$CL_SUBJECTS" | grep -E '^feat' || true)"
|
|
FIXES="$(echo "$CL_SUBJECTS" | grep -E '^(fix|perf)' || true)"
|
|
[ -n "$FEATS" ] && { echo "### Features"; echo "$FEATS" | sed 's/^/- /'; echo; }
|
|
[ -n "$FIXES" ] && { echo "### Fixes"; echo "$FIXES" | sed 's/^/- /'; echo; }
|
|
echo "### All changes"
|
|
if [ -n "$SINCE" ]; then echo "Since ${SINCE}:"; fi
|
|
echo "$CL_SUBJECTS" | sed 's/^/- /'
|
|
echo
|
|
echo "### Verifying this download"
|
|
echo
|
|
echo "Releases are **unsigned** — the \`sha256\` in \`module-uo-${VERSION}.json\` is the"
|
|
echo "trust anchor, and the website verifies it before unpacking."
|
|
echo
|
|
echo '```bash'
|
|
echo "sha256sum -c SHA256SUMS --ignore-missing"
|
|
echo '```'
|
|
} > dist/CHANGELOG.md
|
|
|
|
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
|
echo "tag=v${VERSION}" >> "$GITHUB_OUTPUT"
|
|
echo "release=${RELEASE}" >> "$GITHUB_OUTPUT"
|
|
echo "reuse_tag=${REUSE_TAG}" >> "$GITHUB_OUTPUT"
|
|
echo "bump=${BUMP}" >> "$GITHUB_OUTPUT"
|
|
echo "deploy=${RELEASE}" >> "$GITHUB_OUTPUT"
|
|
echo "==> release=${RELEASE} version=${VERSION} bump=${BUMP} declared=${DECLARED} last_tag=${LAST_TAG:-<none>}"
|
|
|
|
# Before anything is built or tagged, so a repo without secrets fails
|
|
# legibly rather than half-publishing: the tag push can succeed on the
|
|
# credential actions/checkout left in the local git config while the
|
|
# release API call 401s, leaving the repo tagged and unreleased.
|
|
- name: Verify release credentials are configured
|
|
if: ${{ steps.plan.outputs.release == 'true' }}
|
|
env:
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -z "$(printf '%s' "${REGISTRY_TOKEN:-}" | tr -d '\r\n')" ]; then
|
|
echo "::error::Missing Actions secret REGISTRY_TOKEN (needs write:repository) on ${REPO}."
|
|
exit 1
|
|
fi
|
|
echo "Release credentials present."
|
|
|
|
- name: Build the client chunk
|
|
if: ${{ steps.plan.outputs.release == 'true' }}
|
|
run: |
|
|
npm ci --prefix client
|
|
npm run build --prefix client
|
|
|
|
# `--omit=dev` and then PACKED: express, express-validator and swagger-autogen
|
|
# are build- and test-time only — the shipped half is handed express on `ctx`
|
|
# (MODULE_API.md §2.3) — and `ws` is the one runtime dependency. Node resolves
|
|
# it by walking up from `modules/uo/server/`, which is why it ships inside the
|
|
# tarball rather than being installed on the operator's box.
|
|
- name: Install the shipped runtime dependency
|
|
if: ${{ steps.plan.outputs.release == 'true' }}
|
|
run: npm ci --omit=dev --prefix server
|
|
|
|
# ── Assemble exactly what an operator's volume gets ──────────────────
|
|
#
|
|
# Stated as an INCLUDE list, not an exclude list. An exclude list ships
|
|
# whatever it forgot: the day someone adds `server/tools/` with a scratch
|
|
# credential in it, an exclude list packs it and nobody finds out.
|
|
#
|
|
# The list itself lives in `ci/bundle.json`, not here, because it has a
|
|
# second reader: `server/scripts/checkBundle.js` runs in PR checks and asks
|
|
# whether the list still covers everything `server/index.js` reaches. It
|
|
# was hardcoded in this file until v1.0.0 shipped without `server/commands/`
|
|
# — added by the Teams cutover, never added here — and the module died at
|
|
# the register stage on the operator's box. One declaration, two readers,
|
|
# so the next directory cannot go missing quietly.
|
|
- name: Assemble the bundle
|
|
if: ${{ steps.plan.outputs.release == 'true' }}
|
|
run: |
|
|
set -euo pipefail
|
|
VERSION="${{ steps.plan.outputs.version }}"
|
|
OUT="dist/module-uo-${VERSION}"
|
|
rm -rf "$OUT" && mkdir -p "$OUT"
|
|
|
|
# The manifest core reads — with the RELEASED version written into it.
|
|
# The committed `module.json` is a floor, not a record of the last
|
|
# release (see the header), so copying it verbatim would ship a bundle
|
|
# whose `installed_modules` row and admin screen disagree with the tag
|
|
# it came from. This is the one place the derived number becomes the
|
|
# module's own.
|
|
jq --arg v "$VERSION" '.version = $v' module.json > "$OUT/module.json"
|
|
|
|
# The two fragments, and the licence the code is under — a bundle that
|
|
# ships GPL code without its licence is not distributable.
|
|
for f in $(jq -r '.root[]' ci/bundle.json); do
|
|
cp "$f" "$OUT/"
|
|
done
|
|
|
|
# The server half, minus what never runs inside core's process.
|
|
mkdir -p "$OUT/server"
|
|
for d in $(jq -r '.server[]' ci/bundle.json); do
|
|
cp -r "server/$d" "$OUT/server/"
|
|
done
|
|
cp -r server/node_modules "$OUT/server/"
|
|
|
|
# The client half is the BUILT chunk only. `client/src` is 5,000 lines
|
|
# of source an operator has no use for and core will never read.
|
|
mkdir -p "$OUT/client/dist"
|
|
cp client/dist/entry.js "$OUT/client/dist/"
|
|
|
|
# Prove the bundle is loadable before it is published: these are the
|
|
# paths core's loader resolves out of module.json, and a release whose
|
|
# entry point is missing fails on an operator's box with a
|
|
# `startup_failed` row instead of here. The version assertion guards the
|
|
# rewrite above — a bundle that still carries the declared version would
|
|
# install under a number that is not the one it was released as.
|
|
node -e '
|
|
const fs = require("fs"), path = require("path");
|
|
const [root, want] = process.argv.slice(1);
|
|
const m = JSON.parse(fs.readFileSync(path.join(root, "module.json"), "utf8"));
|
|
if (m.version !== want) {
|
|
console.error(`bundle declares ${m.version}, but this is release ${want}`);
|
|
process.exit(1);
|
|
}
|
|
for (const p of [m.server, m.schema, m.purge, m.client.entry, "swagger-fragment.json"]) {
|
|
if (!fs.existsSync(path.join(root, p))) { console.error("bundle is missing " + p); process.exit(1); }
|
|
}
|
|
console.log("bundle contents check: ok");
|
|
' "$OUT" "$VERSION"
|
|
|
|
# ── And that it can actually LOAD ─────────────────────────────────
|
|
#
|
|
# The check above stats the paths `module.json` declares, which is a
|
|
# real question but a shallow one: v1.0.0 passed it and was still
|
|
# missing `server/commands/`, because a file reached only by a require
|
|
# inside `register()` is named nowhere in `module.json`. This resolves
|
|
# every relative require in the assembled tree and asserts the target is
|
|
# in it — asked of the artifact, so it also catches a copy that half
|
|
# failed or a list naming a path that has since moved.
|
|
#
|
|
# Run from the SOURCE tree (`server/scripts/` never ships) against the
|
|
# assembled bundle.
|
|
node server/scripts/checkBundle.js --bundle "$OUT"
|
|
|
|
tar -C dist -czf "dist/module-uo-${VERSION}.tar.gz" "module-uo-${VERSION}"
|
|
rm -rf "$OUT"
|
|
|
|
SHA="$(sha256sum "dist/module-uo-${VERSION}.tar.gz" | cut -d' ' -f1)"
|
|
SIZE="$(stat -c%s "dist/module-uo-${VERSION}.tar.gz")"
|
|
|
|
# The install manifest. Same shape as the installer's bundle JSON — a
|
|
# per-asset sha256 fetched over HTTPS, no signatures — because that is
|
|
# the model this project already has and a second one would be a second
|
|
# thing to get right (MODULE_SYSTEM.md §1.11).
|
|
jq -n \
|
|
--arg id "$(node -p "require('./module.json').id")" \
|
|
--arg name "$(node -p "require('./module.json').name")" \
|
|
--arg version "$VERSION" \
|
|
--arg coreApi "$(node -p "require('./module.json').coreApi")" \
|
|
--arg artifact "module-uo-${VERSION}.tar.gz" \
|
|
--arg sha256 "$SHA" \
|
|
--argjson size "$SIZE" \
|
|
--arg url "https://${GITEA_HOST}/${REPO}/releases/download/v${VERSION}/module-uo-${VERSION}.tar.gz" \
|
|
'{schema:1, id:$id, name:$name, version:$version, coreApi:$coreApi,
|
|
artifact:$artifact, url:$url, sha256:$sha256, size:$size}' \
|
|
> "dist/module-uo-${VERSION}.json"
|
|
|
|
echo "${SHA} module-uo-${VERSION}.tar.gz" > dist/SHA256SUMS
|
|
cat "dist/module-uo-${VERSION}.json"
|
|
|
|
# Skipped on a recovery run: the tag is already there and is the thing being
|
|
# published against.
|
|
- name: Tag the release
|
|
if: ${{ steps.plan.outputs.release == 'true' && steps.plan.outputs.reuse_tag != 'true' }}
|
|
env:
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
TAG="${{ steps.plan.outputs.tag }}"
|
|
git config user.name 'Runic Gateway CI'
|
|
git config user.email 'ci@whitlocktech.net'
|
|
git tag -a "$TAG" -m "module-uo ${TAG}"
|
|
git push origin "$TAG"
|
|
|
|
- name: Create the Gitea release and upload the bundle
|
|
if: ${{ steps.plan.outputs.release == 'true' }}
|
|
env:
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
TAG="${{ steps.plan.outputs.tag }}"
|
|
VERSION="${{ steps.plan.outputs.version }}"
|
|
API="https://${GITEA_HOST}/api/v1/repos/${REPO}"
|
|
CI_TOKEN="$(printf '%s' "${REGISTRY_TOKEN}" | tr -d '\r\n')"
|
|
|
|
REL_ID="$(curl -sSf -X POST "${API}/releases" \
|
|
-H "Authorization: token ${CI_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$(jq -n --arg tag "$TAG" --arg body "$(cat dist/CHANGELOG.md)" \
|
|
'{tag_name:$tag, name:$tag, body:$body, draft:false, prerelease:false}')" \
|
|
| jq -r '.id')"
|
|
echo "Created release ${TAG} (id=${REL_ID})"
|
|
|
|
for f in "module-uo-${VERSION}.tar.gz" "module-uo-${VERSION}.json" SHA256SUMS; do
|
|
curl -sSf -X POST "${API}/releases/${REL_ID}/assets?name=${f}" \
|
|
-H "Authorization: token ${CI_TOKEN}" \
|
|
-F "attachment=@dist/${f}" >/dev/null
|
|
echo " uploaded ${f}"
|
|
done
|
|
|
|
# ── Roll the uom site onto the release ────────────────────────────────────
|
|
#
|
|
# The website's own `build-images.yml` rolls the uom site onto every new core
|
|
# image from this same runner; this does the same for the uo module. It does
|
|
# not unpack anything itself: it points the site's MODULES declaration at the
|
|
# new release and recreates the app container, and core's own start-up
|
|
# (website `server/src/modules/declared.js`) fetches it, verifies the sha256 in
|
|
# the manifest and unpacks it — the path every operator's install takes.
|
|
#
|
|
# 1. Ask the RUNNING core whether it can load this release (the manifest's
|
|
# coreApi against its MODULE_API_VERSION). If not, warn and change
|
|
# nothing: the version already there keeps running until the site's core
|
|
# catches up, and then the Redeploy button (Run workflow, redeploy = true)
|
|
# rolls it out.
|
|
# 2. Rewrite the `uo@…` entry of the MODULES line in .env, in place (other
|
|
# entries and every other line are kept; the file keeps its owner and
|
|
# mode). No MODULES line yet, as on a site where uo was installed from
|
|
# Admin → Modules, appends one. Only id@version is ever printed — this
|
|
# file holds the site's secrets.
|
|
# 3. Recreate only the app container (not the db, not the bot) and wait for
|
|
# core to log `registered module "uo" v<version>`.
|
|
# 4. If it does not, put the entry back to the version that was running and
|
|
# recreate again, so a bad release leaves the site where it was, and fail
|
|
# the job either way.
|
|
#
|
|
# `needs: release` with the job's own `deploy` output: only a run that
|
|
# published a release (or a redeploy dispatch) gets here, and only after its
|
|
# assets are uploaded.
|
|
#
|
|
# Runner: `uom-deploy-runner`, the one `website`'s deploy job uses, on the
|
|
# production host. It needs Docker Compose and write access to the site's
|
|
# .env. The site directory defaults to the one `website`'s deploy job uses;
|
|
# set the Actions variable UOM_SITE_DIR to move it.
|
|
deploy-uom:
|
|
needs: release
|
|
if: needs.release.outputs.deploy == 'true' && github.ref == 'refs/heads/main'
|
|
runs-on: uom-deploy-runner
|
|
timeout-minutes: 20
|
|
env:
|
|
SITE_DIR: ${{ vars.UOM_SITE_DIR || '/home/perry/website' }}
|
|
VERSION: ${{ needs.release.outputs.version }}
|
|
steps:
|
|
- name: Check the running core, declare the release, restart the app
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
cd "$SITE_DIR"
|
|
|
|
manifest() { echo "https://${GITEA_HOST}/${REPO}/releases/download/v$1/module-uo-$1.json"; }
|
|
NEW="uo@${VERSION}=$(manifest "$VERSION")"
|
|
|
|
test -f .env || { echo "::error::${SITE_DIR}/.env is missing."; exit 1; }
|
|
test -w .env || { echo "::error::The runner cannot write ${SITE_DIR}/.env."; exit 1; }
|
|
COUNT="$(grep -cE '^[[:space:]]*MODULES[[:space:]]*=' .env || true)"
|
|
if [ "${COUNT:-0}" -gt 1 ]; then
|
|
echo "::error::.env sets MODULES ${COUNT} times. Leave one line, then press Redeploy."
|
|
exit 1
|
|
fi
|
|
|
|
# ── 1. Can the running core load it? ─────────────────────────────
|
|
# Asked inside the app container: it has core's own version and range
|
|
# check, and the network path core itself will use to fetch the bundle.
|
|
# Prints one line: `ok|skip <core API> <uo version now> <coreApi range>`.
|
|
if ! CHECK="$(docker compose exec -T app node -e '
|
|
const [url, want] = process.argv.slice(1)
|
|
const fs = require("fs")
|
|
const path = require("path")
|
|
const { satisfies } = require("/app/server/src/modules/semver")
|
|
const { MODULE_API_VERSION: core } = require("/app/server/src/modules/version")
|
|
let prev = "none"
|
|
try {
|
|
const dir = process.env.MODULES_DIR || "/app/modules"
|
|
prev = JSON.parse(fs.readFileSync(path.join(dir, "uo", "module.json"), "utf8")).version || "none"
|
|
} catch {}
|
|
fetch(url).then(async (r) => {
|
|
if (!r.ok) throw new Error(`the manifest answered HTTP ${r.status}`)
|
|
const m = await r.json()
|
|
if (m.id !== "uo" || m.version !== want) throw new Error(`the manifest is ${m.id}@${m.version}, not uo@${want}`)
|
|
console.log(`${satisfies(core, m.coreApi) ? "ok" : "skip"} ${core} ${prev} ${m.coreApi}`)
|
|
}).catch((e) => { console.log(`error ${e.message}`); process.exit(1) })
|
|
' "$(manifest "$VERSION")" "$VERSION")"; then
|
|
echo "::error::Could not check the running site: ${CHECK:-the app container did not answer (is it running?)}"
|
|
exit 1
|
|
fi
|
|
read -r VERDICT CORE PREV RANGE <<< "$CHECK"
|
|
echo "uom site: core API ${CORE}, uo ${PREV} on the volume; release v${VERSION} needs ${RANGE}"
|
|
|
|
if [ "$VERDICT" = skip ]; then
|
|
echo "::warning::uo v${VERSION} needs core API ${RANGE} and the uom site runs ${CORE}. Nothing changed; uo ${PREV} keeps running. Once the site's core is updated, run Release with redeploy = true."
|
|
exit 0
|
|
fi
|
|
if [ "$PREV" = "$VERSION" ] && grep -qF "$NEW" .env; then
|
|
echo "uo v${VERSION} is already declared and on the volume. Nothing to do."
|
|
exit 0
|
|
fi
|
|
|
|
# MODULES set under `environment:` in docker-compose.yml wins over .env,
|
|
# so editing .env would change nothing. Catch it before touching anything.
|
|
ENV_MODULES="$(docker compose exec -T app printenv MODULES 2>/dev/null || true)"
|
|
if [ -n "$ENV_MODULES" ] && [ "${COUNT:-0}" -eq 0 ]; then
|
|
echo "::error::The app has MODULES set but .env has no MODULES line, so it comes from docker-compose.yml's environment:, which wins over .env. Move it into .env, then press Redeploy."
|
|
exit 1
|
|
fi
|
|
|
|
# Core logs `registered module` at info. With a quieter LOG_LEVEL that
|
|
# line never reaches `docker compose logs`, so success is judged by the
|
|
# volume instead (failures are logged at error and still show).
|
|
LOG_LEVEL_NOW="$(docker compose exec -T app printenv LOG_LEVEL 2>/dev/null || true)"
|
|
case "$(echo "${LOG_LEVEL_NOW:-info}" | tr '[:upper:]' '[:lower:]')" in
|
|
warn|error) QUIET=true; echo "The app runs with LOG_LEVEL=${LOG_LEVEL_NOW}; checking the volume rather than the info log." ;;
|
|
*) QUIET=false ;;
|
|
esac
|
|
|
|
# ── 2. Point MODULES at it ───────────────────────────────────────
|
|
ORIG="$(mktemp)"; TMP="$(mktemp)"
|
|
trap 'rm -f "$ORIG" "$TMP"' EXIT
|
|
cat .env > "$ORIG"
|
|
|
|
# Rewrites the uo entry of the original file's MODULES line (or appends
|
|
# the line), then writes the result over .env in place with `cat >`, so
|
|
# the file keeps its inode, owner and mode. If that write does not land
|
|
# intact (a full disk), the original goes back before the job fails.
|
|
# Plain `[ \t]`, not `[[:space:]]`: older mawk, Ubuntu's default awk,
|
|
# has no character classes in regex literals.
|
|
set_entry() {
|
|
awk -v entry="$1" -v sq="'" '
|
|
/^[ \t]*MODULES[ \t]*=/ {
|
|
v = $0
|
|
sub(/^[ \t]*MODULES[ \t]*=[ \t]*/, "", v)
|
|
sub(/[ \t]+#.*$/, "", v)
|
|
gsub(/"/, "", v); gsub(sq, "", v)
|
|
n = split(v, parts, /[, \t]+/)
|
|
out = ""
|
|
for (i = 1; i <= n; i++) if (parts[i] != "" && parts[i] !~ /^uo@/) out = out parts[i] ","
|
|
print "MODULES=" out entry
|
|
found = 1
|
|
next
|
|
}
|
|
{ print }
|
|
END { if (!found) print "MODULES=" entry }
|
|
' "$ORIG" > "$TMP"
|
|
test -s "$TMP" || { echo "::error::Rewriting .env produced an empty file; .env left as it was."; exit 1; }
|
|
if ! { cat "$TMP" > .env && cmp -s "$TMP" .env; }; then
|
|
cat "$ORIG" > .env || true
|
|
echo "::error::Writing .env failed; the original was put back. Nothing was restarted by this step."
|
|
exit 1
|
|
fi
|
|
}
|
|
# id@version of each declared entry — never the URLs, never the rest of the file.
|
|
declared() {
|
|
local d
|
|
d="$(grep -E '^[[:space:]]*MODULES[[:space:]]*=' "$1" \
|
|
| grep -oE '[A-Za-z0-9_.-]+@[^=[:space:],]+=' | tr -d '=' | paste -sd' ' - || true)"
|
|
echo "${d:-(none)}"
|
|
}
|
|
|
|
# ── 3. Recreate the app and wait for core to say so ─────────────
|
|
# Only uo's own lines and MODULES errors are ever printed from the app log.
|
|
uo_lines() { grep -E 'module "uo"|declared module "uo|MODULES' <<< "$1" | tail -n 20 || true; }
|
|
restart_and_wait() {
|
|
local want="$1" since logs on_volume settled=0
|
|
since="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
docker compose up -d --no-deps --force-recreate app
|
|
for _ in $(seq 1 60); do
|
|
sleep 5
|
|
logs="$(docker compose logs --no-color --since "$since" app 2>&1 || true)"
|
|
if grep -qE 'could not resolve declared module "uo@|module "uo" (failed to|was not started)|MODULES: ' <<< "$logs"; then
|
|
uo_lines "$logs"
|
|
return 1
|
|
fi
|
|
# Anchored after the version, so v1.2.1 is not satisfied by v1.2.10.
|
|
if grep -qE "registered module \"uo\" v${want//./\\.}([^0-9A-Za-z.+-]|\$)" <<< "$logs"; then return 0; fi
|
|
if [ "$QUIET" = true ]; then
|
|
on_volume="$(docker compose exec -T app node -p 'require((process.env.MODULES_DIR || "/app/modules") + "/uo/module.json").version' 2>/dev/null || true)"
|
|
# The load fails, if it fails, right after the unpack. Give it
|
|
# three quiet polls on the new version before calling it good.
|
|
if [ "$on_volume" = "$want" ]; then settled=$((settled + 1)); else settled=0; fi
|
|
if [ "$settled" -ge 3 ]; then return 0; fi
|
|
fi
|
|
done
|
|
echo "No word from the app about uo v${want} after 5 minutes. Its uo lines:"
|
|
uo_lines "$logs"
|
|
return 1
|
|
}
|
|
|
|
echo "MODULES before: $(declared "$ORIG")"
|
|
set_entry "$NEW"
|
|
echo "MODULES after: $(declared .env)"
|
|
if restart_and_wait "$VERSION"; then
|
|
echo "uo v${VERSION} is registered on the uom site."
|
|
exit 0
|
|
fi
|
|
|
|
# ── 4. It did not come up: put back what was running ─────────────
|
|
if [ "$PREV" = none ]; then
|
|
echo "::error::uo v${VERSION} did not come up, and there was no earlier uo to roll back to."
|
|
exit 1
|
|
fi
|
|
echo "Rolling the uom site back to uo v${PREV}."
|
|
set_entry "uo@${PREV}=$(manifest "$PREV")"
|
|
echo "MODULES now: $(declared .env)"
|
|
if restart_and_wait "$PREV"; then
|
|
echo "::error::uo v${VERSION} did not come up on the uom site. Rolled back to v${PREV}, which is running."
|
|
else
|
|
echo "::error::uo v${VERSION} did not come up, and neither did the rollback to v${PREV}. The site is up without uo; see Admin → Modules."
|
|
fi
|
|
exit 1
|