Skip to content

Commit e344de6

Browse files
authored
Merge pull request #5 from formero009/v2.0.0
V2.0.0
2 parents c057cd4 + 19ba5b7 commit e344de6

File tree

1 file changed

+58
-33
lines changed

1 file changed

+58
-33
lines changed

.github/workflows/build.yml

+58-33
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Build SnipasteOCR
22

33
on:
44
push:
5-
tags:
6-
- 'v*'
75
workflow_dispatch:
86

97
permissions:
@@ -21,64 +19,91 @@ jobs:
2119
with:
2220
python-version: '3.10'
2321

24-
- name: Cache Python packages
22+
- name: Cache UV packages
2523
uses: actions/cache@v4
2624
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') }}
2929
restore-keys: |
30-
${{ runner.os }}-pip-
30+
${{ runner.os }}-uv-
3131
3232
- name: Install dependencies
33+
shell: pwsh
3334
run: |
3435
pip install uv
3536
uv sync
3637
3738
- name: Build Release
39+
shell: pwsh
3840
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 `
5254
--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+
}
5759
5860
- name: Create Zip Archive
5961
shell: pwsh
6062
run: |
6163
Compress-Archive -Path "dist/SnipasteOCR/*" -DestinationPath "SnipasteOCR.zip"
64+
if (-not (Test-Path "SnipasteOCR.zip")) {
65+
throw "Failed to create zip archive"
66+
}
6267
63-
- name: Verify Release Artifact
68+
- name: Get Version
69+
id: get_version
70+
shell: pwsh
6471
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}"
6780
}
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
6890

6991
- name: Create Release
70-
if: startsWith(github.ref, 'refs/tags/')
7192
uses: softprops/action-gh-release@v1
72-
env:
73-
GITHUB_TOKEN: ${{ secrets.TOKEN }}
7493
with:
94+
tag_name: ${{ steps.get_version.outputs.version }}
7595
files: SnipasteOCR.zip
7696
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 }}
7999
body: |
80-
SnipasteOCR Release ${{ github.ref_name }}
100+
SnipasteOCR Release ${{ steps.get_version.outputs.version }}
81101
82102
### 下载说明
83103
- 下载 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

Comments
 (0)