-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild-release.sh
More file actions
executable file
·121 lines (100 loc) · 3.06 KB
/
build-release.sh
File metadata and controls
executable file
·121 lines (100 loc) · 3.06 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
#!/bin/bash
#
# This script automates the building, packaging, and uploading of sshman binaries to a GitHub release.
#
# Usage:
# ./build-release.sh <tag_name>
#
# Example:
# ./build-release.sh v1.3.0
#
# Prerequisites:
# - Go (1.21+)
# - Node.js (18+) and npm
# - GitHub CLI (gh) installed and authenticated
# - The script must be run from the root of the repository
set -e
# --- Configuration ---
# Target platforms (GOOS GOARCH)
PLATFORMS=(
"linux amd64"
"linux arm64"
"windows amd64"
"darwin amd64"
"darwin arm64"
"freebsd amd64"
"openbsd amd64"
)
# --- Pre-flight Checks ---
if [ -z "$1" ]; then
echo "Error: No release tag specified."
echo "Usage: $0 <tag_name>"
exit 1
fi
TAG_NAME=$1
RELEASE_DIR="release-artifacts"
# Check for required commands
for cmd in go npm gh; do
if ! command -v $cmd &> /dev/null; then
echo "Error: $cmd is not installed. Please install it and try again."
exit 1
fi
done
# --- Build Steps ---
echo "--- Preparing for release: $TAG_NAME ---"
# 1. Build the frontend
echo "Building frontend assets..."
(cd frontend && npm install && npm run build)
# 2. Create a directory for release artifacts
echo "Creating release directory: $RELEASE_DIR"
rm -rf $RELEASE_DIR
mkdir -p $RELEASE_DIR
# 3. Build and package binaries for each platform
for platform in "${PLATFORMS[@]}"; do
read -r GOOS GOARCH <<<"$platform"
echo "Building for $GOOS/$GOARCH..."
# Determine binary name and extension
BINARY_NAME="sshman"
if [ "$GOOS" = "windows" ]; then
BINARY_NAME="sshman.exe"
fi
# Build the binary
env GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -ldflags="-s -w" -o "$RELEASE_DIR/$BINARY_NAME" .
# Package the binary
ASSET_NAME="sshman-${GOOS}-${GOARCH}"
if [ "$GOOS" = "windows" ]; then
ASSET_PATH="$RELEASE_DIR/${ASSET_NAME}.zip"
(cd $RELEASE_DIR && zip "${ASSET_NAME}.zip" "$BINARY_NAME")
else
ASSET_PATH="$RELEASE_DIR/${ASSET_NAME}.tar.gz"
(cd $RELEASE_DIR && tar -czvf "${ASSET_NAME}.tar.gz" "$BINARY_NAME")
fi
echo " -> Packaged as $ASSET_PATH"
# Clean up the binary after packaging
rm "$RELEASE_DIR/$BINARY_NAME"
done
# --- Upload ---
echo "--- Uploading artifacts to release $TAG_NAME ---"
MAX_RETRIES=50
RETRY_DELAY=2
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
# Use --clobber to overwrite existing files if the script is re-run
if gh release upload --clobber "$TAG_NAME" "$RELEASE_DIR"/*; then
echo "Upload successful."
break
else
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "Error: Upload failed after $MAX_RETRIES attempts."
exit 1
fi
echo "Upload failed. Retrying in $RETRY_DELAY seconds... (Attempt $RETRY_COUNT of $MAX_RETRIES)"
sleep $RETRY_DELAY
fi
done
# --- Cleanup ---
echo "Cleaning up release directory..."
rm -rf $RELEASE_DIR
echo "--- Done! ---"
echo "All binaries have been built, packaged, and uploaded to release $TAG_NAME."