Repository navigation
Expand file tree
/
Copy pathscripts.sh
More file actions
executable file
·160 lines (134 loc) · 3.22 KB
/
Copy pathscripts.sh
File metadata and controls
executable file
·160 lines (134 loc) · 3.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
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
153
154
155
156
157
158
159
160
#!/bin/sh
set -eu
test_backend() {
echo "testing backend"
(cd backend && go test ./...)
}
test_frontend() {
echo "testing frontend"
(
cd frontend
pnpm install --frozen-lockfile --prefer-offline
pnpm run typecheck
pnpm run test
pnpm run check:i18n
)
}
test_all() {
test_backend
test_frontend
}
build_frontend() {
echo "building frontend"
(
cd frontend
pnpm install --frozen-lockfile --prefer-offline
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 Run backend and frontend tests
test-backend Run backend tests
test-frontend Run frontend typecheck, tests, and i18n check
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_all
;;
"test-backend")
test_backend
;;
"test-frontend")
test_frontend
;;
"build-frontend")
build_frontend
;;
"build-backend")
build_backend "${2:-}" "${3:-}" "${4:-}"
;;
"build")
build
;;
"release")
release
;;
*)
usage
exit 1
;;
esac