-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.sh
executable file
·78 lines (65 loc) · 2.71 KB
/
build.sh
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
#!/usr/bin/env bash
set -e
BUILD_TIME=$(date -Iseconds)
GO_VERSION=$(go version)
GIT_COMMIT=$(git rev-list -1 HEAD)
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
TARGET_DIR=${SND_RELEASE_DIR:='build/release/'}
APP_NAME=${SND_APP_NAME:='Sales & Dungeons'}
OSX_APP_BUNDLE_ENABLED=${SND_OSX_APP_BUNDLE_ENABLED:='false'}
OSX_APP_BUNDLE_DIR=${TARGET_DIR}
# if OSX_APP_BUNDLE_ENABLED we need to append /bundle to SND_RELEASE_DIR and APP_NAME needs to be snd
if [ "${OSX_APP_BUNDLE_ENABLED}" = "true" ]; then
TARGET_DIR="${TARGET_DIR}bundle/"
APP_NAME="snd"
fi
echo "Build Time : ${BUILD_TIME}"
echo "Branch : ${GIT_BRANCH}"
echo "Commit : ${GIT_COMMIT}"
echo "Go Version : ${GO_VERSION}"
echo "Build OS : ${GOOS:=$(go env GOOS)}"
echo "Build Arch : ${GOARCH:=$(go env GOARCH)}"
echo "Build Tags : ${SND_TAGS}"
echo "CGO Enabled : ${CGO_ENABLED}"
echo "OSX Bundle : ${OSX_APP_BUNDLE_ENABLED}"
echo "Clearing old data..."
rm -r ${TARGET_DIR}frontend || true
rm -r ${TARGET_DIR}data || true
rm ${TARGET_DIR}/* || true
mkdir -p ${TARGET_DIR}/frontend/dist ${TARGET_DIR}/data
echo "Building App..."
case "${GOOS}" in
"windows") EXT=".exe" ;;
*) EXT="" ;;
esac
LD_FLAGS="-X github.com/BigJk/snd.GitCommitHash=${GIT_COMMIT} -X github.com/BigJk/snd.GitBranch=${GIT_BRANCH} -X github.com/BigJk/snd.BuildTime=${BUILD_TIME}"
cd cmd/app
go build -ldflags "${LD_FLAGS}" -o app -tags "${SND_TAGS}"
cd ../..
mv cmd/app/app "${TARGET_DIR}/${APP_NAME}${EXT}"
echo "Copying frontend..."
cp -r frontend/dist ${TARGET_DIR}/frontend
echo "Copying resources..."
cp data/icon.png ${TARGET_DIR}/data/icon.png
cp data/icon.icns ${TARGET_DIR}/data/icon.icns
echo "Building version.txt..."
echo "Commit: ${GIT_COMMIT}" > ${TARGET_DIR}/version.txt
echo "Branch: ${GIT_BRANCH}" >> ${TARGET_DIR}/version.txt
echo "Build Time: ${BUILD_TIME}" >> ${TARGET_DIR}/version.txt
echo "Setting permissions..."
chmod +x "${TARGET_DIR}/${APP_NAME}${EXT}"
# if OSX_APP_BUNDLE_ENABLED we need to create a .app bundle
if [ "${OSX_APP_BUNDLE_ENABLED}" = "true" ]; then
echo "Building OSX App Bundle..."
wget -O ${OSX_APP_BUNDLE_DIR}/macapp.go https://gist.githubusercontent.com/mholt/11008646c95d787c30806d3f24b2c844/raw/53d1d4baeeb7ed8ee7dc89ebfd900e444a298323/macapp.go
go run ${OSX_APP_BUNDLE_DIR}/macapp.go -assets "${TARGET_DIR}" -bin "snd" -icon "${TARGET_DIR}data/icon.png" -identifier app.sales-and-dungeons -name "Sales & Dungeons" -o ${OSX_APP_BUNDLE_DIR}
chmod +x "${OSX_APP_BUNDLE_DIR}/Sales & Dungeons.app/Contents/MacOS/snd"
# check if "Sales & Dungeons.app" exists
if [ -d "${OSX_APP_BUNDLE_DIR}Sales & Dungeons.app" ]; then
rm -r "${TARGET_DIR}"
rm "${OSX_APP_BUNDLE_DIR}/macapp.go"
else
echo "Error: Failed to create app bundle"
exit 1
fi
fi