1
1
mirror of https://github.com/KenanZhu/AutoLibrary.git synced 2026-06-17 23:13:03 +08:00

ci(workflows): 重构 CI/CD 工作流执行配置

This commit is contained in:
2026-01-03 14:33:49 +08:00
parent dd48c8a01c
commit 94ce3433a3
4 changed files with 194 additions and 94 deletions
@@ -1,48 +1,41 @@
name: Build and Release
name: Build
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_call:
inputs:
version:
description: 'Version number'
required: true
type: string
tag_name:
description: 'Tag name'
required: true
type: string
outputs:
version:
description: 'The version number'
value: ${{ jobs.build-windows.outputs.version }}
tag_name:
description: 'The tag name'
value: ${{ jobs.build-windows.outputs.tag_name }}
jobs:
update-version-info:
uses: ./.github/workflows/update-version-info.yml
permissions:
contents: write
with:
tag_name: ${{ github.ref_name }}
ref: ${{ github.ref }}
commit-and-move-tag:
needs: update-version-info
if: ${{ needs.update-version-info.outputs.has_changes == 'true' }}
uses: ./.github/workflows/commit-and-move-tag.yml
permissions:
contents: write
with:
tag_name: ${{ needs.update-version-info.outputs.tag_name }}
version: ${{ needs.update-version-info.outputs.version }}
file_path: src/gui/ALVersionInfo.py
build-and-release:
build-windows:
runs-on: windows-latest
needs: [update-version-info, commit-and-move-tag]
if: always() && needs.update-version-info.result == 'success'
permissions:
contents: write
outputs:
version: ${{ steps.get_version.outputs.VERSION }}
tag_name: ${{ steps.get_version.outputs.TAG_NAME }}
steps:
- name: Checkout code with updated version info
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main
- name: Get version info from previous job
id: get_tag
- name: Get version info
id: get_version
run: |
$tagName = "${{ needs.update-version-info.outputs.tag_name }}"
$version = "${{ needs.update-version-info.outputs.version }}"
$version = "${{ inputs.version }}"
$tagName = "${{ inputs.tag_name }}"
echo "TAG_NAME=$tagName" >> $env:GITHUB_OUTPUT
echo "VERSION=$version" >> $env:GITHUB_OUTPUT
@@ -50,17 +43,17 @@ jobs:
Write-Host "✓ Version: $version"
shell: pwsh
- name: Verify ALVersionInfo.py was updated
- name: Verify 'ALVersionInfo.py' was updated
run: |
$versionInfoFile = "src/gui/ALVersionInfo.py"
Write-Host "Verifying $versionInfoFile content:"
Write-Host "================================"
Write-Host "=================================="
Get-Content $versionInfoFile | Write-Host
Write-Host "================================"
Write-Host "=================================="
shell: pwsh
- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@v4
with:
python-version: '3.13'
@@ -69,7 +62,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirement.txt
- name: Fix ddddocr compatibility and copy model files
- name: Solve ddddocr compatibility and copy model files
run: |
$ddddocrPath = python -c "import ddddocr, os; print(os.path.dirname(ddddocr.__file__))"
Write-Host "ddddocr package location: $ddddocrPath"
@@ -121,9 +114,9 @@ jobs:
./compile_rc.bat
shell: cmd
- name: Generate Main.spec dynamically
- name: Generate 'Main.spec'
run: |
$version = "${{ steps.get_tag.outputs.VERSION }}"
$version = "${{ steps.get_version.outputs.VERSION }}"
$exeName = "AutoLibrary-$version"
Write-Host "Generating Main.spec for version: $version"
@@ -173,28 +166,29 @@ jobs:
" icon=['src\\gui\\icons\\AutoLibrary_32x32.ico'],"
")"
)
$specLines | Out-File -FilePath "Main.spec" -Encoding UTF8
Write-Host "✓ Main.spec generated successfully"
Write-Host "`n=== Generated Main.spec ==="
Write-Host "`nGenerated Main.spec ============"
Get-Content "Main.spec" | Write-Host
Write-Host "==========================`n"
Write-Host "==================================`n"
shell: pwsh
- name: Build with PyInstaller
run: |
pyinstaller Main.spec
- name: Create Release Archive
- name: Zip windows release
id: zip_release
run: |
$tagName = "${{ steps.get_tag.outputs.TAG_NAME }}"
$version = "${{ steps.get_tag.outputs.VERSION }}"
$tagName = "${{ steps.get_version.outputs.TAG_NAME }}"
$version = "${{ steps.get_version.outputs.VERSION }}"
$exeName = "AutoLibrary-$version.exe"
$zipName = "AutoLibrary.$tagName-windows-x86_64.zip"
Write-Host "Looking for executable: dist/$exeName"
echo "ZIP_PATH=$zipName" >> $env:GITHUB_OUTPUT
Write-Host "Looking for executable: dist/$exeName"
if (Test-Path "dist/$exeName") {
Compress-Archive -Path "dist/$exeName" -DestinationPath $zipName
Write-Host "✓ Created release archive: $zipName"
@@ -206,31 +200,9 @@ jobs:
}
shell: pwsh
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
tag_name: ${{ steps.get_tag.outputs.TAG_NAME }}
name: AutoLibrary ${{ steps.get_tag.outputs.TAG_NAME }}
files: |
AutoLibrary.${{ steps.get_tag.outputs.TAG_NAME }}-windows-x86_64.zip
draft: false
prerelease: false
generate_release_notes: true
body: |
### 下载获取
- **Windows x86_64**: `AutoLibrary.${{ steps.get_tag.outputs.TAG_NAME }}-windows-x86_64.zip`
### 如何使用
1. 下载 `AutoLibrary.${{ steps.get_tag.outputs.TAG_NAME }}-windows-x86_64.zip` 文件
2. 解压到任意目录
3. 下载对应浏览器的驱动文件
4. 运行 `AutoLibrary-${{ steps.get_tag.outputs.VERSION }}.exe` (首次运行会初始化配置文件)
5. 按照提示操作即可
更多详情请访问 [AutoLibrary 网站](http://autolibrary.cv) 和查看 [帮助手册](https://autolibrary.cv/docs/manual_lists.html)
---
**完整更新日志见下方自动生成的 Release Notes**
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: AutoLibrary.${{ steps.get_version.outputs.TAG_NAME }}-windows-x86_64
path: |
${{ steps.zip_release.outputs.ZIP_PATH }}
@@ -1,4 +1,4 @@
name: Commit and Move Tag
name: Commit Release
on:
workflow_call:
@@ -18,10 +18,10 @@ on:
outputs:
new_commit_sha:
description: 'The new commit SHA after moving the tag'
value: ${{ jobs.commit-and-move-tag.outputs.new_commit_sha }}
value: ${{ jobs.commit-release.outputs.new_commit_sha }}
jobs:
commit-and-move-tag:
commit-release:
runs-on: ubuntu-latest
permissions:
contents: write
@@ -52,9 +52,9 @@ jobs:
echo "✓ File replaced: $FILE_PATH"
echo ""
echo "=== Updated file content ==="
cat "$FILE_PATH"
echo "============================"
echo "Updated file content ==================="
cat "$FILE_PATH"
echo "========================================"
- name: Commit changes
id: commit_changes
@@ -85,7 +85,7 @@ jobs:
git push origin HEAD:${MAIN_BRANCH}
echo "✓ Changes pushed to ${MAIN_BRANCH}"
- name: Move tag to new commit
- name: Move tag to new release commit
run: |
TAG_NAME="${{ inputs.tag_name }}"
+129
View File
@@ -0,0 +1,129 @@
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
#
# Start :
# virtual job that indacates the start of the release process
#
start:
runs-on: ubuntu-latest
steps:
- name: Start release
run: |
echo "✓ Starting release"
#
# Update version :
# this job updates the version in the file 'ALVersionInfo.py'
#
update-version:
needs:
- start
uses: ./.github/workflows/update-version.yml
permissions:
contents: write
with:
tag_name: ${{ github.ref_name }}
ref: ${{ github.ref }}
#
# Commit release :
# this job commits the updated version file and move the release
# tag to this new commit
#
commit-release:
needs:
- update-version
if: ${{ needs.update-version.outputs.has_changes == 'true' }}
uses: ./.github/workflows/commit-release.yml
permissions:
contents: write
with:
tag_name: ${{ needs.update-version.outputs.tag_name }}
version: ${{ needs.update-version.outputs.version }}
file_path: src/gui/ALVersionInfo.py
#
# Build :
# this job builds the application and archives them
build:
needs:
- update-version
- commit-release
if: always() && needs.update-version.result == 'success' && needs.commit-release.result == 'success'
uses: ./.github/workflows/build.yml
permissions:
contents: write
with:
version: ${{ needs.update-version.outputs.version }}
tag_name: ${{ needs.update-version.outputs.tag_name }}
#
# Release :
# this job creates a GitHub release and uploads the archive files
release:
runs-on: ubuntu-latest
needs:
- build
if: always() && needs.build.result == 'success'
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: AutoLibrary.${{ needs.build.outputs.tag_name }}-windows-x86_64
path: artifacts/
- name: Create release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.build.outputs.tag_name }}
name: AutoLibrary ${{ needs.build.outputs.tag_name }}
files: |
artifacts/AutoLibrary.${{ needs.build.outputs.tag_name }}-windows-x86_64.zip
draft: false
prerelease: false
generate_release_notes: true
body: |
### 下载获取
- **Windows x86_64**: `AutoLibrary.${{ needs.build.outputs.tag_name }}-windows-x86_64.zip`
### 如何使用
1. 下载 `AutoLibrary.${{ needs.build.outputs.tag_name }}-windows-x86_64.zip` 文件
2. 解压到任意目录
3. 下载对应浏览器的驱动文件
4. 运行 `AutoLibrary-${{ needs.build.outputs.version }}.exe` (首次运行会初始化配置文件)
5. 按照提示操作即可
更多详情请访问 [AutoLibrary 网站](http://autolibrary.cv) 和查看 [帮助手册](https://autolibrary.cv/docs/manual_lists.html)
---
**完整更新日志见下方自动生成的 Release Notes**
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# End :
# virtual job that indacates the end of the release process
#
end:
needs:
- release
runs-on: ubuntu-latest
steps:
- name: End release
run: |
echo "✓ Ending release"
@@ -1,10 +1,10 @@
name: Update Version Info
name: Update Version
on:
workflow_call:
inputs:
tag_name:
description: 'Tag name (e.g., v1.0.0)'
description: 'Tag name'
required: true
type: string
ref:
@@ -14,16 +14,16 @@ on:
outputs:
tag_name:
description: 'The tag name'
value: ${{ jobs.update-version-info.outputs.tag_name }}
value: ${{ jobs.update-version.outputs.tag_name }}
version:
description: 'The version number'
value: ${{ jobs.update-version-info.outputs.version }}
value: ${{ jobs.update-version.outputs.version }}
has_changes:
description: 'Whether ALVersionInfo.py was modified'
value: ${{ jobs.update-version-info.outputs.has_changes }}
value: ${{ jobs.update-version.outputs.has_changes }}
jobs:
update-version-info:
update-version:
runs-on: ubuntu-latest
permissions:
contents: write
@@ -69,14 +69,13 @@ jobs:
BUILD_DATE=$(date -u '+%Y-%m-%d %H:%M:%S UTC')
echo "Updating $APP_INFO_FILE with build information..."
{
echo '# -*- coding: utf-8 -*-'
echo ''
echo '"""'
echo ' The contents of this file will automatically be updated by the'
echo ' workflow process. Do not edit manually.'
echo ' '
echo ''
echo ' This file is auto-generated during the workflow process.'
echo " Last updated: ${BUILD_DATE}"
echo '"""'
@@ -91,9 +90,9 @@ jobs:
echo "✓ ALVersionInfo.py updated successfully"
echo ""
echo "=== Updated ALVersionInfo.py ==="
cat "$APP_INFO_FILE"
echo "=========================="
echo "Updated ALVersionInfo.py ==============="
cat "$APP_INFO_FILE"
echo "========================================"
- name: Check if ALVersionInfo.py was modified
id: check_changes
@@ -112,4 +111,4 @@ jobs:
with:
name: updated-version-info
path: src/gui/ALVersionInfo.py
retention-days: 1
retention-days: 1