-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.sh
executable file
·108 lines (95 loc) · 2.7 KB
/
manage.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
set -e
cmd="$1"
app="tukui-mirror"
if test ! "$cmd"; then
echo "command required."
echo
echo "available commands:"
# alphabetical order
echo " build build project"
echo " build.all build project, ignore cache"
echo " build.release build project for distribution"
echo " clean deletes all generated files"
echo " test run project tests"
echo " update-deps update project dependencies"
exit 1
fi
shift
rest=$*
if test "$cmd" = "build"; then
./manage.sh clean
# CGO_ENABLED=0 skips CGO and linking against glibc to build static binaries.
# -v 'verbose'
CGO_ENABLED=0 go build \
-v
echo "wrote $app"
exit 0
elif test "$cmd" = "build.all"; then
# CGO_ENABLED=0 skips CGO and linking against glibc to build static binaries.
# -a 'build all'
# -v 'verbose'
./manage.sh clean
CGO_ENABLED=0 go build \
-a \
-v
exit 0
elif test "$cmd" = "build.release"; then
# GOOS is 'Go OS' and is being explicit in which OS to build for.
# CGO_ENABLED=0 skips CGO and linking against glibc to build static binaries.
# ld -s is 'disable symbol table'
# ld -w is 'disable DWARF generation'
# -trimpath removes leading paths to source files
# -v 'verbose'
# -o 'output'
set -u
version="$1" # 1.0.0
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build \
-ldflags "-s -w -X main.APP_VERSION=$version" \
-trimpath \
-v \
-o linux-amd64
upx linux-amd64
sha256sum linux-amd64 > linux-amd64.sha256
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build \
-ldflags "-s -w -X main.APP_VERSION=$version" \
-trimpath \
-v \
-o linux-arm64
upx linux-arm64
sha256sum linux-arm64 > linux-arm64.sha256
echo ---
go version
echo ---
upx --version
echo ---
du -sh linux-a*
echo ---
echo "done"
exit 0
elif test "$cmd" = "clean"; then
# -f 'force' don't fail if file doesn't exist.
# -v 'verbose' print the name of the file that was deleted.
tbd=(
"main" "$app" # generated by 'build'
"linux-amd64" "linux-amd64.sha256 linux-arm64" "linux-arm64.sha256" # generated by 'release'
)
rm -fv ${tbd[@]}
exit 0
elif test "$cmd" = "deps.update"; then
# -u 'update modules [...] to use newer minor or patch releases when available'
go get -u
go mod tidy
./manage.sh build
exit 0
elif test "$cmd" = "test"; then
if [ -z "$GITHUB_TOKEN" ]; then
echo "failed. command 'test' requires GITHUB_TOKEN to be set."
exit 1
fi
go test
exit 0
# ...
fi
echo "unknown command: $cmd"
exit 1