name: Build # This workflow compiles the application for Windows platform using PyInstaller, and # archives the built artifacts as 'AutoLibrary.-windows-x86_64.zip'. # # It is triggered when called by the release workflow. on: 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 }} # # Build Windows # jobs: build-windows: runs-on: windows-latest outputs: version: ${{ steps.get_version.outputs.VERSION }} tag_name: ${{ steps.get_version.outputs.TAG_NAME }} steps: - name: Checkout code uses: actions/checkout@v4 with: ref: main # here we download the build version of ALVersionInfo.py from artifacts # and replace the committed version - name: Download build version of ALVersionInfo.py uses: actions/download-artifact@v4 with: name: updated-version-info-for-build path: src/gui/ - name: Get version info id: get_version run: | $version = "${{ inputs.version }}" $tagName = "${{ inputs.tag_name }}" echo "TAG_NAME=$tagName" >> $env:GITHUB_OUTPUT echo "VERSION=$version" >> $env:GITHUB_OUTPUT Write-Host "✓ Tag: $tagName" Write-Host "✓ Version: $version" shell: pwsh - name: Verify 'ALVersionInfo.py' was updated run: | $versionInfoFile = "src/gui/ALVersionInfo.py" Write-Host "Verifying $versionInfoFile content:" Write-Host "==================================" Get-Content $versionInfoFile | Write-Host Write-Host "==================================" shell: pwsh - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.13' - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirement.txt - 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" $initFile = Join-Path $ddddocrPath "__init__.py" if (Test-Path $initFile) { Write-Host "Fixing ddddocr compatibility in: $initFile" (Get-Content $initFile) -replace 'Image\.ANTIALIAS', 'Image.Resampling.LANCZOS' | Set-Content $initFile Write-Host "✓ Fixed: Image.ANTIALIAS -> Image.Resampling.LANCZOS" } else { Write-Error "✗ ddddocr __init__.py not found" exit 1 } if (-not (Test-Path "models")) { New-Item -ItemType Directory -Path "models" | Out-Null Write-Host "✓ Created models directory" } $onnxSource = Join-Path $ddddocrPath "common.onnx" $onnxDest = "models/common.onnx" if (Test-Path $onnxSource) { Copy-Item $onnxSource $onnxDest -Force Write-Host "✓ Copied ONNX model from: $onnxSource" Write-Host "✓ ONNX model copied to: $onnxDest" } else { Write-Error "✗ ONNX model not found in ddddocr package: $onnxSource" exit 1 } if (Test-Path $onnxDest) { $fileSize = (Get-Item $onnxDest).Length / 1MB Write-Host "✓ Model file verified: $onnxDest (Size: $([math]::Round($fileSize, 2)) MB)" } else { Write-Error "✗ Failed to copy model file" exit 1 } shell: pwsh - name: Compile Qt Resource files run: | cd batchs ./compile_rc.bat shell: cmd - name: Compile Qt UI files run: | cd batchs ./compile_ui.bat shell: cmd - name: Generate 'Main.spec' run: | $version = "${{ steps.get_version.outputs.VERSION }}" $exeName = "AutoLibrary-$version" Write-Host "Generating Main.spec for version: $version" Write-Host "Executable name: $exeName" $specLines = @( "# -*- mode: python ; coding: utf-8 -*-" "" "" "a = Analysis(" " ['src\\Main.py']," " pathex=[]," " binaries=[]," " datas=[" " ('models\\common.onnx', 'ddddocr')," " ('src\\gui\\resources\\icons\\AutoLibrary_32x32.ico', 'gui\\resources\\icons')," " ]," " hiddenimports=[]," " hookspath=[]," " hooksconfig={}," " runtime_hooks=[]," " excludes=[]," " noarchive=False," " optimize=0," ")" "pyz = PYZ(a.pure)" "" "exe = EXE(" " pyz," " a.scripts," " a.binaries," " a.datas," " []," " name='$exeName'," " debug=False," " bootloader_ignore_signals=False," " strip=False," " upx=True," " upx_exclude=[]," " runtime_tmpdir=None," " console=False," " disable_windowed_traceback=False," " argv_emulation=False," " target_arch=None," " codesign_identity=None," " entitlements_file=None," " icon=['src\\gui\\resources\\icons\\AutoLibrary_32x32.ico']," ")" ) $specLines | Out-File -FilePath "Main.spec" -Encoding UTF8 Write-Host "✓ Main.spec generated successfully" Write-Host "`nGenerated Main.spec ============" Get-Content "Main.spec" | Write-Host Write-Host "==================================`n" shell: pwsh - name: Build with PyInstaller run: | pyinstaller Main.spec - name: Zip windows release id: zip_release run: | $tagName = "${{ steps.get_version.outputs.TAG_NAME }}" $version = "${{ steps.get_version.outputs.VERSION }}" $exeName = "AutoLibrary-$version.exe" $zipName = "AutoLibrary.$tagName-windows-x86_64.zip" 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" } else { Write-Error "✗ Executable not found: dist/$exeName" Write-Host "Files in dist directory:" Get-ChildItem "dist" | ForEach-Object { Write-Host " - $($_.Name)" } exit 1 } shell: pwsh - name: Archive artifacts uses: actions/upload-artifact@v4 with: name: AutoLibrary.${{ steps.get_version.outputs.TAG_NAME }}-windows-x86_64 path: | ${{ steps.zip_release.outputs.ZIP_PATH }}