-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild-release.ps1
More file actions
100 lines (75 loc) · 6.95 KB
/
build-release.ps1
File metadata and controls
100 lines (75 loc) · 6.95 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
# Build script for marchat v1.0.0
# This script builds all platform targets and creates release zips
$ErrorActionPreference = "Stop"
$VERSION = "v1.0.0"
$BUILD_DIR = "build"
$RELEASE_DIR = "release"
Write-Host "Building marchat $VERSION..." -ForegroundColor Green
# Create build and release directories
New-Item -ItemType Directory -Force -Path $BUILD_DIR | Out-Null
New-Item -ItemType Directory -Force -Path $RELEASE_DIR | Out-Null
# Clean previous builds
if (Test-Path $BUILD_DIR) { Remove-Item "$BUILD_DIR\*" -Recurse -Force }
if (Test-Path $RELEASE_DIR) { Remove-Item "$RELEASE_DIR\*" -Recurse -Force }
# Get current timestamp and git commit
$BUILD_TIME = (Get-Date).ToUniversalTime().ToString('o')
$GIT_COMMIT = git rev-parse --short HEAD 2>$null
if (-not $GIT_COMMIT) { $GIT_COMMIT = "unknown" }
# Disable CGO for static cross-compiled binaries
$env:CGO_ENABLED = "0"
# Build targets with version information
Write-Host "Building for Linux AMD64..." -ForegroundColor Yellow
$env:GOOS = "linux"; $env:GOARCH = "amd64"
go build -ldflags "-X github.com/Cod-e-Codes/marchat/shared.ClientVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.ServerVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.BuildTime='$BUILD_TIME' -X github.com/Cod-e-Codes/marchat/shared.GitCommit=$GIT_COMMIT" -o "$BUILD_DIR/marchat-client-linux-amd64" ./client
go build -ldflags "-X github.com/Cod-e-Codes/marchat/shared.ClientVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.ServerVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.BuildTime='$BUILD_TIME' -X github.com/Cod-e-Codes/marchat/shared.GitCommit=$GIT_COMMIT" -o "$BUILD_DIR/marchat-server-linux-amd64" ./cmd/server
Write-Host "Building for Windows AMD64..." -ForegroundColor Yellow
$env:GOOS = "windows"; $env:GOARCH = "amd64"
go build -ldflags "-X github.com/Cod-e-Codes/marchat/shared.ClientVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.ServerVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.BuildTime='$BUILD_TIME' -X github.com/Cod-e-Codes/marchat/shared.GitCommit=$GIT_COMMIT" -o "$BUILD_DIR/marchat-client-windows-amd64.exe" ./client
go build -ldflags "-X github.com/Cod-e-Codes/marchat/shared.ClientVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.ServerVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.BuildTime='$BUILD_TIME' -X github.com/Cod-e-Codes/marchat/shared.GitCommit=$GIT_COMMIT" -o "$BUILD_DIR/marchat-server-windows-amd64.exe" ./cmd/server
Write-Host "Building for Darwin AMD64..." -ForegroundColor Yellow
$env:GOOS = "darwin"; $env:GOARCH = "amd64"
go build -ldflags "-X github.com/Cod-e-Codes/marchat/shared.ClientVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.ServerVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.BuildTime='$BUILD_TIME' -X github.com/Cod-e-Codes/marchat/shared.GitCommit=$GIT_COMMIT" -o "$BUILD_DIR/marchat-client-darwin-amd64" ./client
go build -ldflags "-X github.com/Cod-e-Codes/marchat/shared.ClientVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.ServerVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.BuildTime='$BUILD_TIME' -X github.com/Cod-e-Codes/marchat/shared.GitCommit=$GIT_COMMIT" -o "$BUILD_DIR/marchat-server-darwin-amd64" ./cmd/server
Write-Host "Building for Darwin ARM64 (Apple Silicon)..." -ForegroundColor Yellow
$env:GOOS = "darwin"; $env:GOARCH = "arm64"
go build -ldflags "-X github.com/Cod-e-Codes/marchat/shared.ClientVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.ServerVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.BuildTime='$BUILD_TIME' -X github.com/Cod-e-Codes/marchat/shared.GitCommit=$GIT_COMMIT" -o "$BUILD_DIR/marchat-client-darwin-arm64" ./client
go build -ldflags "-X github.com/Cod-e-Codes/marchat/shared.ClientVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.ServerVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.BuildTime='$BUILD_TIME' -X github.com/Cod-e-Codes/marchat/shared.GitCommit=$GIT_COMMIT" -o "$BUILD_DIR/marchat-server-darwin-arm64" ./cmd/server
Write-Host "Building for Linux ARM64 (use on Termux arm64; GOOS=linux, not android)..." -ForegroundColor Yellow
$env:GOOS = "linux"; $env:GOARCH = "arm64"
go build -ldflags "-X github.com/Cod-e-Codes/marchat/shared.ClientVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.ServerVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.BuildTime='$BUILD_TIME' -X github.com/Cod-e-Codes/marchat/shared.GitCommit=$GIT_COMMIT" -o "$BUILD_DIR/marchat-client-linux-arm64" ./client
go build -ldflags "-X github.com/Cod-e-Codes/marchat/shared.ClientVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.ServerVersion=$VERSION -X github.com/Cod-e-Codes/marchat/shared.BuildTime='$BUILD_TIME' -X github.com/Cod-e-Codes/marchat/shared.GitCommit=$GIT_COMMIT" -o "$BUILD_DIR/marchat-server-linux-arm64" ./cmd/server
# Create release zips
Write-Host "Creating release zips..." -ForegroundColor Yellow
# Linux AMD64
Compress-Archive -Path "$BUILD_DIR/marchat-client-linux-amd64", "$BUILD_DIR/marchat-server-linux-amd64" -DestinationPath "$RELEASE_DIR/marchat-$VERSION-linux-amd64.zip" -Force
# Windows AMD64
Compress-Archive -Path "$BUILD_DIR/marchat-client-windows-amd64.exe", "$BUILD_DIR/marchat-server-windows-amd64.exe" -DestinationPath "$RELEASE_DIR/marchat-$VERSION-windows-amd64.zip" -Force
# Darwin AMD64
Compress-Archive -Path "$BUILD_DIR/marchat-client-darwin-amd64", "$BUILD_DIR/marchat-server-darwin-amd64" -DestinationPath "$RELEASE_DIR/marchat-$VERSION-darwin-amd64.zip" -Force
# Darwin ARM64 (Apple Silicon)
Compress-Archive -Path "$BUILD_DIR/marchat-client-darwin-arm64", "$BUILD_DIR/marchat-server-darwin-arm64" -DestinationPath "$RELEASE_DIR/marchat-$VERSION-darwin-arm64.zip" -Force
# Linux ARM64 (Termux / aarch64 Linux)
Compress-Archive -Path "$BUILD_DIR/marchat-client-linux-arm64", "$BUILD_DIR/marchat-server-linux-arm64" -DestinationPath "$RELEASE_DIR/marchat-$VERSION-linux-arm64.zip" -Force
Write-Host "Build complete!" -ForegroundColor Green
Write-Host "Release files created in $RELEASE_DIR/:" -ForegroundColor Cyan
Get-ChildItem $RELEASE_DIR | Format-Table Name, Length, LastWriteTime
Write-Host ""
Write-Host "Release assets for ${VERSION}:" -ForegroundColor Magenta
Write-Host "- marchat-$VERSION-linux-amd64.zip"
Write-Host "- marchat-$VERSION-linux-arm64.zip"
Write-Host "- marchat-$VERSION-windows-amd64.zip"
Write-Host "- marchat-$VERSION-darwin-amd64.zip"
Write-Host "- marchat-$VERSION-darwin-arm64.zip"
# Build and push Docker image
Write-Host "Building Docker image for marchat..." -ForegroundColor Yellow
docker build -t codecodesxyz/marchat:$VERSION `
--build-arg GIT_COMMIT=$GIT_COMMIT `
--build-arg BUILD_TIME=$BUILD_TIME `
--build-arg VERSION=$VERSION `
.
# Tag as latest
docker tag codecodesxyz/marchat:$VERSION codecodesxyz/marchat:latest
# Push images
docker push codecodesxyz/marchat:$VERSION
docker push codecodesxyz/marchat:latest
Write-Host "Docker image build and push complete!" -ForegroundColor Green