1212 fail-fast : false
1313 matrix :
1414 include :
15+ # ----- Native Builds -----
1516 # ===== Linux =====
1617 - os : linux
1718 arch : x86_64
4647 py_arch : arm64
4748 desc : macos-arm64
4849
50+ # ----- Emulated Builds (都运行在 ubuntu-22.04 x86_64 上) -----
51+ - os : linux
52+ arch : x86
53+ runs_on : ubuntu-22.04
54+ desc : linux-x86
55+ image : i386/debian:12
56+ platform : linux/386
57+ - os : linux
58+ arch : armv7
59+ runs_on : ubuntu-22.04
60+ desc : linux-armv7
61+ image : arm32v7/ubuntu:22.04
62+ platform : linux/arm/v7
63+
4964 runs-on : ${{ matrix.runs_on }}
5065
5166 permissions :
@@ -57,27 +72,96 @@ jobs:
5772 with :
5873 fetch-depth : 0
5974
60- # 安装对应架构的 Python
61- - name : Set up Python
75+ # ===================================================================
76+ # 分支 1: Native Builds (x86_64, arm64, windows, macos)
77+ # ===================================================================
78+ - name : Set up Python (Native)
79+ if : " !matrix.image" # 只在没有定义 matrix.image 的原生构建上运行
6280 uses : actions/setup-python@v5
6381 with :
6482 python-version : ' 3.12'
6583 architecture : ${{ matrix.py_arch }}
6684
67- - name : Install dependencies
85+ - name : Install dependencies (Native)
86+ if : " !matrix.image"
6887 run : |
6988 python -m pip install --upgrade pip
7089 if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
7190 pip install pyinstaller
7291 shell : bash
7392
74- - name : Build with PyInstaller
93+ - name : Build with PyInstaller (Native)
94+ if : " !matrix.image"
7595 run : |
7696 mkdir -p dist
7797 pyinstaller --onefile --name TJUEcardSetup setup.py
7898 pyinstaller --onefile --noconsole --name TJUEcard TJUEcard_main.py
7999 shell : bash
80100
101+ # ===================================================================
102+ # 分支 2: Emulated Builds (x86, armv7)
103+ # ===================================================================
104+ - name : Set up QEMU
105+ if : " matrix.image"
106+ uses : docker/setup-qemu-action@v3
107+
108+ - name : Build with PyInstaller (Emulated)
109+ if : " matrix.image"
110+ run : |
111+ # 根据 matrix.arch 的值,决定 PIP_FLAG 的内容
112+ PIP_FLAG_VALUE=""
113+ if [ "${{ matrix.arch }}" = "x86" ]; then
114+ PIP_FLAG_VALUE="--break-system-packages"
115+ fi
116+
117+ # 将 PIP_FLAG_VALUE 作为环境变量传入容器
118+ docker run --rm --privileged \
119+ --platform ${{ matrix.platform }} \
120+ -v "${{ github.workspace }}":/workspace \
121+ -w /workspace \
122+ -e PIP_FLAG="${PIP_FLAG_VALUE}" \
123+ ${{ matrix.image }} \
124+ sh -c ' \
125+ set -ex; \
126+ apt-get update; \
127+ apt-get install -y \
128+ python3 \
129+ python3-pip \
130+ git \
131+ build-essential \
132+ libffi-dev \
133+ python3-cryptography; \
134+ \
135+ ln -s /usr/bin/python3 /usr/bin/python || true; \
136+ \
137+ # 直接使用从外部传入的 PIP_FLAG 环境变量
138+ python -m pip install --upgrade pip ${PIP_FLAG}; \
139+ \
140+ if [ -f requirements.txt ]; then \
141+ if [ "${{ matrix.arch }}" = "x86" ]; then \
142+ echo "==> i386 environment: Installing dependencies from requirements.txt, excluding cryptography"; \
143+ grep -v "^cryptography" requirements.txt | xargs -r python -m pip install ${PIP_FLAG}; \
144+ else \
145+ echo "==> armv7 environment: Installing all dependencies from requirements.txt"; \
146+ python -m pip install -r requirements.txt ${PIP_FLAG}; \
147+ fi; \
148+ fi; \
149+ \
150+ pip install pyinstaller ${PIP_FLAG}; \
151+ \
152+ pyinstaller --onefile --name TJUEcardSetup setup.py; \
153+ pyinstaller --onefile --noconsole --name TJUEcard TJUEcard_main.py \
154+ '
155+
156+ - name : Fix file ownership
157+ if : " matrix.image" # 只在 Emulated 构建后运行
158+ run : |
159+ # The files created inside the container are owned by root.
160+ # Change ownership to the current runner user to avoid permission errors.
161+ sudo chown -R "$(id -u):$(id -g)" .
162+ shell : bash
163+ # ============ 从这里开始,所有分支的步骤合并 ============
164+
81165 # ===== 验证架构 =====
82166 - name : Check binary arch (Linux)
83167 if : runner.os == 'Linux'
0 commit comments