1- name : Auto-increment version and release
1+ name : Auto-increment version and release (Win7 compatible)
22
3- # 触发条件:推送到 main 分支(排除标签推送,避免循环触发)
43on :
54 push :
65 branches : [ "main" ]
7- tags-ignore : [ 'v*' ] # 忽略标签推送,防止重复执行
6+ tags-ignore : [ 'v*' ]
87
98jobs :
109 get-next-version :
1110 runs-on : ubuntu-latest
1211 outputs :
13- next_version : ${{ steps.calc-version.outputs.next_version }} # 输出下一个版本号
12+ next_version : ${{ steps.calc-version.outputs.next_version }}
1413 steps :
1514 - uses : actions/checkout@v4
1615 with :
17- fetch-depth : 0 # 拉取所有历史,以便获取所有标签
16+ fetch-depth : 0
1817
1918 - name : Calculate next version
2019 id : calc-version
2120 run : |
22- # 获取所有符合 v*.*.* 格式的标签,按版本号排序
2321 latest_tag=$(git tag --list "v*.*.*" --sort=-v:refname | head -n 1)
24-
25- # 如果没有历史标签,初始版本为 v1.0.0
2622 if [ -z "$latest_tag" ]; then
2723 next_version="v0.0.1"
2824 else
29- # 移除前缀 'v',拆分版本号为 major.minor.patch
30- version=${latest_tag:1} # 如 v1.1.2 → 1.1.2
25+ version=${latest_tag:1}
3126 IFS='.' read -r major minor patch <<< "$version"
32-
33- # 递增 patch 版本(小版本+1)
3427 patch=$((patch + 1))
3528 next_version="v$major.$minor.$patch"
3629 fi
37-
3830 echo "next_version=$next_version" >> $GITHUB_OUTPUT
3931 echo "将创建新版本: $next_version"
4032
@@ -45,29 +37,47 @@ jobs:
4537 fail-fast : false
4638 matrix :
4739 os : [ubuntu-latest, windows-latest]
48- python-version : ["3.11"]
40+ python-version : ["3.8"] # 关键:使用 Python 3.8(Win7 最后支持的版本)
4941
5042 steps :
5143 - uses : actions/checkout@v4
5244
53- - name : Set up Python
45+ - name : Set up Python 3.8
5446 uses : actions/setup-python@v5
5547 with :
5648 python-version : ${{ matrix.python-version }}
49+ # 可选:指定缓存依赖路径(加速构建)
50+ cache : ' pip'
5751
58- - name : Install dependencies
52+ - name : Install compatible PyInstaller (Win7 support)
5953 run : |
6054 python -m pip install --upgrade pip
61- pip install pyinstaller
55+ # PyInstaller 5.13 是最后支持 Python 3.8 且兼容 Win7 的版本之一
56+ pip install pyinstaller==5.13
6257 if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
63- shell : ${{ matrix.os == 'windows-latest' ? 'pwsh' : 'bash' }}
58+ shell : ${{ contains( matrix.os, 'windows') && 'pwsh' || 'bash' }}
6459
65- - name : Package with pyinstaller
60+ - name : Set OS name env
6661 run : |
67- # 按系统和版本号命名(如 myapp-v1.0.0-linux)
68- os_name=${{ matrix.os == 'windows-latest' ? 'windows' : 'linux' }}
69- pyinstaller --onefile --name "myapp-${{ needs.get-next-version.outputs.next_version }}-$os_name" main.py
70- shell : ${{ matrix.os == 'windows-latest' ? 'pwsh' : 'bash' }}
62+ if [[ "${{ matrix.os }}" == *"windows"* ]]; then
63+ echo "OS_NAME=windows" >> $GITHUB_ENV
64+ else
65+ echo "OS_NAME=linux" >> $GITHUB_ENV
66+ fi
67+ shell : bash
68+
69+ - name : Package with pyinstaller (Win7 compatible)
70+ run : |
71+ # 针对 Windows 7 额外添加兼容性参数
72+ if [ "$env:OS_NAME" = "windows" ]; then
73+ pyinstaller --onefile --name "myapp-${{ needs.get-next-version.outputs.next_version }}-$env:OS_NAME" \
74+ --win-private-assemblies \ # 打包私有依赖,避免系统依赖冲突
75+ main.py
76+ else
77+ pyinstaller --onefile --name "myapp-${{ needs.get-next-version.outputs.next_version }}-$env:OS_NAME" \
78+ main.py
79+ fi
80+ shell : ${{ contains(matrix.os, 'windows') && 'pwsh' || 'bash' }}
7181
7282 - name : Upload artifacts
7383 uses : actions/upload-artifact@v4
@@ -93,18 +103,18 @@ jobs:
93103 git tag ${{ needs.get-next-version.outputs.next_version }}
94104 git push origin ${{ needs.get-next-version.outputs.next_version }}
95105 env :
96- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} # 用于推送标签
106+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
97107
98108 - name : Create GitHub Release
99109 uses : softprops/action-gh-release@v2
100110 with :
101111 tag_name : ${{ needs.get-next-version.outputs.next_version }}
102- name : Release ${{ needs.get-next-version.outputs.next_version }}
112+ name : Release ${{ needs.get-next-version.outputs.next_version }} (Win7 兼容)
103113 body : |
104114 自动发布版本 ${{ needs.get-next-version.outputs.next_version }}
105- 包含 Linux 和 Windows 可执行文件
115+ 支持 Windows 7(基于 Python 3.8)和 Linux 系统
106116 files : |
107- ExamCountdown -${{ needs.get-next-version.outputs.next_version }}-ubuntu-latest/*
108- ExamCountdown -${{ needs.get-next-version.outputs.next_version }}-windows-latest/*
117+ myapp -${{ needs.get-next-version.outputs.next_version }}-ubuntu-latest/*
118+ myapp -${{ needs.get-next-version.outputs.next_version }}-windows-latest/*
109119 env :
110- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
120+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments