-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·52 lines (43 loc) · 1.24 KB
/
release.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
#!/bin/bash
MODULE=$(grep module go.mod | cut -d\ -f2)
BINBASE=${MODULE##*/}
VERSION=${VERSION:-$GITHUB_REF_NAME}
COMMIT_HASH="$(git rev-parse --short HEAD)"
BUILD_TIMESTAMP=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
BUILDER=$(go version)
[ -d dist ] && rm -rf dist
mkdir dist
# For version in sub module
# "-X '${MODULE}/main.Version=${VERSION}'"
LDFLAGS=(
"-X 'main.Version=${VERSION}'"
"-X 'main.CommitHash=${COMMIT_HASH}'"
"-X 'main.BuildTimestamp=${BUILD_TIMESTAMP}'"
"-X 'main.Builder=${BUILDER}'"
)
echo "[*] go get"
go get .
echo "[*] go builds:"
for DIST in {linux,openbsd,windows,freebsd}/{amd64,arm,arm64}; do
#for DIST in linux/{amd64,386}; do
GOOS=${DIST%/*}
GOARCH=${DIST#*/}
echo "[+] $DIST:"
echo "[-] - build"
SUFFIX=""
[ "$GOOS" = "windows" ] && SUFFIX=".exe"
TARGET=${BINBASE}-${GOOS}-${GOARCH}
env GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="${LDFLAGS[*]}" -o dist/${TARGET}${SUFFIX}
echo "[-] - compress"
if [ "$GOOS" = "windows" ]; then
(cd dist; zip -qm9 ${TARGET}.zip ${TARGET}${SUFFIX})
else
xz dist/${TARGET}
fi
done
echo "[*] sha256sum"
(cd dist; sha256sum *) | tee ${BINBASE}.sha256sum
mv ${BINBASE}.sha256sum dist/
#echo "[*] pack"
#tar -cvf all.tar -C dist/ . && mv all.tar dist
echo "[*] done"