.github/workflows/macos.yml
name: macOS
on:
workflow_dispatch:
push:
branches: [main, master]
paths:
- '.github/workflows/macos.yml'
jobs:
pyinstaller-build:
runs-on: macos-13
strategy:
matrix:
node-version: [ 12.x ]
env:
TZ: Asia/Shanghai
PYTHON_VERSION: "3.9.9"
MACOSX_DEPLOYMENT_TARGET: "10.15"
steps:
- uses: actions/checkout@v4
with:
architecture: x64
- name: Install x86_64 Python via pyenv
run: |
# 安装编译依赖
brew install openssl readline sqlite3 xz zlib tcl-tk
# 安装 pyenv
brew install pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
source ~/.bashrc
# 强制安装 x86_64 版本 Python
arch -x86_64 pyenv install $PYTHON_VERSION --verbose
pyenv global $PYTHON_VERSION
# 验证架构
python -c "import platform; print('Python Arch:', platform.machine())"
which python
- name: Set up Python PATH
run: |
echo "$HOME/.pyenv/shims" >> $GITHUB_PATH
echo "$HOME/.pyenv/bin" >> $GITHUB_PATH
- name: Verify Python
run: |
python --version
pip --version
python -c "import platform; print(platform.machine())"
- name: Install build tools
run: |
pip install --upgrade pip
pip install pyinstaller==5.7.0
pip install -r requirements.txt
- name: Build x86_64 executable
run: |
# 完全清理环境
rm -rf __pycache__ build dist
# 强制 x86_64 编译环境
export ARCHFLAGS="-arch x86_64"
export CC="clang -arch x86_64"
export CXX="clang++ -arch x86_64"
# 构建可执行文件
python -m PyInstaller \
--onefile \
--name start_macos \
--clean \
--noconfirm \
start.py
# 验证架构
file dist/start_macos
lipo -archs dist/start_macos
- name: Prepare artifacts
run: |
mkdir -p dist/macos_bundle
cp dist/start_macos dist/macos_bundle/
cp sdk/.env dist/macos_bundle/
# 创建 ZIP 包
cd dist && zip -r macos_bundle.zip macos_bundle/
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: macos-x86_64-build
path: dist/macos_bundle.zip
- name: Create summary
run: |
echo "### 🖥️ x86_64 Build Report" >> $GITHUB_STEP_SUMMARY
echo "- Python: $(python --version)" >> $GITHUB_STEP_SUMMARY
echo "- Binary Architecture: $(lipo -archs dist/start_macos)" >> $GITHUB_STEP_SUMMARY
echo "- Size: $(du -h dist/start_macos | cut -f1)" >> $GITHUB_STEP_SUMMARY
echo "```" >> $GITHUB_STEP_SUMMARY
file dist/start_macos >> $GITHUB_STEP_SUMMARY
echo "```" >> $GITHUB_STEP_SUMMARY
.github/workflows/ubuntu.yml
name: Ubuntu
on:
workflow_dispatch:
push:
branches: [ main,master ]
paths:
- '.github/workflows/ubuntu.yml'
jobs:
pyinstaller-build:
runs-on: ubuntu-latest
container:
image: ubuntu:22.04
env: # 工作级别环境变量
DEBIAN_FRONTEND: noninteractive
TZ: Asia/Shanghai
steps:
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
DEBIAN_FRONTEND=noninteractive TZ=Asia/Shanghai apt-get update && apt-get install -y \
sudo \
openjdk-11-jdk \
libx11-6 \
libxcomposite1 \
libxrandr2 \
libxss1 \
libgdk-pixbuf2.0-0 \
libgtk-3-0 \
xauth \
libbz2-dev \
libncurses5-dev \
libffi-dev \
libreadline-dev \
libssl-dev \
zlib1g-dev \
build-essential \
libsqlite3-dev \
tk-dev \
libgdbm-dev \
libc6-dev \
liblzma-dev \
libncursesw5-dev \
git \
python3-pip \
python-is-python3 \
python3-venv \
wget \
unzip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
- name: Install pyenv and Python and Install Env and Build Executable
shell: bash -l {0}
run: |
wget https://bj.bcebos.com/petite-mark/public_read/vipshop/Jetbrains/pyenv-2.5.0.zip -O pyenv.zip && unzip pyenv.zip && mv pyenv-2.5.0/ ~/.pyenv && rm pyenv.zip
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
# 立即生效
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
mkdir -p ~/.pyenv/cache && wget https://bj.bcebos.com/petite-mark/public_read/vipshop/Jetbrains/Python-3.9.9.tar.xz -O ~/.pyenv/cache/Python-3.9.9.tar.xz
ln -s ~/.pyenv/bin/pyenv /usr/bin/pyenv && pyenv install 3.9.9 && sudo pyenv global 3.9.9 && rm -rf ~/.pyenv/cache/Python-*.tar.xz
rm -f ~/.pyenv/version
echo "3.9.9" > ~/.pyenv/version
pyenv rehash
# 验证安装
echo "当前Python路径: $(which python)"
echo "当前Python版本: $(python --version)"
echo "当前pip版本: $(pip --version)"
pip install --cache-dir=/tmp/pip-cache -r requirements.txt pyinstaller
python -m PyInstaller \
--onefile \
--name main_app \
--paths=./sdk \
start.py
mv dist/main_app dist/start_linux
- name: Verify .env file
run: |
cd $GITHUB_WORKSPACE
pwd
ls -al
cp sdk/.env dist/.env
ls -al dist/
tar -zcvf linux.zip dist/
ls -la linux.zip
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: linux-build
path: |
linux.zip
start.spec
- name: Create summary
run: |
echo "### 🎉 Build Successful" >> $GITHUB_STEP_SUMMARY
echo "Python Version: $(python --version)" >> $GITHUB_STEP_SUMMARY
echo "- Executable size: $(du -h dist/start_linux | cut -f1)" >> $GITHUB_STEP_SUMMARY
echo "- Download URL: [Artifacts page](#)" >> $GITHUB_STEP_SUMMARY
echo "✔️ Executable **_(start_linux)_** uploaded successfully" >> $GITHUB_STEP_SUMMARY
.github/workflows/windows.yml
name: Windows
on:
workflow_dispatch:
push:
branches: [main, master]
paths:
- '.github/workflows/windows.yml'
jobs:
pyinstaller-build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9.9 (x64)
uses: actions/setup-python@v4
with:
python-version: '3.9.9'
architecture: 'x64' # 明确指定64位架构
- name: Install system dependencies
run: |
# 安装VC++运行库
choco install -y vcredist2015
pip install --upgrade pip setuptools wheel
- name: Install pandas with workaround
run: |
# 先安装numpy确保ABI兼容
pip install numpy==1.21.6 --only-binary=:all:
# 使用预编译的pandas轮子
pip install pandas==2.3.1 --only-binary=:all: --no-deps
# 安装其他依赖
pip install pandas==2.3.1 # 这次带上依赖
pip install setuptools==58.0.4
- name: Install project dependencies
run: |
pip install -r requirements.txt
- name: Build executable
run: |
echo "=== Python版本 ==="
python --version
echo "=== PyInstaller版本 ==="
pyinstaller --version
python -m PyInstaller -F -n main_app --paths=./sdk start.py
copy sdk\.env dist\
- name: Create verified zip
shell: pwsh
run: |
$zipPath = "${{ runner.temp }}/build_artifact.zip"
$files = @(
"${{ github.workspace }}/dist/main_app.exe",
"${{ github.workspace }}/dist/.env"
)
Compress-Archive -Path $files -DestinationPath $zipPath -Force
Write-Output "zip_path=$zipPath" >> $env:GITHUB_ENV
- name: Upload verified zip
uses: actions/upload-artifact@v4
with:
name: windows-build
path: ${{ env.zip_path }}
- name: Create summary
run: |
echo "### 🎉 Build Successful" >> $GITHUB_STEP_SUMMARY
echo "- Python version: $(python --version)" >> $GITHUB_STEP_SUMMARY
echo "- Pandas version: $(pip show pandas | findstr Version)" >> $GITHUB_STEP_SUMMARY
echo "✔️ Windows 7+ compatible build" >> $GITHUB_STEP_SUMMARY