-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.sh
More file actions
71 lines (55 loc) · 1.78 KB
/
build.sh
File metadata and controls
71 lines (55 loc) · 1.78 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
#!/bin/bash
set -euo pipefail
# Get the directory of the script
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Change to the script directory
cd "$SCRIPT_DIR" || exit
# Binary name - must match SafeDashId() from extension.yaml id (microsoft.azd.waza -> microsoft-azd-waza)
BINARY_NAME="microsoft-azd-waza"
# Define output directory
OUTPUT_DIR="${OUTPUT_DIR:-$SCRIPT_DIR/bin}"
# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
# Build web dashboard
echo "Building web dashboard..."
(cd "$SCRIPT_DIR/web" && npm ci --silent && npm run build)
# Get Git commit hash and build date
COMMIT=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
VERSION="${VERSION:-0.1.0}"
# List of OS and architecture combinations
if [ -n "${PLATFORM:-}" ]; then
PLATFORMS=("$PLATFORM")
else
PLATFORMS=(
"windows/amd64"
"windows/arm64"
"darwin/amd64"
"darwin/arm64"
"linux/amd64"
"linux/arm64"
)
fi
# Loop through platforms and build
for PLATFORM in "${PLATFORMS[@]}"; do
OS=$(echo "$PLATFORM" | cut -d'/' -f1)
ARCH=$(echo "$PLATFORM" | cut -d'/' -f2)
OUTPUT_NAME="$OUTPUT_DIR/$BINARY_NAME-$OS-$ARCH"
if [ "$OS" = "windows" ]; then
OUTPUT_NAME+='.exe'
fi
echo "Building for $OS/$ARCH..."
# Delete the output file if it already exists
[ -f "$OUTPUT_NAME" ] && rm -f "$OUTPUT_NAME"
# Set environment variables for Go build
GOOS=$OS GOARCH=$ARCH go build \
-ldflags="-X 'main.version=$VERSION'" \
-o "$OUTPUT_NAME" \
./cmd/waza
if [ $? -ne 0 ]; then
echo "An error occurred while building for $OS/$ARCH"
exit 1
fi
done
echo "Build completed successfully!"
echo "Binaries are located in the $OUTPUT_DIR directory."