-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·88 lines (69 loc) · 2.22 KB
/
build.sh
File metadata and controls
executable file
·88 lines (69 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# Remote Code Build Script
# 构建不同平台的可执行文件
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKEND_DIR="$SCRIPT_DIR/backend"
BUILD_DIR="$SCRIPT_DIR/build"
# 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}"
echo "🔨 Remote Code Build Script"
echo "================================${NC}"
# 创建构建目录
mkdir -p "$BUILD_DIR"
# 进入后端目录
cd "$BACKEND_DIR"
# 版本信息
VERSION=${VERSION:-"1.0.0"}
BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
echo -e "${YELLOW}Building version: $VERSION${NC}"
echo -e "${YELLOW}Git commit: $GIT_COMMIT${NC}"
echo ""
# 构建函数
build_binary() {
local GOOS=$1
local GOARCH=$2
local OUTPUT_NAME=$3
echo -e "${BLUE}Building for $GOOS/$GOARCH...${NC}"
GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build \
-ldflags "-s -w -X main.Version=$VERSION -X main.GitCommit=$GIT_COMMIT" \
-o "$BUILD_DIR/remote-code-$OUTPUT_NAME" \
./cmd/server 2>&1
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Built: remote-code-$OUTPUT_NAME${NC}"
else
echo -e "${RED}❌ Failed to build for $GOOS/$GOARCH${NC}"
return 1
fi
}
# 构建所有平台
echo -e "${BLUE}Building for current platform...${NC}"
build_binary "$(go env GOOS)" "$(go env GOARCH)" "$(go env GOOS)-$(go env GOARCH)"
echo ""
echo -e "${BLUE}Building for macOS Intel...${NC}"
build_binary "darwin" "amd64" "macos-intel"
echo ""
echo -e "${BLUE}Building for macOS Apple Silicon...${NC}"
build_binary "darwin" "arm64" "macos-apple"
echo ""
echo -e "${BLUE}Building for Linux x64...${NC}"
build_binary "linux" "amd64" "linux-x64"
echo ""
echo -e "${BLUE}Building for Linux ARM64...${NC}"
build_binary "linux" "arm64" "linux-arm64"
echo ""
echo -e "${BLUE}Building for Windows x64...${NC}"
build_binary "windows" "amd64" "windows-x64.exe"
echo ""
echo -e "${GREEN}================================${NC}"
echo -e "${GREEN}✨ Build completed!${NC}"
echo -e "${GREEN}================================${NC}"
echo ""
echo -e "Output directory: ${YELLOW}$BUILD_DIR${NC}"
echo ""
ls -lh "$BUILD_DIR"