修复后端构建提交号注入

This commit is contained in:
andy
2026-07-21 14:21:09 +07:00
parent ab766cf4e2
commit ef6658aa34
6 changed files with 100 additions and 11 deletions

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
git update-index -q --refresh
if [[ -n "$(git status --porcelain)" ]]; then
echo "ERROR: Git worktree is not clean. Commit or stash changes before packaging a deployment-proof Jar." >&2
git status --short >&2
exit 1
fi
build_commit="$(git rev-parse --short HEAD 2>/dev/null || true)"
if [[ -z "$build_commit" || "$build_commit" == "UNKNOWN" ]]; then
echo "ERROR: Cannot resolve current Git commit for TH_HOTEL_BUILD_COMMIT." >&2
exit 1
fi
echo "Packaging TH Hotel backend with TH_HOTEL_BUILD_COMMIT=$build_commit"
cd "$repo_root/server"
TH_HOTEL_BUILD_COMMIT="$build_commit" ./mvnw clean package "$@"
build_info_file="$repo_root/server/target/classes/META-INF/build-info.properties"
if ! grep -q "^build.commit=$build_commit$" "$build_info_file"; then
echo "ERROR: build-info verification failed. Expected build.commit=$build_commit in $build_info_file." >&2
exit 1
fi
echo "Build proof OK: build.commit=$build_commit"