-
Notifications
You must be signed in to change notification settings - Fork 934
378 lines (346 loc) · 13.5 KB
/
Copy pathbuild.yml
File metadata and controls
378 lines (346 loc) · 13.5 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
name: Build and Release
on:
push:
branches:
- main
- master
tags:
- 'v*'
pull_request:
branches:
- main
- master
workflow_dispatch:
jobs:
build:
strategy:
matrix:
include:
- os: windows-latest
goos: windows
goarch: amd64
exe_ext: .exe
archive_format: zip
archive_ext: .zip
target: desktop
artifact_suffix: ""
enable_gui: true
cgo_enabled: "0"
- os: macos-15-intel
goos: darwin
goarch: amd64
exe_ext: ""
archive_format: zip
archive_ext: .zip
target: desktop
artifact_suffix: ""
enable_gui: true
cgo_enabled: "0"
- os: macos-14
goos: darwin
goarch: arm64
exe_ext: ""
archive_format: zip
archive_ext: .zip
target: desktop
artifact_suffix: ""
enable_gui: true
cgo_enabled: "0"
- os: ubuntu-latest
goos: linux
goarch: amd64
exe_ext: ""
archive_format: tar.gz
archive_ext: .tar.gz
target: desktop
artifact_suffix: ""
enable_gui: true
cgo_enabled: "0"
- os: ubuntu-24.04-arm
goos: linux
goarch: arm64
exe_ext: ""
archive_format: tar.gz
archive_ext: .tar.gz
target: desktop
artifact_suffix: ""
enable_gui: true
cgo_enabled: "0"
- os: ubuntu-latest
goos: linux
goarch: amd64
exe_ext: ""
archive_format: tar.gz
archive_ext: .tar.gz
target: softrouter
artifact_suffix: "-softrouter"
enable_gui: false
cgo_enabled: "0"
- os: ubuntu-latest
goos: linux
goarch: arm64
exe_ext: ""
archive_format: tar.gz
archive_ext: .tar.gz
target: softrouter
artifact_suffix: "-softrouter"
enable_gui: false
cgo_enabled: "0"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: false
- name: Initialize Go module
run: |
go mod init ech-workers || true
go mod tidy
- name: Build Go executable
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: ${{ matrix.cgo_enabled }}
run: |
echo "Building for $GOOS/$GOARCH (target=${{ matrix.target }}, CGO_ENABLED=$CGO_ENABLED)"
go build -trimpath -ldflags="-s -w" -o ech-workers${{ matrix.exe_ext }} ech-workers.go
shell: bash
# 下面这些步骤:只有打 tag 且 enable_gui == true 时才会执行,用来打包 GUI
- name: Set up Python
if: startsWith(github.ref, 'refs/tags/') && matrix.enable_gui == true
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install system dependencies (Linux)
if: startsWith(github.ref, 'refs/tags/') && matrix.goos == 'linux' && matrix.enable_gui == true
run: |
sudo apt-get update
sudo apt-get install -y python3-pyqt5 python3-pyqt5.qtsvg python3-dev
shell: bash
- name: Install PyInstaller, PySocks, and other dependencies
if: startsWith(github.ref, 'refs/tags/') && matrix.enable_gui == true
run: |
python -m pip install --upgrade pip
if [ "${{ matrix.goos }}" == "linux" ]; then
# Linux: 使用系统包中的 PyQt5,只安装其他依赖
pip install pyinstaller pystray Pillow PySocks
python -c "import PyQt5.QtWidgets; print('PyQt5 available')" || echo "PyQt5 not available, will skip GUI build"
else
# Windows / macOS: 从 PyPI 安装
pip install pyinstaller PyQt5 pystray Pillow PySocks
fi
shell: bash
- name: Check application icon
if: startsWith(github.ref, 'refs/tags/') && matrix.enable_gui == true
run: |
# 检查图标文件是否存在(图标文件已包含在仓库中)
echo "Checking for icon files..."
ls -lh app_icon.* 2>/dev/null || echo "No icon files found"
if [ "${{ matrix.goos }}" == "windows" ]; then
if [ -f "app_icon.ico" ]; then
echo "✓ Found app_icon.ico"
elif [ -f "app_icon.png" ]; then
echo "✓ Found app_icon.png (will be used as icon)"
else
echo "⚠ No icon file found, PyInstaller will use default icon"
fi
elif [ "${{ matrix.goos }}" == "darwin" ]; then
if [ -f "app_icon.icns" ]; then
echo "✓ Found app_icon.icns"
elif [ -f "app_icon.png" ]; then
echo "✓ Found app_icon.png (will be used as icon)"
else
echo "⚠ No icon file found, PyInstaller will use default icon"
fi
else
if [ -f "app_icon.png" ]; then
echo "✓ Found app_icon.png"
else
echo "⚠ No icon file found, PyInstaller will use default icon"
fi
fi
shell: bash
- name: Build Python executable
if: startsWith(github.ref, 'refs/tags/') && matrix.enable_gui == true
run: |
# 构建 PyInstaller 命令,根据平台添加图标
ICON_ARG=""
if [ "${{ matrix.goos }}" == "windows" ]; then
if [ -f "app_icon.ico" ]; then
ICON_ARG="--icon=app_icon.ico"
elif [ -f "app_icon.png" ]; then
ICON_ARG="--icon=app_icon.png"
fi
pyinstaller --onefile --windowed --name ECHWorkersGUI --hidden-import=PyQt5 $ICON_ARG gui.py
elif [ "${{ matrix.goos }}" == "linux" ]; then
if python -c "import PyQt5.QtWidgets" 2>/dev/null; then
if [ -f "app_icon.png" ]; then
ICON_ARG="--icon=app_icon.png"
fi
pyinstaller --onefile --name ECHWorkersGUI --hidden-import=PyQt5 $ICON_ARG gui.py
else
echo "PyQt5 not available, skipping GUI build for Linux"
echo "Only Go executable will be included"
fi
else
# macOS
if [ -f "app_icon.icns" ]; then
ICON_ARG="--icon=app_icon.icns"
elif [ -f "app_icon.png" ]; then
ICON_ARG="--icon=app_icon.png"
fi
pyinstaller --onefile --name ECHWorkersGUI --hidden-import=PyQt5 $ICON_ARG gui.py
fi
shell: bash
- name: Download China IP list
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "Downloading latest China IP list (IPv4 and IPv6)..."
curl -L -o chn_ip.txt "https://raw.githubusercontent.com/mayaxcn/china-ip-list/refs/heads/master/chn_ip.txt" || echo "Failed to download IPv4 list, will skip"
curl -L -o chn_ip_v6.txt "https://raw.githubusercontent.com/mayaxcn/china-ip-list/refs/heads/master/chn_ip_v6.txt" || echo "Failed to download IPv6 list, will skip"
if [ -f "chn_ip.txt" ]; then
echo "✓ China IPv4 IP list downloaded successfully"
wc -l chn_ip.txt
else
echo "⚠ China IPv4 IP list download failed, release will continue without it"
fi
if [ -f "chn_ip_v6.txt" ]; then
echo "✓ China IPv6 IP list downloaded successfully"
wc -l chn_ip_v6.txt
else
echo "⚠ China IPv6 IP list download failed, release will continue without it"
fi
shell: bash
- name: Prepare release files
if: startsWith(github.ref, 'refs/tags/')
run: |
mkdir -p release
# Go 可执行文件
cp ech-workers${{ matrix.exe_ext }} release/
# 中国IP列表文件(离线版本)
if [ -f "chn_ip.txt" ]; then
cp chn_ip.txt release/
echo "✓ China IPv4 IP list included in release"
fi
if [ -f "chn_ip_v6.txt" ]; then
cp chn_ip_v6.txt release/
echo "✓ China IPv6 IP list included in release"
fi
# GUI(仅桌面版)
if [ "${{ matrix.enable_gui }}" = "true" ]; then
if [ "${{ matrix.goos }}" == "windows" ]; then
if [ -f "dist/ECHWorkersGUI.exe" ]; then
cp dist/ECHWorkersGUI.exe release/
fi
else
if [ -f "dist/ECHWorkersGUI" ]; then
cp dist/ECHWorkersGUI release/
chmod +x release/ECHWorkersGUI
elif [ "${{ matrix.goos }}" == "linux" ]; then
echo "GUI executable not built, only Go executable will be included"
fi
fi
fi
# README
{
echo "ECH Workers Client"
echo ""
echo "Target: ${{ matrix.target }}"
echo ""
echo "Files:"
echo "- ech-workers${{ matrix.exe_ext }}: Go compiled core proxy program"
if [ -f "release/chn_ip.txt" ]; then
echo "- chn_ip.txt: China IPv4 IP list (offline version)"
fi
if [ -f "release/chn_ip_v6.txt" ]; then
echo "- chn_ip_v6.txt: China IPv6 IP list (offline version)"
fi
if [ "${{ matrix.enable_gui }}" = "true" ]; then
if [ "${{ matrix.goos }}" == "windows" ]; then
echo "- ECHWorkersGUI.exe: Python GUI client (standalone executable)"
elif [ -f "release/ECHWorkersGUI" ]; then
echo "- ECHWorkersGUI: Python GUI client (standalone executable)"
else
echo "- Note: GUI client not available for this architecture"
echo " Use ech-workers from command line instead"
fi
else
echo "- GUI client not included for this build (CLI only, suitable for routers / servers)"
fi
echo ""
echo "Usage:"
if [ "${{ matrix.goos }}" == "windows" ]; then
echo "1. Double-click ECHWorkersGUI.exe to launch the GUI (if present)"
echo "2. Or run ech-workers.exe from command line"
else
echo "1. Run ./ech-workers from command line"
if [ "${{ matrix.enable_gui }}" = "true" ]; then
echo "2. Or run ./ECHWorkersGUI to launch the GUI"
fi
fi
echo ""
echo "System Requirements:"
if [ "${{ matrix.target }}" = "softrouter" ]; then
echo "- Linux soft router / NAS (OpenWrt / iStoreOS / x86_64 or ARM64)"
echo "- Architecture: ${{ matrix.goarch }}"
echo "- Recommended: run from SSH / shell"
else
if [ "${{ matrix.goos }}" == "windows" ]; then
echo "- Windows: Windows 10+"
elif [ "${{ matrix.goos }}" == "darwin" ]; then
echo "- macOS: macOS 10.13+"
else
echo "- Linux: Ubuntu 18.04+ / Debian 10+ / CentOS 7+"
echo "- Architecture: ${{ matrix.goarch }}"
fi
fi
echo "- No Python installation required for running the binaries"
} > release/README.txt
shell: bash
- name: Create archive (Windows)
if: startsWith(github.ref, 'refs/tags/') && matrix.goos == 'windows'
run: |
cd release
powershell Compress-Archive -Path * -DestinationPath ../ECHWorkers-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.artifact_suffix }}${{ matrix.archive_ext }} -Force
shell: powershell
- name: Create archive (macOS)
if: startsWith(github.ref, 'refs/tags/') && matrix.goos == 'darwin'
run: |
cd release
zip -r ../ECHWorkers-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.artifact_suffix }}${{ matrix.archive_ext }} .
shell: bash
- name: Create archive (Linux)
if: startsWith(github.ref, 'refs/tags/') && matrix.goos == 'linux'
run: |
cd release
tar -czf ../ECHWorkers-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.artifact_suffix }}${{ matrix.archive_ext }} .
shell: bash
- name: Upload artifacts
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v4
with:
name: ECHWorkers-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.artifact_suffix }}
path: ECHWorkers-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.artifact_suffix }}${{ matrix.archive_ext }}
retention-days: 30
release:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create release
uses: softprops/action-gh-release@v1
with:
files: |
artifacts/**/*.zip
artifacts/**/*.tar.gz
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}