Package and Release EXE Files #18
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: Package and Release EXE Files | |
on: | |
workflow_dispatch: | |
inputs: | |
tag_name: | |
description: 'Tag name for the release' | |
required: true | |
default: 'v1.0.0' | |
release_name: | |
description: 'Release name' | |
required: true | |
default: 'Release 1.0.0' | |
jobs: | |
build: | |
runs-on: windows-2019 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
ref: main | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install PyInstaller | |
run: pip install pyinstaller | |
- name: Install Requirements | |
shell: pwsh | |
run: Get-ChildItem -Directory | ForEach-Object { $requirementsPath = "$($_.FullName)\requirements.txt"; if (Test-Path $requirementsPath) { try { pip install -r $requirementsPath } catch { Write-Error "Failed to install packages from $requirementsPath" } } } | |
- name: Package Python scripts to EXE | |
shell: pwsh | |
run: Get-ChildItem -Directory | ForEach-Object { $latestScript = Get-ChildItem -Path "$($_.FullName)" -Filter *.py | Sort-Object LastWriteTime -Descending | Select-Object -First 1; if ($latestScript) { $folderName = [System.IO.Path]::GetFileName($_.FullName); $scriptName = [System.IO.Path]::GetFileNameWithoutExtension($latestScript.Name); $exeName = "$folderName - $scriptName.exe"; pyinstaller --onefile --distpath "$($_.FullName)\dist" --workpath "$($_.FullName)\build" --specpath "$($_.FullName)\spec" --name "$exeName" "$($latestScript.FullName)" } } | |
- name: Install GitHub CLI | |
run: | | |
Invoke-WebRequest -Uri https://github.com/cli/cli/releases/download/v2.20.2/gh_2.20.2_windows_amd64.msi -OutFile gh-cli.msi; Start-Process msiexec.exe -Wait -ArgumentList '/i gh-cli.msi /quiet'; Remove-Item gh-cli.msi -Force | |
- name: Create Release and Upload Assets | |
shell: pwsh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh auth login --with-token <<< $env:GITHUB_TOKEN; gh release create ${{ github.event.inputs.tag_name }} --title "${{ github.event.inputs.release_name }}" --notes "Release ${{ github.event.inputs.release_name }}"; Get-ChildItem -Recurse -Filter *.exe | ForEach-Object { gh release upload ${{ github.event.inputs.tag_name }} $_.FullName --clobber } |