-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathscripts.sh
More file actions
executable file
·152 lines (125 loc) · 3.17 KB
/
scripts.sh
File metadata and controls
executable file
·152 lines (125 loc) · 3.17 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
set -eu
resolve_version() {
if [ -n "${FUSION_VERSION:-}" ]; then
printf '%s\n' "$FUSION_VERSION"
return
fi
if git describe --tags --abbrev=0 >/dev/null 2>&1; then
git describe --tags --abbrev=0
return
fi
git rev-parse --short HEAD
}
test_backend() {
echo "testing backend"
(cd backend && go test ./...)
}
build_frontend() {
echo "building frontend"
version=$(resolve_version)
echo "Using fusion version string: ${version}"
(
cd frontend
pnpm install --frozen-lockfile --prefer-offline
VITE_FUSION_VERSION="$version" pnpm run build
)
echo "syncing frontend build artifacts for backend embed"
rm -rf backend/internal/web/dist
mkdir -p backend/internal/web/dist
cp -R frontend/dist/. backend/internal/web/dist/
printf '%s\n' "This file keeps the embedded dist directory in version control." > backend/internal/web/dist/.keep
}
build_backend() {
target_os=${1:-$(go env GOOS)}
target_arch=${2:-$(go env GOARCH)}
root=$(pwd)
output_path=${3:-"${root}/build/fusion"}
case "$output_path" in
/*) ;;
*) output_path="${root}/${output_path#./}" ;;
esac
if [ ! -f backend/internal/web/dist/index.html ]; then
echo "frontend build artifacts not found for embed"
echo "run ./scripts.sh build-frontend before building backend"
exit 1
fi
echo "building backend for OS: ${target_os}, Arch: ${target_arch}, Output: ${output_path}"
mkdir -p "$(dirname "$output_path")"
(
cd backend
CGO_ENABLED=0 GOOS=${target_os} GOARCH=${target_arch} go build \
-trimpath \
-ldflags '-extldflags "-static"' \
-o "$output_path" \
./cmd/fusion
)
}
release() {
echo "building release artifacts"
rm -rf ./dist
mkdir -p ./dist
build_frontend
platforms="linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64"
for platform in $platforms; do
os=${platform%/*}
arch=${platform#*/}
echo "--- building ${os}/${arch} ---"
bin_name="fusion"
if [ "$os" = "windows" ]; then
bin_name="fusion.exe"
fi
build_backend "$os" "$arch" "./dist/${bin_name}"
if [ "$os" = "linux" ]; then
cp "./dist/${bin_name}" "./dist/fusion-linux-${arch}"
fi
archive="fusion_${os}_${arch}.zip"
zip -j "./dist/${archive}" "./dist/${bin_name}" LICENSE* README* || \
zip -j "./dist/${archive}" "./dist/${bin_name}"
rm "./dist/${bin_name}"
done
(
cd ./dist
sha256sum ./*.zip ./fusion-linux-* > checksums.txt
)
echo "release artifacts:"
ls -lh ./dist/
}
build() {
test_backend
build_frontend
build_backend
}
usage() {
cat <<'EOF'
Usage: ./scripts.sh <command>
Commands:
test-backend Run backend tests
build-frontend Build frontend bundle
build-backend [os] [arch] [output]
Build backend binary
build Run backend tests and build all
release Build release archives and checksums
EOF
}
case "${1:-}" in
"test" | "test-backend")
test_backend
;;
"build-frontend")
build_frontend
;;
"build-backend")
build_backend "${2:-}" "${3:-}" "${4:-}"
;;
"build")
build
;;
"release")
release
;;
*)
usage
exit 1
;;
esac