Repository navigation
308 lines (269 loc) · 10.9 KB
/
Copy pathbuild-release.yml
File metadata and controls
308 lines (269 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
name: Build and Release Python Archives
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
release_tag:
description: 'Release tag name'
required: true
default: 'latest'
permissions:
contents: write
jobs:
build-python:
name: Build ${{ matrix.python_version }} on ${{ matrix.os-name }} (${{ matrix.arch }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# --- Linux x64 ---
- os: ubuntu-latest
os-name: 'linux'
arch: x86_64
python_version: '2.7.18'
- os: ubuntu-latest
os-name: 'linux'
arch: x86_64
python_version: '3.13.1'
# --- Linux ARM64 (native ARM64 runner) ---
- os: ubuntu-24.04-arm
os-name: 'linux'
arch: aarch64
python_version: '2.7.18'
- os: ubuntu-24.04-arm
os-name: 'linux'
arch: aarch64
python_version: '3.13.1'
# --- macOS x64 (via Rosetta 2 on ARM64 runner) ---
# GitHub 已淘汰所有 Intel macOS 运行器 (macos-12/13)
# 使用 macos-latest (ARM64) + Rosetta 2 模拟 x86_64
- os: macos-latest
os-name: 'macos'
arch: x86_64
python_version: '2.7.18'
- os: macos-latest
os-name: 'macos'
arch: x86_64
python_version: '3.13.1'
# --- macOS ARM64 (Apple Silicon) ---
- os: macos-latest
os-name: 'macos'
arch: arm64
python_version: '2.7.18'
- os: macos-latest
os-name: 'macos'
arch: arm64
python_version: '3.13.1'
# --- Windows x64 ---
# Python 2.7 无法在现代 CI 上从源码编译(需要 VS2008)
# 改用 python.org 官方预编译 MSI 安装包提取
- os: windows-latest
os-name: 'windows'
arch: x86_64
python_version: '2.7.18'
use_prebuilt: true
- os: windows-latest
os-name: 'windows'
arch: x86_64
python_version: '3.13.1'
# --- Windows ARM64 (Cross-compile) ---
- os: windows-latest
os-name: 'windows'
arch: arm64
python_version: '3.13.1'
steps:
- name: Checkout code
uses: actions/checkout@v4
# --- Standard Setup & Build ---
- name: Set up dependencies (Linux)
if: matrix.os-name == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev zlib1g-dev \
libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev \
libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev \
tk-dev libffi-dev wget
- name: Set up dependencies (macOS)
if: matrix.os-name == 'macos'
run: |
if [[ "${{ matrix.arch }}" == "x86_64" ]]; then
echo "Installing Rosetta 2 for x86_64 emulation..."
sudo softwareupdate --install-rosetta --agree-to-license || true
# 安装 x86_64 版本的 Homebrew(安装到 /usr/local)
echo "Installing x86_64 Homebrew..."
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" </dev/null
# 用 x86_64 Homebrew 安装 x86_64 版本的依赖
BREW_X86="/usr/local/bin/brew"
arch -x86_64 $BREW_X86 install readline sqlite3 xz zlib tcl-tk
if [[ "${{ matrix.python_version }}" == 2.* ]]; then
if ! arch -x86_64 $BREW_X86 install openssl@1.1; then
echo "openssl@1.1 is unavailable on current Homebrew, falling back to openssl@3"
arch -x86_64 $BREW_X86 install openssl@3
fi
else
arch -x86_64 $BREW_X86 install openssl@3
fi
else
# ARM64 原生构建,使用默认 Homebrew
brew install readline sqlite3 xz zlib tcl-tk
if [[ "${{ matrix.python_version }}" == 2.* ]]; then
if ! brew install openssl@1.1; then
echo "openssl@1.1 is unavailable on current Homebrew, falling back to openssl@3"
brew install openssl@3
fi
else
brew install openssl@3
fi
fi
- name: Set up dependencies (Windows)
if: matrix.os-name == 'windows'
shell: bash
run: |
which msbuild.exe || where.exe msbuild || echo "MSBuild not found"
# Windows + Python 2.7:从 python.org 下载官方预编译 MSI 并提取
# 原因:Python 2.7 需要 Visual Studio 2008 (VC9) 从源码编译,
# 现代 CI runner 使用 VS2022,无法编译 Python 2.7 源码。
- name: Download prebuilt Python 2.7 (Windows)
if: matrix.os-name == 'windows' && startsWith(matrix.python_version, '2.')
shell: powershell
run: |
$version = "${{ matrix.python_version }}"
$distDir = "dist\python-$version"
New-Item -ItemType Directory -Force -Path $distDir
# 下载官方 Python 2.7.18 Windows x64 MSI
$msiUrl = "https://www.python.org/ftp/python/$version/python-$version.amd64.msi"
$msiPath = "$env:TEMP\python-$version.amd64.msi"
Write-Host "Downloading $msiUrl ..."
Invoke-WebRequest -Uri $msiUrl -OutFile $msiPath
# 使用 admin install (/a) 将 MSI 内容提取到目标目录
# /a 模式不会写入注册表,生成可移植的文件树
$targetDir = (Resolve-Path $distDir).Path
Write-Host "Extracting to $targetDir ..."
$proc = Start-Process msiexec -ArgumentList "/a `"$msiPath`" TARGETDIR=`"$targetDir`" /quiet /qn /norestart" -Wait -PassThru
if ($proc.ExitCode -ne 0) {
Write-Error "msiexec /a failed with exit code $($proc.ExitCode)"
exit 1
}
# 验证 python.exe 是否存在
if (-not (Test-Path "$targetDir\python.exe")) {
Write-Error "python.exe not found in $targetDir after extraction"
Get-ChildItem $targetDir -Recurse | Select-Object FullName | Head -30
exit 1
}
Write-Host "Python 2.7 extraction successful:"
Get-ChildItem $targetDir | Select-Object Name, Length
- name: Build Python
# Windows + Python 2.7 使用上方预编译步骤,跳过从源码编译
if: "!(matrix.os-name == 'windows' && startsWith(matrix.python_version, '2.'))"
shell: bash
env:
TARGET_ARCH: ${{ matrix.arch }}
run: |
# macOS x86_64:通过 Rosetta 2 运行整个构建
if [[ "${{ matrix.os-name }}" == "macos" && "${{ matrix.arch }}" == "x86_64" ]]; then
echo "Building under Rosetta 2 (arch -x86_64)..."
arch -x86_64 bash ./scripts/build-python.sh ${{ matrix.python_version }}
else
bash ./scripts/build-python.sh ${{ matrix.python_version }}
fi
- name: Create archive
shell: bash
run: |
cd dist
if [ "${{ matrix.os-name }}" = "windows" ]; then
7z a python-${{ matrix.python_version }}-windows-${{ matrix.arch }}.zip python-${{ matrix.python_version }}/
else
# Use matrix.arch explicitly
tar czf python-${{ matrix.python_version }}-${{ matrix.os-name }}-${{ matrix.arch }}.tar.gz python-${{ matrix.python_version }}/
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: python-${{ matrix.python_version }}-${{ matrix.os-name }}-${{ matrix.arch }}
path: |
dist/*.tar.gz
dist/*.zip
retention-days: 7
create-release:
name: Create GitHub Release
needs: build-python
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare release assets
run: |
mkdir -p release-assets
find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec cp {} release-assets/ \;
ls -lh release-assets/
- name: Get release tag
id: get_tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ github.event.inputs.release_tag }}" >> $GITHUB_OUTPUT
else
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Generate release notes
id: release_notes
run: |
cat << EOF > release-notes.md
# Python Archive Release ${{ steps.get_tag.outputs.tag }}
This release includes standalone Python distributions for multiple platforms.
## Included Python Versions
- Python 2.7.18 (最后的 Python 2 版本)
- Python 3.13.1 (最新的 Python 3 稳定版)
## Platforms
- Linux (x86_64, aarch64)
- macOS (x86_64, arm64)
- Windows (x86_64, arm64)
## Usage
Download the appropriate archive for your platform and extract it:
**Linux/macOS:**
\`\`\`bash
tar xzf python-<version>-<platform>-<arch>.tar.gz
cd python-<version>
./bin/python --version
\`\`\`
**Windows:**
\`\`\`powershell
Expand-Archive python-<version>-windows-<arch>.zip
cd python-<version>
python.exe --version
\`\`\`
## Checksums
SHA256 checksums for verification:
\`\`\`
$(cd release-assets && sha256sum * 2>/dev/null || shasum -a 256 *)
\`\`\`
EOF
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_tag.outputs.tag }}
name: Python Archive ${{ steps.get_tag.outputs.tag }}
body_path: release-notes.md
draft: false
prerelease: false
files: release-assets/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate checksums file
run: |
cd release-assets
sha256sum * > SHA256SUMS.txt 2>/dev/null || shasum -a 256 * > SHA256SUMS.txt
- name: Upload checksums
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_tag.outputs.tag }}
files: release-assets/SHA256SUMS.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}