mirror of
https://github.com/bitbaum/fleet.git
synced 2026-12-04 04:47:24 +01:00
render-app.sh --workflow-ref v1 pins the merge sweep, composition check and deploy to a release tag instead of @main, so a change to bitbaum's workflows reaches a client's repository as an update it can see. Not a new placeholder: Loki renders the same template with its own four. test-app-template.sh checks both the pinning and that only a release tag is accepted (48 passed). docs/builders.md: what applies to a builder invited to one project, linking each fact to where it lives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmsUci3JMszzVB3ZhZZ
89 lines
4.1 KiB
Bash
Executable File
89 lines
4.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Render templates/app — the one starter every new bitbaum product is created
|
|
# from — into a directory, with its placeholders filled in.
|
|
#
|
|
# scripts/templates/render-app.sh <slug> <dest> [--title "Name"] [--host h] [--owner o] [--workflow-ref v1]
|
|
#
|
|
# Placeholders (the same four Loki's new-site.sh substitutes):
|
|
# __SLUG__ repo + package name, DNS label (a-z0-9-, required)
|
|
# __TITLE__ display name (default: the slug)
|
|
# __HOST__ public host (default: <slug>.orangecat.ch)
|
|
# __WORKFLOW_OWNER__ GitHub owner of the repo/loki (default: bitbaum)
|
|
#
|
|
# --workflow-ref pins the shared workflows (the merge sweep, the composition
|
|
# check, the deploy) to a release tag instead of `@main`. A repository bitbaum
|
|
# does not own (a client's) uses it, so a change to bitbaum's workflows reaches
|
|
# that client through an update PR it can see, not on bitbaum's next push. Not a
|
|
# placeholder: Loki renders this template with its own list of four, and a new
|
|
# one it does not know would ship unrendered.
|
|
#
|
|
# `gitignore` is shipped without its dot (a file named .gitignore inside a
|
|
# template would ignore the template's own files) and renamed here.
|
|
#
|
|
# A title is substituted into TypeScript string literals and Markdown, so the
|
|
# characters that could end a literal or open markup are refused rather than
|
|
# escaped per file type: a renderer that knows nothing about the files it fills
|
|
# cannot escape correctly for all of them.
|
|
set -euo pipefail
|
|
|
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
TEMPLATE="$HERE/../../templates/app"
|
|
|
|
SLUG="${1:-}"; DEST="${2:-}"
|
|
[ -n "$SLUG" ] && [ -n "$DEST" ] || { sed -n '2,20p' "$0" >&2; exit 2; }
|
|
shift 2
|
|
TITLE="$SLUG"; HOST=""; OWNER="bitbaum"; WORKFLOW_REF=""
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--title) TITLE="$2"; shift 2 ;;
|
|
--host) HOST="$2"; shift 2 ;;
|
|
--owner) OWNER="$2"; shift 2 ;;
|
|
--workflow-ref) WORKFLOW_REF="$2"; shift 2 ;;
|
|
*) echo "unknown argument: $1" >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
HOST="${HOST:-$SLUG.orangecat.ch}"
|
|
|
|
[[ "$SLUG" =~ ^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$ ]] \
|
|
|| { echo "slug must be lowercase letters, digits and hyphens" >&2; exit 2; }
|
|
[[ "$HOST" =~ ^[a-z0-9.-]+$ ]] || { echo "host must be a plain hostname" >&2; exit 2; }
|
|
[[ "$OWNER" =~ ^[A-Za-z0-9-]+$ ]] || { echo "owner must be a GitHub login" >&2; exit 2; }
|
|
[ -z "$WORKFLOW_REF" ] || [[ "$WORKFLOW_REF" =~ ^v[0-9]+(\.[0-9]+){0,2}$ ]] \
|
|
|| { echo "workflow ref must be a release tag such as v1 or v1.2.0" >&2; exit 2; }
|
|
case "$TITLE" in
|
|
*'"'*|*"\\"*|*'`'*|*'$'*|*'<'*|*'>'*|*'|'*|*'&'*)
|
|
echo "title may not contain \" \\ \` \$ < > | &" >&2; exit 2 ;;
|
|
esac
|
|
[ -n "$TITLE" ] || { echo "title is empty" >&2; exit 2; }
|
|
|
|
[ -e "$DEST" ] && [ -n "$(ls -A "$DEST" 2>/dev/null)" ] && { echo "$DEST is not empty" >&2; exit 1; }
|
|
mkdir -p "$DEST"
|
|
|
|
# Copy what git tracks (or the tree, outside a checkout), never build output.
|
|
( cd "$TEMPLATE" && tar --exclude=node_modules --exclude=.next --exclude='*.tsbuildinfo' \
|
|
--exclude=next-env.d.ts -cf - . ) | ( cd "$DEST" && tar -xf - )
|
|
mv "$DEST/gitignore" "$DEST/.gitignore"
|
|
|
|
esc() { printf '%s' "$1" | sed 's/[&|\\]/\\&/g'; }
|
|
grep -rlZ --exclude-dir=node_modules -e '__SLUG__' -e '__TITLE__' -e '__HOST__' -e '__WORKFLOW_OWNER__' "$DEST" \
|
|
| xargs -0 -r sed -i \
|
|
-e "s|__SLUG__|$(esc "$SLUG")|g" \
|
|
-e "s|__TITLE__|$(esc "$TITLE")|g" \
|
|
-e "s|__HOST__|$(esc "$HOST")|g" \
|
|
-e "s|__WORKFLOW_OWNER__|$(esc "$OWNER")|g"
|
|
|
|
if [ -n "$WORKFLOW_REF" ]; then
|
|
# Only the shared workflows' own references move; nothing else says @main.
|
|
sed -i -E "s#(uses: [A-Za-z0-9-]+/(fleet|loki)/\.github/workflows/[A-Za-z0-9._-]+\.ya?ml)@main#\1@${WORKFLOW_REF}#" \
|
|
"$DEST"/.github/workflows/*.yml
|
|
if grep -nE 'uses: [A-Za-z0-9-]+/(fleet|loki)/\.github/workflows/.*@main' "$DEST"/.github/workflows/*.yml; then
|
|
echo "a shared workflow is still on @main" >&2; exit 1
|
|
fi
|
|
fi
|
|
|
|
if left=$(grep -rln --exclude-dir=node_modules -e '__SLUG__' -e '__TITLE__' -e '__HOST__' -e '__WORKFLOW_OWNER__' "$DEST"); then
|
|
echo "placeholders left unfilled in: $left" >&2; exit 1
|
|
fi
|
|
echo "rendered templates/app as $SLUG into $DEST"
|