forked from q191201771/lal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_release.sh
executable file
·83 lines (67 loc) · 2.46 KB
/
gen_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
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
#!/usr/bin/env bash
# linux, windows, macos, macos_arm, arm32, arm64
#
# name GOOS GOARCH
# linux -> linux (amd64)
# windows -> windows (amd64)
# macos -> darwin (amd64)
# macos_arm64 -> darwin arm64
# arm32 -> (linux) arm
# arm64 -> (linux) arm64
NAMES=("linux" "windows" "macos" "macos_arm64" "arm32" "arm64")
MAPPING_GOOS=("linux" "windows" "darwin" "darwin" "linux" "linux")
MAPPING_GOARCH=( "amd64" "amd64" "amd64" "arm64" "arm" "arm64")
MAPPING_EXE=("lalserver" "lalserver.exe" "lalserver" "lalserver" "lalserver" "lalserver")
#set -x
ROOT_DIR=`pwd`
OUT_DIR=release
v=`git tag --sort=version:refname | tail -n 1`
prefix=lal_${v}_
rm -rf ${ROOT_DIR}/${OUT_DIR}
# 创建目录
for name in ${NAMES[@]};
do
mkdir -p ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/bin
mkdir -p ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/conf
done
# README.txt
for name in ${NAMES[@]};
do
echo ${v} >> ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/README.txt
echo 'github: https://github.com/q191201771/lal ' >> ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/README.txt
echo 'doc: https://pengrl.com/lal ' >> ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/README.txt
done
# conf/
for name in ${NAMES[@]};
do
cp conf/lalserver.conf.json conf/cert.pem conf/key.pem ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/conf
done
# 编译不同架构和操作系统
GitTag=`git tag --sort=version:refname | tail -n 1`
GitCommitLog=`git log --pretty=oneline -n 1`
# 将 log 原始字符串中的单引号替换成双引号
GitCommitLog=${GitCommitLog//\'/\"}
GitStatus=`git status -s`
BuildTime=`date +'%Y.%m.%d.%H%M%S'`
BuildGoVersion=`go version`
LDFlags=" \
-X 'github.com/q191201771/naza/pkg/bininfo.GitTag=${GitTag}' \
-X 'github.com/q191201771/naza/pkg/bininfo.GitCommitLog=${GitCommitLog}' \
-X 'github.com/q191201771/naza/pkg/bininfo.GitStatus=${GitStatus}' \
-X 'github.com/q191201771/naza/pkg/bininfo.BuildTime=${BuildTime}' \
-X 'github.com/q191201771/naza/pkg/bininfo.BuildGoVersion=${BuildGoVersion}' \
"
export CGO_ENABLED=0
for i in "${!NAMES[@]}";
do
printf "build %s(%s %s)...\n" "${NAMES[$i]}" "${MAPPING_GOOS[$i]}" "${MAPPING_GOARCH[$i]}"
export GOOS=${MAPPING_GOOS[$i]}
export GOARCH=${MAPPING_GOARCH[$i]}
cd ${ROOT_DIR}/app/lalserver && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/${OUT_DIR}/${prefix}${NAMES[$i]}/bin/${MAPPING_EXE[$i]}
done
# 打zip包
cd ${ROOT_DIR}/${OUT_DIR}
for name in ${NAMES[@]};
do
zip -r ${prefix}${name}.zip ${prefix}${name}
done