Package and Release EXE Files #8
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) { | |
$scriptName = [System.IO.Path]::GetFileNameWithoutExtension($latestScript.Name) | |
$exeName = "$scriptName.exe" | |
pyinstaller --onefile --distpath "$($_.FullName)\dist" --workpath "$($_.FullName)\build" --specpath "$($_.FullName)\spec" "$($latestScript.FullName)" | |
} | |
} | |
- name: Get current date in UTC+8 | |
id: date | |
shell: pwsh | |
run: | | |
$currentDate = (Get-Date).ToUniversalTime().AddHours(8).ToString("yy.MM.dd") | |
echo "CURRENT_DATE=$currentDate" >> $GITHUB_ENV | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: "v${{ env.CURRENT_DATE }}" | |
release_name: "Release ${{ env.CURRENT_DATE }}" | |
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 $releaseUrl $_.FullName | |
} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |