-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·61 lines (51 loc) · 1.78 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·61 lines (51 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
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WEB_DIR="$ROOT_DIR/web"
EMBED_DIR="$ROOT_DIR/internal/webdist/dist"
OUTPUT="${1:-${OUTPUT:-$ROOT_DIR/dist/nekode}}"
DAEMON_OUTPUT="${DAEMON_OUTPUT:-$(dirname "$OUTPUT")/nekode-daemon}"
VERSION="${VERSION:-dev}"
COMMIT="${COMMIT:-$(git -C "$ROOT_DIR" rev-parse --short HEAD 2>/dev/null || printf unknown)}"
BUILD_TIME="${BUILD_TIME:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}"
CGO_ENABLED="${CGO_ENABLED:-0}"
if ! command -v go >/dev/null 2>&1; then
echo "go is required to build the Nekode binary" >&2
exit 1
fi
if ! command -v npm >/dev/null 2>&1; then
echo "npm is required to build the Web console" >&2
exit 1
fi
GOOS="${GOOS:-$(go env GOOS)}"
GOARCH="${GOARCH:-$(go env GOARCH)}"
echo "Building Nekode Web console"
cd "$WEB_DIR"
if [ "${SKIP_NPM_INSTALL:-0}" != "1" ]; then
npm ci
fi
npm run build
mkdir -p "$EMBED_DIR"
find "$EMBED_DIR" -mindepth 1 -maxdepth 1 ! -name .gitkeep -exec rm -rf {} +
cp -R "$WEB_DIR/dist/." "$EMBED_DIR/"
echo "Building Nekode binaries"
cd "$ROOT_DIR"
mkdir -p "$(dirname "$OUTPUT")"
mkdir -p "$(dirname "$DAEMON_OUTPUT")"
ldflags="-s -w"
ldflags="$ldflags -X github.com/ca-x/nekode/internal/version.Version=$VERSION"
ldflags="$ldflags -X github.com/ca-x/nekode/internal/version.Commit=$COMMIT"
ldflags="$ldflags -X github.com/ca-x/nekode/internal/version.BuildTime=$BUILD_TIME"
CGO_ENABLED="$CGO_ENABLED" GOOS="$GOOS" GOARCH="$GOARCH" go build \
-trimpath \
-ldflags "$ldflags" \
-o "$OUTPUT" ./cmd/nekode
CGO_ENABLED="$CGO_ENABLED" GOOS="$GOOS" GOARCH="$GOARCH" go build \
-trimpath \
-ldflags "$ldflags" \
-o "$DAEMON_OUTPUT" ./cmd/nekode-daemon
echo "Built $OUTPUT"
echo "Built $DAEMON_OUTPUT"
echo "Version: $VERSION"
echo "Commit: $COMMIT"
echo "Build time: $BUILD_TIME"