sirius-press/tools/build.sh
Silent Mode 961cb108ca build(sirius-press): build from the vendored subtree instead of a download
The subtree is in place, so everything that used to fetch and patch core at
build time now just copies it.

  tools/build.sh        copies wordpress/ — no download, no checksum step,
                        because there is nothing to fetch and nothing to
                        trust that is not already in the repository
  docker/Dockerfile     COPY wordpress/ instead of curl + sha256 + patch;
                        the build args and the `patch` package are gone
  docker-compose.yml    no WP_VERSION / WP_URL / WP_SHA256 to keep in step

tools/update-wordpress.sh is rewritten around what the subtree makes
possible. It imports the pristine release onto sirius-press/wordpress-upstream
and then `git subtree merge`s that branch, which three-way merges upstream
against the fork's own commit. A patch either applies with fuzz and hopes or
fails and leaves you re-deriving the change by hand; a merge conflict is
resolved once, in the file, and the next release merges against the
resolution.

patches/ survives as documentation rather than mechanism, and is now
generated: tools/refresh-patches.sh diffs the subtree against the pristine
import and rewrites the directory, with --check for CI. It answers the
question anyone auditing a fork asks first — what exactly did you change
inside WordPress? — in a minute, which `git log wordpress/` cannot, because
that log is mostly upstream imports. Generated documentation stays true; a
hand-maintained record of a core diff drifts, and a stale one is worse than
none because people trust it.

One test change worth noting: the syntax sweep no longer walks all of
wordpress/. It lints the fork's own PHP plus every core file patches/ says
the fork touches, which keeps the suite at seven seconds instead of a minute
while still covering the only core file that can break.
2026-09-21 03:19:28 +02:00

108 lines
3.8 KiB
Bash

#!/usr/bin/env bash
# build.sh — assemble a complete Sirius Press tree.
#
# Copies the vendored WordPress from wordpress/, drops this repository's
# plugins and must-use plugins into it, and leaves the result in
# dist/sirius-press/.
#
# With --zip it also produces dist/sirius-press-<version>.zip, which is the
# artifact shared-hosting users upload.
#
# There is no download and no checksum step, because there is nothing to
# fetch: core is in the repository, already patched, and what you build is
# exactly what you can read in `git log wordpress/`. Moving to a new upstream
# release is tools/update-wordpress.sh, not a flag here.
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$here"
# shellcheck source=wordpress.lock
source tools/wordpress.lock
VERSION="$(grep -m1 "^ \* Version:" plugins/sirius-press-core/sirius-press-core.php | awk '{print $3}')"
DIST="$here/dist"
TARGET="$DIST/sirius-press"
SOURCE="$here/wordpress"
MAKE_ZIP=0
for arg in "$@"; do
case "$arg" in
--zip) MAKE_ZIP=1 ;;
*) echo "unknown option: $arg" >&2; exit 2 ;;
esac
done
say() { printf '\033[1m→\033[0m %s\n' "$*"; }
die() { printf '\033[31merror:\033[0m %s\n' "$*" >&2; exit 1; }
[ -f "$SOURCE/wp-includes/version.php" ] \
|| die "wordpress/ is missing or empty — check the whole repository was cloned."
vendored="$(grep -m1 'wp_version = ' "$SOURCE/wp-includes/version.php" | sed "s/.*'\(.*\)'.*/\1/")"
if [ "$vendored" != "$WP_VERSION" ]; then
die "wordpress/ holds $vendored but tools/wordpress.lock says $WP_VERSION.
One of them is stale; tools/update-wordpress.sh keeps them in step."
fi
# ------------------------------------------------------------------ assemble
say "copying WordPress $vendored out of wordpress/"
rm -rf "$TARGET"
mkdir -p "$TARGET"
# The trailing /. copies the contents rather than nesting another directory.
cp -a "$SOURCE/." "$TARGET/"
say "installing Sirius Press plugins"
mkdir -p "$TARGET/wp-content/plugins" "$TARGET/wp-content/mu-plugins"
for plugin in plugins/*/; do
cp -R "$plugin" "$TARGET/wp-content/plugins/"
done
cp mu-plugins/*.php "$TARGET/wp-content/mu-plugins/"
say "built dist/sirius-press ($(du -sh "$TARGET" | cut -f1))"
# --------------------------------------------------------------------- zip
if [ "$MAKE_ZIP" -eq 1 ]; then
archive="$DIST/sirius-press-$VERSION.zip"
say "packing $(basename "$archive")"
rm -f "$archive"
# `zip` is the obvious tool and is missing often enough — minimal container
# images, Git Bash on Windows — that falling back to Python's zipfile is
# worth nine lines. Both produce the same archive as far as anyone
# unpacking it is concerned.
if command -v zip >/dev/null; then
( cd "$DIST" && zip -qr "$archive" sirius-press )
elif command -v python3 >/dev/null || command -v python >/dev/null; then
py="$(command -v python3 || command -v python)"
"$py" - "$DIST" "$archive" <<'PYZIP'
import os, sys, zipfile
root, archive = sys.argv[1], sys.argv[2]
base = os.path.join(root, 'sirius-press')
with zipfile.ZipFile(archive, 'w', zipfile.ZIP_DEFLATED, compresslevel=6) as z:
for folder, _dirs, files in os.walk(base):
for name in files:
full = os.path.join(folder, name)
z.write(full, os.path.relpath(full, root).replace(os.sep, '/'))
PYZIP
else
die "--zip needs either the zip command or Python."
fi
sha256sum "$archive" | cut -d' ' -f1 > "$archive.sha256"
say "$(basename "$archive")$(du -h "$archive" | cut -f1), sha256 $(cat "$archive.sha256")"
fi
cat <<EOF
Sirius Press $VERSION, on WordPress $vendored.
dist/sirius-press/ a complete tree, ready to serve
$( [ "$MAKE_ZIP" -eq 1 ] && echo " dist/sirius-press-$VERSION.zip upload this to a shared host" )
To run it locally: cd docker && docker compose up -d
To install on a VPS: see docs/install.md
EOF