-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
43 lines (36 loc) · 965 Bytes
/
Copy pathbuild.sh
File metadata and controls
43 lines (36 loc) · 965 Bytes
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
OS_LIST=(darwin windows)
ARCH_LIST=(amd64)
buildTarget() {
dist_dir=$1
name=$2
os=$3
arch=$4
flags=$5
# grep line 'const Version = ""'
version=$(grep -E "const\b\s*\bVersion\s*=" "$main_dir/main.go" | grep -E -o "(\d+)((\.{1}\d+)*)(\.{0})")
folder=$name-$version-$os-$arch
folderPath=$dist_dir/$folder
echo "---------------------------------------------"
filename=$name
if [ "$os" = "windows" ]; then
filename="$name.exe"
fi
build_cmd="go build -o $folderPath/$filename $flags $main_dir"
echo "$build_cmd"
env GOOS="$os" GOARCH="$arch" sh -c "$build_cmd"
tar -zcf "$folderPath.tar.gz" -C "$dist_dir" "$folder"
}
#dist_dir=dist
#name=$(basename $PWD)
#flags="-ldflags=\"-X 'main.CMD=$name'\""
#main_dir="./cmd/$name"
#main_dir="."
dist_dir=$1
name=$2
flags=$3
main_dir=$4
for os in "${OS_LIST[@]}"; do
for arch in "${ARCH_LIST[@]}"; do
buildTarget "$dist_dir" "$name" "$os" "$arch" "$flags" "$main_dir"
done
done