-
Notifications
You must be signed in to change notification settings - Fork 3
71 lines (59 loc) · 1.98 KB
/
release.yml
File metadata and controls
71 lines (59 loc) · 1.98 KB
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
name: Release
on:
push:
tags: ["v*.*.*"]
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25"
- name: Install UPX
run: |
sudo apt-get update
sudo apt-get -y install upx-ucl
upx --version
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Compress binaries with UPX
run: |
echo "开始压缩二进制文件..."
# 查找所有二进制文件(不是归档文件)
find dist/ -type f -executable -not -name "*.tar.gz" -not -name "*.zip" -not -name "*.txt" | while read -r file; do
echo "处理文件: $file"
# 获取文件信息
file_info=$(file "$file")
file_size_before=$(stat -c%s "$file")
# 检查是否为可执行文件
if echo "$file_info" | grep -q "executable"; then
# 尝试压缩
if upx --lzma --best "$file" 2>/dev/null; then
file_size_after=$(stat -c%s "$file")
compression_ratio=$(echo "scale=1; ($file_size_before - $file_size_after) * 100 / $file_size_before" | bc)
echo "✅ 成功压缩 $file (压缩率: ${compression_ratio}%)"
else
echo "⚠️ 跳过 $file (UPX 不支持或压缩失败)"
fi
else
echo "⚠️ 跳过 $file (非可执行文件)"
fi
done
echo "UPX 压缩完成!"
- name: List final artifacts
run: |
echo "最终构建产物:"
find dist/ -type f -name "*" | sort