File tree Expand file tree Collapse file tree 3 files changed +89
-1
lines changed Expand file tree Collapse file tree 3 files changed +89
-1
lines changed Original file line number Diff line number Diff line change 4646 with :
4747 args : tool-gin* application/octet-stream
4848 env :
49- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
49+ GITHUB_TOKEN : ${{ secrets.PERSONAL_TOKEN }}
File renamed without changes.
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # 需要打包的静态文件或目录
4+ static_files=(pyutils static)
5+
6+ # 脚本当前目录绝对路径
7+ project_path=$( cd ` dirname $0 ` ; pwd)
8+ # 脚本当前目录名
9+ project_name=" ${project_path##*/ } "
10+
11+ # 对IFS变量进行替换处理
12+ OLD_IFS=" $IFS "
13+ # 指定分隔符
14+ IFS=" "
15+ # 获得所有受支持平台的列表
16+ os_arch_array=` go tool dist list`
17+ # 还原
18+ IFS=" $OLD_IFS "
19+
20+ for item in ${os_arch_array[@]} ; do
21+ # 替换指定字符串为IFS的默认分隔符空格
22+ array=(${item// \/ / } )
23+ os=${array[0]}
24+ arch=${array[1]}
25+ zip_dir=${project_name} _${os} _${arch}
26+
27+ # 忽略以下平台的编译
28+ if [[ $os == " android" ]] || [[ $os == " darwin" && $arch == * arm* ]]; then
29+ continue
30+ fi
31+
32+ if [ -e $zip_dir ]; then
33+ # 如果压缩目录存在则删除
34+ rm -rf $zip_dir
35+ fi
36+
37+ # 创建要打包的目录,把静态文件复制进去
38+ mkdir $zip_dir
39+ for static_file in ${static_files[@]} ; do
40+ cp -r $static_file $zip_dir
41+ done
42+
43+ # 设置变量
44+ export GOOS=$os GOARCH=$arch
45+
46+ echo " 环境变量设置成功:$GOOS ------$GOARCH "
47+
48+ # 指定编译的二进制文件名
49+ binary_file=${os} _${arch}
50+ if [ $os == " windows" ]; then
51+ binary_file=$binary_file .exe
52+ fi
53+
54+ # 编译文件到压缩目录
55+ if [ $os == " android" ]; then
56+ # 开启 CGO
57+ # export CGO_ENABLED=1
58+ # go build -ldflags="-w -linkmode=external -extldflags=-pie" -i -o $zip_dir/$binary_file
59+ continue
60+ elif [ $os == " darwin" ]; then
61+ # 开启 CGO
62+ # export CGO_ENABLED=1
63+ go build -ldflags=" -w" -i -o $zip_dir /$binary_file
64+ # elif [ $os == "windows" ]; then
65+ # # 交叉编译不支持 CGO 所以要禁用它
66+ # export CGO_ENABLED=0
67+ # go build -ldflags="-w -H windowsgui" -i -o $zip_dir/$binary_file
68+ else
69+ # 交叉编译不支持 CGO 所以要禁用它
70+ export CGO_ENABLED=0
71+ go build -ldflags=" -w" -i -o $zip_dir /$binary_file
72+ fi
73+
74+ # 压缩
75+ if [ $os == " windows" ]; then
76+ zip -q -r $zip_dir .zip $zip_dir
77+ else
78+ tar -czf $zip_dir .tar.gz $zip_dir
79+ fi
80+
81+ # 删除压缩目录
82+ rm -rf $zip_dir
83+
84+ # 编译完成清理缓存
85+ go clean -cache
86+
87+ done
88+
You can’t perform that action at this time.
0 commit comments