@@ -19,42 +19,58 @@ jobs:
1919    strategy :
2020      matrix :
2121        os : [ "ubuntu-latest", "windows-latest" ] 
22+         python-version : [ "3.12" ]  #  指定 Python 版本
2223    runs-on : ${{ matrix.os }} 
2324    steps :
2425      - name : Checkout code 
25-         uses : actions/checkout@v3  
26+         uses : actions/checkout@v4   #  推荐使用最新版本 
2627
27-       - name : Set up environment for Linux (Ubuntu) 
28-         if : matrix.os == 'ubuntu-latest' 
28+       - name : Set up Python ${{ matrix.python-version }} 
29+         uses : actions/setup-python@v5  #  使用 setup-python action
30+         with :
31+           python-version : ${{ matrix.python-version }} 
32+           #  cache: 'pip' # 如果有 requirements.txt 可以开启 pip 缓存
33+ 
34+       - name : Create and activate virtual environment 
35+         shell : bash  #  Linux和Windows通用Shell,方便执行venv命令
2936        run : | 
30-           sudo apt update 
31-           sudo apt install -y python3-venv build-essential 
32-           echo "Environment setup complete." 
37+           # 创建虚拟环境 
38+           python -m venv .venv 
39+           # 激活虚拟环境 (对于当前runner的Shell有效) 
40+           # 对于bash/zsh 
41+           if [[ "${{ runner.os }}" == "Linux" ]]; then 
42+             echo "source .venv/bin/activate" >> "$GITHUB_ENV" 
43+           # 对于PowerShell 
44+           elif [[ "${{ runner.os }}" == "Windows" ]]; then 
45+             echo ".venv/Scripts/Activate.ps1" >> "$GITHUB_ENV" 
46+           fi 
47+           # 更新 PATH 确保后续步骤使用激活的 venv 
48+           echo "PATH=$PWD/.venv/bin:$PATH" >> "$GITHUB_ENV" # Linux 
49+           echo "PATH=$PWD/.venv/Scripts;$PATH" >> "$GITHUB_ENV" # Windows 
3350
34- name : Set up environment for Windows 
35-         if :  matrix.os == 'windows-latest' 
51+ name : Install dependencies from requirements.txt 
52+         #  确保在激活的虚拟环境中安装依赖 
3653        run : | 
37-           choco install python312 --yes 
38-           python -m ensurepip 
39-           echo "Environment setup complete." 
54+           pip install --upgrade pip 
55+           pip install -r requirements.txt # 假设你的依赖在 requirements.txt 中 
4056
4157name : Install dependencies and build for Linux 
4258        if : matrix.os == 'ubuntu-latest' 
4359        shell : bash 
4460        run : | 
45-           chmod +x build.sh  # 确保脚本可执行  
46-           ./build.sh  # 运行Bash脚本  
61+           chmod +x build.sh 
62+           ./build.sh 
4763
4864name : Install dependencies and build for Windows 
4965        if : matrix.os == 'windows-latest' 
5066        shell : pwsh 
5167        run : | 
52-           .\build.ps1  # 运行PowerShell脚本  
68+           .\build.ps1 
5369
5470name : Upload build output as artifact 
5571        uses : actions/upload-artifact@v4 
5672        with :
5773          name : app-${{ matrix.os }} 
5874          path : | 
5975            build/app.dist/** 
60- if-no-files-found : error 
76+ if-no-files-found : error 
0 commit comments