Files
leonpan/build.sh

54 lines
1.8 KiB
Bash
Raw Normal View History

2025-10-21 20:27:45 +08:00
#!/bin/bash
set -e
# 1. 记录起始时间(用 %s 取整数秒,避免小数运算依赖 bc
start_seconds=$(date +%s)
start_datetime=$(date +"%Y-%m-%d %H:%M:%S")
echo "========================================"
echo "Build started at: $start_datetime"
echo "========================================"
# 2. 构建前端(统计耗时)
echo -e "\n[1/2] Starting frontend build..."
frontend_start=$(date +%s) # 前端开始时间(整数秒)
chmod +x ./.build/build-assets.sh
./.build/build-assets.sh
# 计算前端耗时(整数秒,直接用 bash 内置减法,无需 bc
frontend_end=$(date +%s)
frontend_duration=$((frontend_end - frontend_start))
echo "[1/2] Frontend build completed! (Time: ${frontend_duration}s)"
# 3. 构建后端(统计耗时)
echo -e "\n[2/2] Starting backend build..."
backend_start=$(date +%s) # 后端开始时间(整数秒)
# 获取 Git 版本和 Commit
export COMMIT_SHA=$(git rev-parse --short HEAD)
export VERSION=$(git describe --tags)
echo "Backend version: $VERSION, Commit: $COMMIT_SHA"
# 编译 Go 后端
go build -a -o cloudreve \
-ldflags "-s -w -X 'github.com/cloudreve/Cloudreve/v4/application/constants.BackendVersion=$VERSION' -X 'github.com/cloudreve/Cloudreve/v4/application/constants.LastCommit=$COMMIT_SHA'"
# 计算后端耗时
backend_end=$(date +%s)
backend_duration=$((backend_end - backend_start))
echo "[2/2] Backend build completed! (Time: ${backend_duration}s)"
# 4. 总耗时统计(整数秒,直观易懂)
end_seconds=$(date +%s)
total_duration=$((end_seconds - start_seconds))
end_datetime=$(date +"%Y-%m-%d %H:%M:%S")
echo -e "\n========================================"
echo "Build successfully completed!"
echo "Total duration: ${total_duration}s"
echo "Started at: $start_datetime"
echo "Ended at: $end_datetime"
echo "========================================"