39 lines
1.1 KiB
Bash
Executable File
39 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# ----- Resolve and enter the repository root -----
|
|
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
|
cd "$REPO_ROOT"
|
|
|
|
# ----- Set the output file, with a default project path -----
|
|
OUTPUT_FILE="${1:-./data/gen/build_info.typ}"
|
|
|
|
# ----- Retrieve the current Git commit identifiers -----
|
|
build_commit="$(git rev-parse HEAD)"
|
|
build_commit_short="$(git rev-parse --short HEAD)"
|
|
|
|
# ----- Retrieve the latest reachable Git tag -----
|
|
build_version="$(git describe --tags --abbrev=0 2>/dev/null || true)"
|
|
build_version="${build_version:-}"
|
|
|
|
# ----- Check whether the main Typst document builds successfully -----
|
|
if typst query main.typ '<a>' >/dev/null 2>&1; then
|
|
build_status="true"
|
|
else
|
|
build_status="false"
|
|
fi
|
|
|
|
# ----- Generate the Typst build metadata file -----
|
|
cat > "$OUTPUT_FILE" <<EOF
|
|
// ----- Autogenerated build metadata -----
|
|
#let build_info = (
|
|
build_commit : "$build_commit",
|
|
build_commit_short : "$build_commit_short",
|
|
build_version : "$build_version",
|
|
build_status : $build_status,
|
|
)
|
|
EOF
|
|
|
|
# ----- Report the generated file -----
|
|
echo "Generated $OUTPUT_FILE"
|