|
|
@@ -1,16 +1,46 @@
|
|
1
|
1
|
#!/bin/sh
|
|
2
|
2
|
|
|
3
|
|
-rm release -rf
|
|
|
3
|
+set -e
|
|
|
4
|
+# Automatically get the current environment's GOARCH; if not defined, use the detected system architecture
|
|
|
5
|
+GOARCH=${GOARCH:-$(go env GOARCH)}
|
|
|
6
|
+DOCS="true"
|
|
|
7
|
+# Safely remove the old release directory
|
|
|
8
|
+rm -rf release
|
|
|
9
|
+
|
|
|
10
|
+# Set Go environment variables
|
|
4
|
11
|
go env -w GO111MODULE=on
|
|
5
|
12
|
go env -w GOPROXY=https://goproxy.cn,direct
|
|
6
|
13
|
go env -w CGO_ENABLED=1
|
|
7
|
14
|
go env -w GOOS=linux
|
|
8
|
|
-go env -w GOARCH=amd64
|
|
9
|
|
-swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin
|
|
10
|
|
-swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
|
|
|
15
|
+go env -w GOARCH=${GOARCH}
|
|
|
16
|
+
|
|
|
17
|
+
|
|
|
18
|
+# Generate Swagger documentation if DOCS is not empty
|
|
|
19
|
+if [ -n "${DOCS}" ]; then
|
|
|
20
|
+ # Check if swag is installed
|
|
|
21
|
+ if ! command -v swag &> /dev/null; then
|
|
|
22
|
+ echo "swag command not found. Please install it using:"
|
|
|
23
|
+ echo "go install github.com/swaggo/swag/cmd/swag@latest"
|
|
|
24
|
+ echo "Skipping Swagger documentation generation due to missing swag tool."
|
|
|
25
|
+ else
|
|
|
26
|
+ echo "Generating Swagger documentation..."
|
|
|
27
|
+ swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin
|
|
|
28
|
+ swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
|
|
|
29
|
+ fi
|
|
|
30
|
+else
|
|
|
31
|
+ echo "Skipping Swagger documentation generation due to DOCS is empty."
|
|
|
32
|
+fi
|
|
|
33
|
+
|
|
|
34
|
+# Compile the Go code and output it to the release directory
|
|
11
|
35
|
go build -o release/apimain cmd/apimain.go
|
|
|
36
|
+
|
|
|
37
|
+# Copy resource files to the release directory
|
|
12
|
38
|
cp -ar resources release/
|
|
13
|
39
|
cp -ar docs release/
|
|
14
|
40
|
cp -ar conf release/
|
|
|
41
|
+
|
|
|
42
|
+# Create necessary directory structures
|
|
15
|
43
|
mkdir -p release/data
|
|
16
|
44
|
mkdir -p release/runtime
|
|
|
45
|
+
|
|
|
46
|
+echo "Build and setup completed successfully."
|