80 lines
2.5 KiB
Bash
Executable File
80 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
|
usage() {
|
|
echo "Usage: $0 OUTPUT_ROOT [--include-json] [--replace]" >&2
|
|
exit 2
|
|
}
|
|
|
|
output_root=${1:-}
|
|
[[ -n "$output_root" ]] || usage
|
|
shift
|
|
|
|
include_json=false replace=false
|
|
while (($#)); do
|
|
case $1 in
|
|
--include-json) include_json=true ;;
|
|
--replace) replace=true ;;
|
|
*) usage ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
[[ ! -L "$output_root" ]] || {
|
|
echo "$output_root: symlink output root is not supported" >&2
|
|
exit 1
|
|
}
|
|
output_root=$(python3 -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' "$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/build.sh render-all report reports/reports --output-dir "$stage/reports/pdfs"
|
|
reporter/build.sh render-all diagnostic reports/diagnostics --output-dir "$stage/diagnostics"
|
|
|
|
if [[ "$include_json" == true ]]; then
|
|
reporter/build.sh export-json-all reports/reports --output-dir "$stage/reports/pdfs"
|
|
while IFS= read -r -d '' source; do
|
|
relative=${source#reports/diagnostics/}
|
|
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"
|