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: tag_name: description: 'Tag name' required: false type: string version: description: 'Version number' required: false type: string is_test: description: 'Whether this is a test build (not a release)' required: false type: string default: 'true' # # Build Windows # jobs: build-windows: runs-on: windows-latest outputs: tag_name: ${{ steps.get_version.outputs.TAG_NAME }} version: ${{ steps.get_version.outputs.VERSION }} steps: - name: Checkout code uses: actions/checkout@v6 with: ref: ${{ github.ref }} # 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@v6 with: name: updated-version-info-for-build path: src/gui/ - name: Get version info id: get_version run: | $isTest = "${{ inputs.is_test }}" if ($isTest -eq "true") { $version = "test" $tagName = "test" Write-Host "✓ Mode: Test Build" } else { $version = "${{ inputs.version }}" $tagName = "${{ inputs.tag_name }}" if ([string]::IsNullOrEmpty($version)) { $version = "test" $tagName = "test" Write-Host "✓ Mode: Independent Build (No inputs provided)" } } Write-Host "✓ Tag: $tagName" Write-Host "✓ Version: $version" "VERSION=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append "TAG_NAME=$tagName" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append 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@v6 with: python-version: '3.13' - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirement.txt - 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," " name='AutoLibrary'," " 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']," ")" "" "coll = COLLECT(" " exe," " a.binaries," " a.datas," " strip=False," " upx=True," " upx_exclude=[]," " name='$exeName'" ")" ) $specLines | Out-File -FilePath "Main.spec" -Encoding UTF8 Write-Host "✓ Main.spec (non-single file) 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 }}" $distDir = "dist/AutoLibrary-$version" $zipName = "AutoLibrary.$tagName-windows-x86_64.zip" echo "ZIP_NAME=$zipName" >> $env:GITHUB_OUTPUT Write-Host "Looking for distribution directory: $distDir" if (Test-Path $distDir) { Compress-Archive -Path "$distDir/*" -DestinationPath $zipName Write-Host "✓ Created release archive (directory mode): $zipName" } else { Write-Error "✗ Distribution directory not found: $distDir" 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@v6 with: name: AutoLibrary.${{ steps.get_version.outputs.TAG_NAME }}-windows-x86_64 path: | ${{ steps.zip_release.outputs.ZIP_NAME }} retention-days: ${{ github.event_name != 'workflow_call' && 7 || 90 }} - name: Upload build summary if: ${{ github.event_name != 'workflow_call' }} run: | Write-Host "## Build Summary" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 Write-Host "" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append Write-Host "✓ Build test completed successfully!" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append Write-Host "- Version: ${{ steps.get_version.outputs.VERSION }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append Write-Host "- Tag: ${{ steps.get_version.outputs.TAG_NAME }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append Write-Host "- Event: ${{ github.event_name }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append Write-Host "- Ref: ${{ github.ref }}" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append shell: pwsh