-
Notifications
You must be signed in to change notification settings - Fork 382
312 lines (275 loc) · 10.9 KB
/
release.yml
File metadata and controls
312 lines (275 loc) · 10.9 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
name: Release
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
release_tag:
description: "Tag name to publish (example: v1.2.0). Leave empty for build-only run."
required: false
type: string
publish:
description: "Publish GitHub release"
required: false
default: false
type: boolean
make_public:
description: "Make release public immediately (false = draft + prerelease)"
required: false
default: false
type: boolean
include_termux:
description: "Publish Termux ARM64 and ARMv7 bundles"
required: false
default: true
type: boolean
permissions:
contents: write
jobs:
build-binaries:
name: Build ${{ matrix.platform }}-${{ matrix.arch }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.optional }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
platform: windows
arch: amd64
optional: false
- os: ubuntu-latest
platform: linux
arch: amd64
optional: false
- os: macos-13
platform: macos
arch: amd64
optional: false
- os: macos-14
platform: macos
arch: arm64
optional: false
- os: ubuntu-24.04-arm
platform: linux
arch: arm64
optional: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt pyinstaller
- name: Build standalone binary
run: pyinstaller --noconfirm --clean --onefile --name MasterHttpRelayVPN --paths src main.py
- name: Smoke test binary
shell: bash
run: |
set -euo pipefail
if [ "${{ runner.os }}" = "Windows" ]; then
BIN="dist/MasterHttpRelayVPN.exe"
else
BIN="dist/MasterHttpRelayVPN"
chmod +x "$BIN"
fi
"$BIN" --version
"$BIN" --help >/dev/null
- name: Package release artifact (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$content = Get-Content "src/core/constants.py" -Raw
$m = [regex]::Match($content, '__version__\s*=\s*"([^"]+)"')
if (-not $m.Success) { throw "Could not read version from src/core/constants.py" }
$version = $m.Groups[1].Value
New-Item -ItemType Directory -Path "release-assets" -Force | Out-Null
$staging = "release-staging"
Remove-Item -Recurse -Force $staging -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path $staging -Force | Out-Null
Copy-Item "dist/MasterHttpRelayVPN.exe" "$staging/MasterHttpRelayVPN.exe"
foreach ($f in @("README.md", "README_FA.md", "config.example.json", "start.bat", "start.sh")) {
if (Test-Path $f) { Copy-Item $f $staging }
}
$archive = "MasterHttpRelayVPN-$version-${{ matrix.platform }}-${{ matrix.arch }}.zip"
Compress-Archive -Path "$staging/*" -DestinationPath "release-assets/$archive" -Force
$hash = (Get-FileHash "release-assets/$archive" -Algorithm SHA256).Hash.ToLower()
"$hash $archive" | Out-File -FilePath "release-assets/$archive.sha256" -Encoding ascii
- name: Package release artifact (non-Windows)
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
version=$(python - <<'PY'
import re
from pathlib import Path
t = Path('src/core/constants.py').read_text(encoding='utf-8')
m = re.search(r'__version__\s*=\s*"([^"]+)"', t)
print(m.group(1) if m else '0.0.0')
PY
)
mkdir -p release-assets release-staging
rm -rf release-staging/*
cp dist/MasterHttpRelayVPN release-staging/MasterHttpRelayVPN
chmod +x release-staging/MasterHttpRelayVPN
for f in README.md README_FA.md config.example.json start.sh start.bat; do
[ -f "$f" ] && cp "$f" release-staging/
done
archive="MasterHttpRelayVPN-${version}-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz"
tar -C release-staging -czf "release-assets/$archive" .
ARCHIVE_NAME="$archive" python - <<'PY'
import hashlib
import os
from pathlib import Path
archive = Path("release-assets") / os.environ["ARCHIVE_NAME"]
digest = hashlib.sha256(archive.read_bytes()).hexdigest()
(archive.parent / f"{archive.name}.sha256").write_text(
f"{digest} {archive.name}\n",
encoding="utf-8",
)
PY
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.platform }}-${{ matrix.arch }}
path: release-assets/*
build-termux:
name: Build termux-arm64-armv7
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.inputs.include_termux == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU for cross-arch containers
uses: docker/setup-qemu-action@v3
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Build Termux binaries (arm64 + armv7)
shell: bash
run: |
set -euo pipefail
version=$(python - <<'PY'
import re
from pathlib import Path
t = Path('src/core/constants.py').read_text(encoding='utf-8')
m = re.search(r'__version__\s*=\s*"([^"]+)"', t)
print(m.group(1) if m else '0.0.0')
PY
)
mkdir -p release-assets termux-dist
# Build using Alpine Linux with QEMU for cross-compilation
# This is more reliable than depending on Termux Docker images
build_termux_arch () {
local arch="$1"
local platform="$2"
local qemu_arch="$3"
echo "Building for Termux ${arch}..."
rm -rf dist build *.spec || true
# Use Alpine with QEMU for reliable cross-platform builds
docker run --rm --platform "$platform" \
-v "$PWD:/work" \
-w /work \
alpine:latest \
sh -c '
set -euo pipefail
echo "Installing build dependencies..."
apk add --no-cache python3 py3-pip make gcc musl-dev openssl-dev libffi-dev rust cargo
echo "Installing Python packages..."
python3 -m pip install --upgrade pip pyinstaller
pip install -r requirements.txt
echo "Building binary for '"'"'${arch}'"'"'..."
pyinstaller --noconfirm --clean --onefile --name MasterHttpRelayVPN --paths src main.py
'
if [ ! -f dist/MasterHttpRelayVPN ]; then
echo "ERROR: Missing binary output for ${arch}" >&2
exit 1
fi
cp dist/MasterHttpRelayVPN "termux-dist/MasterHttpRelayVPN-${arch}"
chmod +x "termux-dist/MasterHttpRelayVPN-${arch}"
echo "✓ Successfully built for ${arch}"
}
# Build both ARM architectures
build_termux_arch "arm64" "linux/arm64" "aarch64"
build_termux_arch "armv7" "linux/arm/v7" "arm"
echo ""
echo "Packaging releases..."
for arch in arm64 armv7; do
staging="termux-staging-${arch}"
rm -rf "$staging"
mkdir -p "$staging"
cp "termux-dist/MasterHttpRelayVPN-${arch}" "$staging/MasterHttpRelayVPN"
chmod +x "$staging/MasterHttpRelayVPN"
[ -f config.example.json ] && cp config.example.json "$staging/"
[ -f README.md ] && cp README.md "$staging/"
[ -f README_FA.md ] && cp README_FA.md "$staging/"
# Create Termux launch script for native Termux environment
printf '%s\n' \
'#!/data/data/com.termux/files/usr/bin/bash' \
'set -euo pipefail' \
'chmod +x ./MasterHttpRelayVPN' \
'exec ./MasterHttpRelayVPN "$@"' \
> "$staging/termux-run.sh"
chmod +x "$staging/termux-run.sh"
archive="MasterHttpRelayVPN-${version}-termux-${arch}.zip"
(cd "$staging" && zip -qr "../release-assets/${archive}" .)
# Generate checksum
python3 << EOF
import hashlib
from pathlib import Path
archive_file = Path("release-assets") / "$archive"
sha256_sum = hashlib.sha256(archive_file.read_bytes()).hexdigest()
checksum_file = archive_file.with_suffix(archive_file.suffix + ".sha256")
checksum_file.write_text(f"{sha256_sum} $archive\\n")
EOF
echo "✓ Packaged: $archive"
done
echo ""
ls -lah release-assets/
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: release-termux
path: release-assets/*
publish-release:
name: Publish GitHub Release
runs-on: ubuntu-latest
needs: [build-binaries, build-termux]
if: always() && !cancelled() && (startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true' && startsWith(github.event.inputs.release_tag, 'v')))
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: release-assets
- name: Flatten artifact directories
run: |
mkdir -p final-assets
find release-assets -type f -exec cp {} final-assets/ \;
ls -lah final-assets
- name: Fail if no artifacts
run: |
set -euo pipefail
count=$(find final-assets -type f | wc -l)
echo "Artifact count: ${count}"
if [ "${count}" -eq 0 ]; then
echo "No artifacts were produced."
exit 1
fi
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.event.inputs.release_tag }}
files: final-assets/*
generate_release_notes: true
prerelease: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.make_public != 'true' }}
draft: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.make_public != 'true' }}
make_latest: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.make_public == 'true') && 'true' || 'false' }}