#!/bin/sh # Assemble the exact URL layout documented in .gitea/README.md from committed # Git revisions. Using git archive, rather than copying the working tree, keeps # uncommitted experiments and ignored pack exports out of published images. set -eu repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) cd "$repo_root" dev_ref=${1:-HEAD} packwiz_bin=${PACKWIZ_BIN:-packwiz} build_root="$repo_root/.build" site_root="$build_root/site" work_root="$build_root/work" if ! command -v "$packwiz_bin" >/dev/null 2>&1; then echo "Packwiz executable not found: $packwiz_bin" >&2 exit 1 fi rm -rf "$site_root" "$work_root" mkdir -p "$site_root/forever/releases" "$work_root" export_pack() { revision=$1 pack=$2 destination=$3 scratch="$work_root/export" rm -rf "$scratch" mkdir -p "$scratch" "$(dirname -- "$destination")" if ! git cat-file -e "$revision:$pack/pack.toml" 2>/dev/null; then return 1 fi git archive "$revision" "$pack" | tar -x -C "$scratch" mv "$scratch/$pack" "$destination" # Source packs intentionally omit internal hashes. Generate the distributable # index only in the ephemeral image-build tree, never in the Git checkout. ( cd "$destination" "$packwiz_bin" refresh --build ) } # main is always the development source, including when this script runs for a # release-tag event whose checked-out commit is intentionally older than main. export_pack "$dev_ref" forever "$site_root/forever/dev" # Each forever-vX.Y.Z tag becomes an immutable URL. Version-aware Git sorting # also identifies the newest release to copy to the stable channel. release_tags=$(git tag --list 'forever-v*' --sort=-version:refname \ | grep -E '^forever-v[0-9]+\.[0-9]+\.[0-9]+$' || true) for tag in $release_tags; do version=${tag#forever-} export_pack "$tag" forever "$site_root/forever/releases/$version" echo "Published Forever release $version" done latest_tag=$(printf '%s\n' "$release_tags" | sed -n '/./{p;q;}') if [ -n "$latest_tag" ]; then export_pack "$latest_tag" forever "$site_root/forever/stable" echo "Promoted ${latest_tag#forever-} to Forever stable" else echo "No forever-vX.Y.Z tag exists; /forever/stable is not published yet" >&2 fi rm -rf "$work_root"