Merge pull request #6 from formero009/v2.0.0 #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build SnipasteOCR | |
on: | |
push: | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Cache UV packages | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~\AppData\Local\uv | |
~\.cache\uv | |
key: ${{ runner.os }}-uv-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-uv- | |
- name: Install dependencies | |
shell: pwsh | |
run: | | |
pip install uv | |
uv sync | |
- name: Build Release | |
shell: pwsh | |
run: | | |
uv run pyinstaller -w main.py ` | |
--name=SnipasteOCR ` | |
--collect-all fastdeploy ` | |
--icon=assets/icon.ico ` | |
--add-data="models;models" ` | |
--add-data="assets;assets" ` | |
--add-data="config.yml;." ` | |
--hidden-import=pyqt6 ` | |
--hidden-import=PyQt6.QtWidgets ` | |
--hidden-import=PyQt6.QtGui ` | |
--hidden-import=PyQt6.QtCore ` | |
--hidden-import=PyQt6.sip ` | |
--clean ` | |
--noconfirm | |
if (-not (Test-Path "dist/SnipasteOCR/SnipasteOCR.exe")) { | |
throw "Build failed: SnipasteOCR.exe not found" | |
} | |
- name: Create Zip Archive | |
shell: pwsh | |
run: | | |
Compress-Archive -Path "dist/SnipasteOCR/*" -DestinationPath "SnipasteOCR.zip" | |
if (-not (Test-Path "SnipasteOCR.zip")) { | |
throw "Failed to create zip archive" | |
} | |
- name: Get Version | |
id: get_version | |
shell: pwsh | |
run: | | |
# 如果是tag push,使用tag名称 | |
if ("${{ github.ref_type }}" -eq "tag") { | |
$version = "${{ github.ref_name }}" | |
} else { | |
# 否则使用分支名称-commit短hash | |
$branch = "${{ github.ref }}".Replace('refs/heads/', '') | |
$hash = "${{ github.sha }}".Substring(0, 7) | |
$version = "${branch}-${hash}" | |
} | |
echo "version=$version" >> $env:GITHUB_OUTPUT | |
- name: Delete existing release | |
uses: dev-drprasad/delete-tag-and-release@v1.0 | |
with: | |
tag_name: ${{ steps.get_version.outputs.version }} | |
github_token: ${{ github.token }} | |
delete_release: true | |
continue-on-error: true | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ steps.get_version.outputs.version }} | |
files: SnipasteOCR.zip | |
draft: false | |
prerelease: ${{ github.ref_type != 'tag' }} | |
name: Release ${{ steps.get_version.outputs.version }} | |
body: | | |
SnipasteOCR Release ${{ steps.get_version.outputs.version }} | |
### 下载说明 | |
- 下载 SnipasteOCR.zip | |
- 解压后运行 SnipasteOCR.exe | |
### 构建信息 | |
- 分支: ${{ github.ref_name }} | |
- 提交: ${{ github.sha }} | |
- 时间: ${{ github.event.head_commit.timestamp }} |