Compile the project #32
This file contains hidden or 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: Compile the project | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'File version (Without spaces and brackets) (Eg: 1.1.0.0, 1.1.0.0-pre)' | |
| required: true | |
| tagname: | |
| description: 'TagName release (Without spaces and brackets) (Eg: 1.1.0.0-test)' | |
| required: true | |
| release_name: | |
| description: 'Release name' | |
| required: true | |
| permissions: | |
| contents: write | |
| jobs: | |
| Windows: | |
| runs-on: windows-latest | |
| steps: | |
| - name: 'Checkout Repo' | |
| uses: actions/checkout@v4 | |
| - name: 'Install Python' | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: 'Install dependencies' | |
| run: pip install -r requirements.txt | |
| - name: 'Build PyInstaller bootloader from source' | |
| # The shared prebuilt bootloader is a major cause of antivirus false | |
| # positives; a self-compiled one has a unique binary signature. | |
| # --gcc forces MinGW (preinstalled at C:\mingw64 on the runner) even | |
| # though MSVC is also present; a MinGW bootloader links against the | |
| # system msvcrt.dll instead of the redistributable Universal CRT. | |
| run: | | |
| git clone --depth 1 --branch v6.22.2 https://github.com/pyinstaller/pyinstaller.git | |
| # PyInstaller always bundles ucrtbase.dll/api-ms-win-* if it finds | |
| # them on the build machine (depend/dylib.py _win_includes). Windows | |
| # Server runners ship physical api-ms-* stubs in System32, so without | |
| # this patch they end up in the exe (~1 MB of DLLs that are redundant | |
| # on Windows 10+, the minimum supported OS per the README). | |
| $f = "pyinstaller\PyInstaller\depend\dylib.py" | |
| $c = Get-Content $f -Raw | |
| $c = $c.Replace("r'api-ms-win-core.*',", "# r'api-ms-win-core.*',") | |
| $c = $c.Replace("r'api-ms-win-crt.*',", "# r'api-ms-win-crt.*',") | |
| $c = $c.Replace("r'ucrtbase\.dll',", "# r'ucrtbase\.dll',") | |
| Set-Content $f $c | |
| Select-String -Path $f -Pattern "# r'(api-ms|ucrtbase)" | Select-Object -ExpandProperty Line | |
| cd pyinstaller/bootloader | |
| python ./waf all --gcc | |
| cd .. | |
| pip install . | |
| - name: 'Generate version info resource' | |
| run: | | |
| $ver = "${{ github.event.inputs.version }}" | |
| # Numeric core (e.g. "1.1.5.0" from "1.1.5.0-pre") feeds the DWORD | |
| # tuple, which must be all-numeric; the full version (suffix | |
| # included) goes into the FileVersion/ProductVersion strings. | |
| $core = ($ver -split '-')[0] | |
| $tuple = ($core -split '\.') -join ', ' | |
| $content = Get-Content version_info.txt -Raw | |
| $content = $content -replace '\d+\.\d+\.\d+\.\d+', $core | |
| $content = $content -replace '\(\d+, \d+, \d+, \d+\)', "($tuple)" | |
| $content = $content -replace "'FileVersion', '[^']*'", "'FileVersion', '$ver'" | |
| $content = $content -replace "'ProductVersion', '[^']*'", "'ProductVersion', '$ver'" | |
| Set-Content version_info.txt $content | |
| - name: 'Generate version.py from version input' | |
| run: | | |
| $ver = "${{ github.event.inputs.version }}" | |
| $core = ($ver -split '-')[0] | |
| Set-Content version.py "__version__ = `"$core`"" | |
| Get-Content version.py | |
| - name: 'Compile (based on Python x64)' | |
| run: | | |
| pyinstaller --onefile --clean --noconsole --version-file version_info.txt -n SRR --add-data "assets/icon.png;assets" main.py | |
| Move-Item -Path .\dist\SRR.exe -Destination ".\SRR_v${{ github.event.inputs.version }}_win64.exe" | |
| - name: 'SHA256 checksum' | |
| run: | | |
| $exe = "SRR_v${{ github.event.inputs.version }}_win64.exe" | |
| $hash = (Get-FileHash -Algorithm SHA256 $exe).Hash.ToLower() | |
| "$hash $exe" | Set-Content -NoNewline "$exe.sha256" | |
| Get-Content "$exe.sha256" | |
| - name: Release | |
| if: github.ref == 'refs/heads/main' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| SRR_v${{ github.event.inputs.version }}_win64.exe | |
| SRR_v${{ github.event.inputs.version }}_win64.exe.sha256 | |
| name: v${{ github.event.inputs.release_name }} | |
| tag_name: v${{ github.event.inputs.tagname }} | |
| draft: false | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |