-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.go
More file actions
75 lines (62 loc) · 1.87 KB
/
build.go
File metadata and controls
75 lines (62 loc) · 1.87 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
// build/build.go
//go:build ignore
// +build ignore
// run from root with `go run build/build.go`
package main
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
)
const (
// ANSI color codes for styling terminal output
colorReset = "\033[0m"
colorRed = "\033[31m"
colorGreen = "\033[32m"
colorYellow = "\033[33m"
colorBlue = "\033[34m"
colorCyan = "\033[36m"
)
func main() {
fmt.Printf("%s=== Starting Build Pipeline ===%s\n", colorCyan, colorReset)
// Platforms to build for
platforms := []struct {
os string
arch string
}{
{"windows", "amd64"},
{"linux", "amd64"},
}
// Build for each platform
for _, platform := range platforms {
fmt.Printf("%s\nBuilding for %s/%s...%s\n", colorBlue, platform.os, platform.arch, colorReset)
// Set OS and architecture for cross-compilation
os.Setenv("GOOS", platform.os)
os.Setenv("GOARCH", platform.arch)
// Prepare the output file name with the new version, branch, and platform
var outputName = "StationeersBackupManager"
// Append appropriate extension based on platform
if platform.os == "windows" {
outputName += ".exe"
}
if platform.os == "linux" {
outputName += ".x86_64"
}
// Output to /build
outputPath := filepath.Join("./", outputName)
// Run the go build command targeting mian.go at root
cmd := exec.Command("go", "build", "-ldflags=-s -w", "-gcflags=-l=4", "-o", outputPath, "main.go")
// Capture any output or errors
cmdOutput, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("%s✗ Build failed for %s/%s:%s %s\nOutput: %s\n",
colorRed, platform.os, platform.arch, colorReset, err, string(cmdOutput))
log.Fatalf("Build process terminated")
}
fmt.Printf("%s✓ Build successful!%s Created: %s%s%s\n",
colorGreen, colorReset, colorYellow, outputPath, colorReset)
}
fmt.Printf("%s\n=== Build Pipeline Completed ===%s\n", colorCyan, colorReset)
}