Skip to content

Package and Release EXE Files #16

Package and Release EXE Files

Package and Release EXE Files #16

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: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.tag_name }}
release_name: ${{ github.event.inputs.release_name }}
draft: false
prerelease: false
- name: Upload Release Assets
shell: pwsh
run: |
$releaseUrl = "${{ steps.create_release.outputs.upload_url }}"
Get-ChildItem -Recurse -Filter *.exe | ForEach-Object { gh release upload --clobber $releaseUrl $_.FullName }
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}