@@ -2,8 +2,6 @@ name: Build SnipasteOCR
2
2
3
3
on :
4
4
push :
5
- tags :
6
- - ' v*'
7
5
workflow_dispatch :
8
6
9
7
permissions :
@@ -21,64 +19,91 @@ jobs:
21
19
with :
22
20
python-version : ' 3.10'
23
21
24
- - name : Cache Python packages
22
+ - name : Cache UV packages
25
23
uses : actions/cache@v4
26
24
with :
27
- path : ~/.cache/pip
28
- key : ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
25
+ path : |
26
+ ~\AppData\Local\uv
27
+ ~\.cache\uv
28
+ key : ${{ runner.os }}-uv-${{ hashFiles('**/requirements.txt') }}
29
29
restore-keys : |
30
- ${{ runner.os }}-pip -
30
+ ${{ runner.os }}-uv -
31
31
32
32
- name : Install dependencies
33
+ shell : pwsh
33
34
run : |
34
35
pip install uv
35
36
uv sync
36
37
37
38
- name : Build Release
39
+ shell : pwsh
38
40
run : |
39
- uv run pyinstaller -w main.py ^
40
- --collect-all fastdeploy ^
41
- --name=SnipasteOCR ^
42
- --icon=assets/icon.ico ^
43
- --add-data="models;models" ^
44
- --add-data="assets;assets" ^
45
- --add-data="config.yml;." ^
46
- --hidden-import=pyqt6 ^
47
- --hidden-import=PyQt6.QtWidgets ^
48
- --hidden-import=PyQt6.QtGui ^
49
- --hidden-import=PyQt6.QtCore ^
50
- --hidden-import=PyQt6.sip ^
51
- --clean ^
41
+ uv run pyinstaller -w main.py `
42
+ --name=SnipasteOCR `
43
+ --collect-all fastdeploy `
44
+ --icon=assets/icon.ico `
45
+ --add-data="models;models" `
46
+ --add-data="assets;assets" `
47
+ --add-data="config.yml;." `
48
+ --hidden-import=pyqt6 `
49
+ --hidden-import=PyQt6.QtWidgets `
50
+ --hidden-import=PyQt6.QtGui `
51
+ --hidden-import=PyQt6.QtCore `
52
+ --hidden-import=PyQt6.sip `
53
+ --clean `
52
54
--noconfirm
53
-
54
- - name : Debug Dist Path
55
- run : |
56
- dir dist
55
+
56
+ if (-not (Test- Path "dist/SnipasteOCR/SnipasteOCR.exe")) {
57
+ throw "Build failed: SnipasteOCR.exe not found"
58
+ }
57
59
58
60
- name : Create Zip Archive
59
61
shell : pwsh
60
62
run : |
61
63
Compress-Archive -Path "dist/SnipasteOCR/*" -DestinationPath "SnipasteOCR.zip"
64
+ if (-not (Test-Path "SnipasteOCR.zip")) {
65
+ throw "Failed to create zip archive"
66
+ }
62
67
63
- - name : Verify Release Artifact
68
+ - name : Get Version
69
+ id : get_version
70
+ shell : pwsh
64
71
run : |
65
- if (!(Test-Path -Path "SnipasteOCR.zip")) {
66
- Write-Error "SnipasteOCR.zip not found!"
72
+ # 如果是tag push,使用tag名称
73
+ if ("${{ github.ref_type }}" -eq "tag") {
74
+ $version = "${{ github.ref_name }}"
75
+ } else {
76
+ # 否则使用分支名称-commit短hash
77
+ $branch = "${{ github.ref }}".Replace('refs/heads/', '')
78
+ $hash = "${{ github.sha }}".Substring(0, 7)
79
+ $version = "${branch}-${hash}"
67
80
}
81
+ echo "version=$version" >> $env:GITHUB_OUTPUT
82
+
83
+ - name : Delete existing release
84
+ uses : dev-drprasad/delete-tag-and-release@v1.0
85
+ with :
86
+ tag_name : ${{ steps.get_version.outputs.version }}
87
+ github_token : ${{ github.token }}
88
+ delete_release : true
89
+ continue-on-error : true
68
90
69
91
- name : Create Release
70
- if : startsWith(github.ref, 'refs/tags/')
71
92
uses : softprops/action-gh-release@v1
72
- env :
73
- GITHUB_TOKEN : ${{ secrets.TOKEN }}
74
93
with :
94
+ tag_name : ${{ steps.get_version.outputs.version }}
75
95
files : SnipasteOCR.zip
76
96
draft : false
77
- prerelease : false
78
- name : Release ${{ github.ref_name }}
97
+ prerelease : ${{ github.ref_type != 'tag' }}
98
+ name : Release ${{ steps.get_version.outputs.version }}
79
99
body : |
80
- SnipasteOCR Release ${{ github.ref_name }}
100
+ SnipasteOCR Release ${{ steps.get_version.outputs.version }}
81
101
82
102
### 下载说明
83
103
- 下载 SnipasteOCR.zip
84
- - 解压后运行 SnipasteOCR.exe
104
+ - 解压后运行 SnipasteOCR.exe
105
+
106
+ ### 构建信息
107
+ - 分支: ${{ github.ref_name }}
108
+ - 提交: ${{ github.sha }}
109
+ - 时间: ${{ github.event.head_commit.timestamp }}
0 commit comments