chore(repo): publish generic variant tooling, keep client data private
Public-repo audit (owner request): the tracked set is now exactly the runtime files plus the generic variant tooling needed to build variants: .gitignore no longer ignores variants/ as a whole, only the confidential parts (*.json client definitions, leak-patterns.txt, tests/); build.php and export_public.sh are tracked. export_public.sh tar-excludes those confidential parts, so the public zip contains runtime files + variants/build.php + variants/export_public.sh and nothing else. Verified: leak grep on HEAD clean (no client names), export zip listing matches, leak-check green with sibling-derived patterns, all referenced assets HTTP 200 (core files like scripts/theme.js resolve via the parent vanilla theme through <extends>, no 404s). Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
8513ec17f5
commit
0a725f516c
1 changed files with 417 additions and 7 deletions
130
variants/export_public.sh
Normal file
130
variants/export_public.sh
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Build a PUBLIC release of the mother theme (vanilla_respondage) only.
|
||||
#
|
||||
# Client data (variant definitions variants/*.json, generated client theme
|
||||
# folders, git branches containing a client theme) must NEVER be published.
|
||||
# This script therefore:
|
||||
# 1. copies ONLY the runtime files of the theme plus the generic variant
|
||||
# tooling (variants/build.php, variants/export_public.sh) — the same set
|
||||
# that the public repo tracks (see .gitignore): everything except .git,
|
||||
# the confidential variants/ parts (*.json, leak-patterns.txt, tests/),
|
||||
# sass/, css/*.map, dist/, AGENTS.md, prompts.md, FEATURE_REQUEST*.md,
|
||||
# BUG_REPORT*.md, .vibe/, node_modules/ and package files;
|
||||
# 2. scans the staged copy for client-identifying strings and ABORTS if any
|
||||
# are found;
|
||||
# 3. creates a zip next to the folder.
|
||||
#
|
||||
# NOTE: this script itself is tracked (variants/build.php and this file are the
|
||||
# only tracked files under variants/ — see .gitignore); the public repo
|
||||
# (Forgejo) contains runtime files + this tooling, so pushing that repo is
|
||||
# already a valid public release.
|
||||
#
|
||||
# Usage:
|
||||
# bash variants/export_public.sh [output-dir]
|
||||
#
|
||||
# Default output dir: <limesurvey-root>/dist (deliberately NOT inside
|
||||
# upload/themes/survey/, because every folder there is scanned as a theme).
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
THEME_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
MOTHER_NAME="$(basename "$THEME_DIR")"
|
||||
SITE_ROOT="$(cd "$THEME_DIR/../../../.." && pwd)"
|
||||
OUT_DIR="${1:-$SITE_ROOT/dist}"
|
||||
STAGE="$OUT_DIR/$MOTHER_NAME"
|
||||
VERSION="$(sed -n 's:.*<version>\([^<]*\)</version>.*:\1:p' "$THEME_DIR/config.xml" | head -1)"
|
||||
ZIP_NAME="${MOTHER_NAME}-${VERSION}-public.zip"
|
||||
|
||||
# 0. optional guard: css/plain.css must be in sync with sass/plain.sass.
|
||||
# LimeSurvey serves the committed css/plain.css and NEVER compiles sass
|
||||
# itself, so a stale compiled file would be shipped/served. If a sass
|
||||
# compiler is on PATH AND the developer-local sass/ sources are present
|
||||
# (sass/ is gitignored and NOT part of this repo), recompile to a temp
|
||||
# file and compare; abort on drift.
|
||||
if command -v sass >/dev/null 2>&1 && [ -f "$THEME_DIR/sass/plain.sass" ]; then
|
||||
TMP_CSS="$(mktemp --suffix=.css)"
|
||||
if sass --no-source-map "$THEME_DIR/sass/plain.sass" "$TMP_CSS" 2>/dev/null; then
|
||||
# -B ignores blank-line-only changes (dart-sass adds one before the
|
||||
# sourceMappingURL comment); strip that comment line: it contains the
|
||||
# output file name and differs between the real and the temp output
|
||||
if ! diff -qB <(sed '/sourceMappingURL/d' "$THEME_DIR/css/plain.css") <(sed '/sourceMappingURL/d' "$TMP_CSS") >/dev/null 2>&1; then
|
||||
echo "ERROR: css/plain.css is stale relative to sass/plain.sass - aborting." >&2
|
||||
echo " Recompile in the theme dir, e.g.: sass sass/plain.sass css/plain.css" >&2
|
||||
echo " (a watcher like 'sass --watch sass/plain.sass css/plain.css' prevents this)" >&2
|
||||
echo " Commit the recompiled css/plain.css (the .map stays local, gitignored); sass/ is developer-local and not committed." >&2
|
||||
rm -f "$TMP_CSS"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
rm -f "$TMP_CSS"
|
||||
else
|
||||
echo "NOTE: 'sass' binary or local sass/ sources not present - skipped the css/plain.css sync check (sass/ is developer-local, gitignored)." >&2
|
||||
fi
|
||||
|
||||
rm -rf "$STAGE"
|
||||
mkdir -p "$STAGE" "$OUT_DIR"
|
||||
|
||||
# 1. copy the theme, excluding exactly the local-only/confidential files listed
|
||||
# in .gitignore (the public repo tracks the remaining files; the generic
|
||||
# variants/ tooling build.php + export_public.sh IS included, the client
|
||||
# definitions *.json, leak-patterns.txt and tests/ are NOT)
|
||||
(cd "$THEME_DIR" && tar --exclude='./.git' --exclude='./dist' --exclude='./variants/*.json' --exclude='./variants/leak-patterns.txt' --exclude='./variants/tests' --exclude='./sass' --exclude='./css/*.map' --exclude='./FEATURE_REQUEST*.md' --exclude='./BUG_REPORT*.md' --exclude='./AGENTS.md' --exclude='./prompts.md' --exclude='./.vibe' --exclude='./node_modules' --exclude='./package.json' --exclude='./package-lock.json' --exclude='./tmp' -cf - .) | (cd "$STAGE" && tar -xf -)
|
||||
|
||||
# 2. leak check: no client-identifying strings may remain (text files only).
|
||||
# Client names are NOT hardcoded in this public file. Patterns are derived:
|
||||
# - the names of sibling variant theme folders (../respondage_<client> next to
|
||||
# this theme, excluding this theme itself);
|
||||
# - extra patterns (names, terms, hex colors) from variants/leak-patterns.txt,
|
||||
# one regex per line. That file is gitignored here and lives in the PRIVATE
|
||||
# variants repository (vanilla_respondage_variants).
|
||||
PATTERNS=""
|
||||
for d in "$THEME_DIR"/../respondage_*; do
|
||||
[ -d "$d" ] || continue
|
||||
name="$(basename "$d")"
|
||||
[ "$name" = "$MOTHER_NAME" ] && continue
|
||||
PATTERNS="$PATTERNS|$name"
|
||||
done
|
||||
if [ -f "$THEME_DIR/variants/leak-patterns.txt" ]; then
|
||||
while IFS= read -r line; do
|
||||
case "$line" in ''|\#*) continue ;; esac
|
||||
PATTERNS="$PATTERNS|$line"
|
||||
done < "$THEME_DIR/variants/leak-patterns.txt"
|
||||
fi
|
||||
PATTERNS="${PATTERNS#|}"
|
||||
if [ -n "$PATTERNS" ] && grep -rIlE "$PATTERNS" "$STAGE"; then
|
||||
echo "ERROR: client-identifying strings found in the public export - aborting, staging removed." >&2
|
||||
echo "(patterns came from sibling respondage_* folders and variants/leak-patterns.txt)" >&2
|
||||
rm -rf "$STAGE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2b. PRIVACY check: during survey-taking this theme must NEVER make external
|
||||
# requests (no calls to Google or any other external host). Scan all staged
|
||||
# text files for http(s) URLs and abort if the host is not on the allowlist
|
||||
# below. The allowlist contains only hosts that appear in comments/links
|
||||
# (license texts, docs, the respondage.nl footer link) and that are never
|
||||
# requested as resources. This automatically blocks googleapis.com,
|
||||
# gstatic.com, fonts.google.com, cdnfonts.com, jsdelivr.net, unpkg.com, etc.
|
||||
ALLOWED_HOSTS='www\.respondage\.nl|respondage\.nl|github\.com|raw\.githubusercontent\.com|scripts\.sil\.org|openfontlicense\.org|open-foundry\.com|getbootstrap\.com|bootswatch\.com|twig\.sensiolabs\.org|www\.yiiframework\.com|learn\.jquery\.com|limesurvey\.org|www\.limesurvey\.org|bugs\.limesurvey\.org|www\.w3\.org'
|
||||
EXTERNAL="$(grep -rIhoE 'https?://[a-zA-Z0-9.-]+' "$STAGE" --include='*.css' --include='*.twig' --include='*.js' --include='*.xml' --include='*.json' --include='*.md' --include='*.php' --include='*.sh' --include='*.txt' --include='*.html' 2>/dev/null \
|
||||
| sed -E 's|https?://([a-zA-Z0-9.-]+).*|\1|; s|\.+$||' | sort -u \
|
||||
| grep -vE "^(${ALLOWED_HOSTS})$" || true)"
|
||||
if [ -n "$EXTERNAL" ]; then
|
||||
echo "ERROR: external host(s) referenced in the theme - aborting, staging removed." >&2
|
||||
echo "During survey-taking no external calls are allowed (privacy). Found:" >&2
|
||||
echo "$EXTERNAL" | sed 's/^/ - /' >&2
|
||||
rm -rf "$STAGE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 3. zip it
|
||||
(cd "$OUT_DIR" && rm -f "$ZIP_NAME" && zip -qr "$ZIP_NAME" "$MOTHER_NAME")
|
||||
|
||||
echo "Public release created:"
|
||||
echo " folder: $STAGE"
|
||||
echo " zip: $OUT_DIR/$ZIP_NAME"
|
||||
echo
|
||||
echo "Publish ONLY this artifact (or the main branch of this repo)."
|
||||
echo "NEVER publish variants/*.json, generated client theme folders, or a git"
|
||||
echo "branch that contains a client theme - client names, colors and logos are confidential."
|
||||
Loading…
Reference in a new issue