-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·60 lines (50 loc) · 1.3 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
#!/bin/bash
# Expects the directory structure:
# .
# └── projectname
# ├── build.sh
# └── src
# ├── custompackage
# │ └── custompackage.go
# └── main
# └── main.go
#
# This will build a binary called "projectname" at "projectname/bin/projectname".
#
# The final structure will look like:
#
# .
# └── projectname
# ├── bin
# │ └── projectname
# ├── build.sh
# └── src
# ├── custompackage
# │ └── custompackage.go
# └── main
# └── main.go
#
# Save the pwd before we run anything
PRE_PWD=`pwd`
# Determine the build script's actual directory, following symlinks
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
BUILD_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
# Derive the project name from the directory
PROJECT="$(basename $BUILD_DIR)"
# Setup the environment for the build
GOPATH=$BUILD_DIR:$GOPATH
# Build the project
cd $BUILD_DIR
mkdir -p bin
env GOOS=linux GOARCH=amd64 go build ./cmd/main.go
mv main ./goexec
EXIT_STATUS=$?
if [ $EXIT_STATUS == 0 ]; then
echo "Build succeeded"
else
echo "Build failed"
fi
# Change back to where we were
cd $PRE_PWD
exit $EXIT_STATUS