Allow staged replacement of publication builds

This commit is contained in:
Dandaedre 2026-09-16 19:34:55 +02:00
parent fa196cc595
commit 894924dde1
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
3 changed files with 38 additions and 11 deletions

View File

@ -66,6 +66,9 @@ JSON files, which is useful for downstream automation:
```bash
./beffroi.sh all build/publication --include-json
Use `--replace` to rebuild an existing publication directory at the same path.
The previous build stays in place until the new PDFs are ready.
```
Jenkins runs the same build and publishes AES-encrypted `Reports.zip` and
@ -79,7 +82,7 @@ destination.
./beffroi.sh diagnostic-pdf DIAGNOSTIC.json OUTPUT.pdf
./beffroi.sh capture-pdf CAPTURE OUTPUT.pdf
./beffroi.sh diagnostic CAPTURE EVIDENCE_ROOT OUTPUT_DIR REFERENCE_TIME TITLE AUTHOR DATE
./beffroi.sh all NEW_OUTPUT_DIR [--include-json]
./beffroi.sh all OUTPUT_DIR [--include-json] [--replace]
./beffroi.sh package BUILD_DIR ARTIFACT_DIR
./beffroi.sh test
./beffroi.sh bootstrap

View File

@ -9,7 +9,7 @@ Usage:
./beffroi.sh diagnostic-pdf DIAGNOSTIC.json OUTPUT.pdf
./beffroi.sh capture-pdf CAPTURE OUTPUT.pdf
./beffroi.sh diagnostic CAPTURE EVIDENCE_ROOT OUTPUT_DIR REFERENCE_TIME TITLE AUTHOR DATE
./beffroi.sh all NEW_OUTPUT_DIR [--include-json]
./beffroi.sh all OUTPUT_DIR [--include-json] [--replace]
./beffroi.sh package BUILD_DIR ARTIFACT_DIR
./beffroi.sh test
./beffroi.sh bootstrap

View File

@ -2,7 +2,7 @@
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
usage() {
echo "Usage: $0 NEW_OUTPUT_ROOT [--include-json]" >&2
echo "Usage: $0 OUTPUT_ROOT [--include-json] [--replace]" >&2
exit 2
}
@ -10,24 +10,41 @@ output_root=${1:-}
[[ -n "$output_root" ]] || usage
shift
include_json=false
include_json=false replace=false
while (($#)); do
case $1 in
--include-json) include_json=true ;;
--replace) replace=true ;;
*) usage ;;
esac
shift
done
[[ ! -e "$output_root" ]]||{ echo "$output_root: output root already exists" >&2; exit 1; }
mkdir -p "$output_root/reports" "$output_root/diagnostics"
[[ ! -L "$output_root" ]] || { echo "$output_root: symlink output root is not supported" >&2; exit 1; }
output_root=$(realpath -m "$output_root")
root=$(pwd -P)
[[ "$output_root" != "$root" && "$root" != "$output_root"/* ]] || { echo "$output_root: output root cannot contain the repository" >&2; exit 1; }
[[ "$output_root" != "$root/reports" && "$output_root" != "$root/reports"/* && "$output_root" != "$root/reporter" && "$output_root" != "$root/reporter"/* ]] || { echo "$output_root: output root cannot be inside a source component" >&2; exit 1; }
[[ ! -e "$output_root" || -d "$output_root" ]] || { echo "$output_root: output root is not a directory" >&2; exit 1; }
[[ ! -e "$output_root" || "$replace" == true ]] || { echo "$output_root: output root already exists; use --replace" >&2; exit 1; }
output_parent=$(dirname "$output_root")
mkdir -p "$output_parent"
output_name=$(basename "$output_root")
stage=$(mktemp -d "$output_parent/.${output_name}.build.XXXXXXXX")
backup=
cleanup() {
if [[ -n "$backup" && -d "$backup" && ! -e "$output_root" ]]; then mv -- "$backup" "$output_root"; fi
[[ ! -d "$stage" ]] || rm -rf -- "$stage"
}
trap cleanup EXIT
mkdir -p "$stage/reports" "$stage/diagnostics"
reporter/tools/validate-all.sh reports/reports
reporter/tools/render-all.sh reports/reports --output-dir "$output_root/reports/pdfs"
reporter/tools/render-all.sh reports/reports --output-dir "$stage/reports/pdfs"
count=0
while IFS= read -r -d '' source; do
relative=${source#reports/diagnostics/}
output="$output_root/diagnostics/${relative%.json}.pdf"
output="$stage/diagnostics/${relative%.json}.pdf"
mkdir -p "$(dirname "$output")"
scripts/render-capture.sh "$source" "$output"
((count += 1))
@ -36,12 +53,19 @@ done < <(find reports/diagnostics -type f -name '*.json' -print0 | sort -z)
echo "Rendered $count diagnostic PDFs into $output_root/diagnostics"
if [[ "$include_json" == true ]]; then
reporter/tools/export-json-all.sh reports/reports --output-dir "$output_root/reports/pdfs"
reporter/tools/export-json-all.sh reports/reports --output-dir "$stage/reports/pdfs"
while IFS= read -r -d '' source; do
relative=${source#reports/diagnostics/}
mkdir -p "$output_root/diagnostics/$(dirname "$relative")"
cp "$source" "$output_root/diagnostics/$relative"
mkdir -p "$stage/diagnostics/$(dirname "$relative")"
cp "$source" "$stage/diagnostics/$relative"
done < <(find reports/diagnostics -type f -name '*.json' -print0)
fi
if [[ -d "$output_root" ]]; then
backup=$(mktemp -d "$output_parent/.${output_name}.old.XXXXXXXX")
rmdir -- "$backup"
mv -- "$output_root" "$backup"
fi
mv -- "$stage" "$output_root"
if [[ -n "$backup" ]]; then rm -rf -- "$backup"; backup=; fi
echo "Built publishable reports under $output_root"