Package and Release EXE Files #22
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: Authenticate GitHub CLI | |
shell: pwsh | |
run: | | |
$env:GITHUB_TOKEN | Out-File -FilePath gh_token.txt -NoNewline; | |
gh auth login --with-token < gh_token.txt; | |
Remove-Item gh_token.txt | |
- name: Create Release and Upload Assets | |
shell: pwsh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
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 } |