Skip to content

Build Windows Executable #170

Build Windows Executable

Build Windows Executable #170

name: Build Windows Executable
env:
AAA_VERSION: "1.3.3"
on:
workflow_dispatch:
# push:
# branches:
# - main
jobs:
build-windows:
runs-on: windows-latest
outputs:
upload_url_base64: ${{ steps.b64encode_upload_url.outputs.upload_url_base64 }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup MSBuild
uses: microsoft/[email protected] #using Microsoft's setup-msbuild action
- name: Install python packages
run: |
# Create the python-embedded directory if it doesn't exist
$pythonEmbeddedDir = ".\python-embedded"
If (-Not (Test-Path $pythonEmbeddedDir)) {
New-Item -ItemType Directory -Force -Path $pythonEmbeddedDir
}
# Download the embedded Python zip
curl https://www.python.org/ftp/python/3.12.1/python-3.12.1-embed-amd64.zip -o "python.zip"
# Extract the Python zip
Expand-Archive -Path "python.zip" -DestinationPath $pythonEmbeddedDir -Force
# Download pip.pyz
curl https://bootstrap.pypa.io/pip/pip.pyz -o "$pythonEmbeddedDir\pip.pyz"
# Install packages from requirements.txt using the embedded Python and pip.pyz
& "$pythonEmbeddedDir\python.exe" "$pythonEmbeddedDir\pip.pyz" install -r .\requirements.txt --target=".\Lib\site-packages\"
Remove-Item -Recurse -Force .\python-embedded
Move-Item -Path python.zip -Destination AzerothAuctionAssassin-windows\AzerothAuctionAssassin\Resources\python.zip -Force
shell: pwsh
- name: Zip python packages
run: |
Compress-Archive -Path .\Lib -DestinationPath Lib.zip
Move-Item -Path Lib.zip -Destination AzerothAuctionAssassin-windows\AzerothAuctionAssassin\Resources\Lib.zip -Force
Remove-Item -Recurse -Force .\Lib
- name: Zip Project Files
run: |
$DirToCompress = ".\"
$ZipFileResult = "..\app.zip"
$DirsToExclude = @("AzerothAuctionAssassin-windows", ".git", ".github", "__pycache__")
$FilesToExclude = @(".gitignore")
# Get all directories that are not in the exclude list and compress them
Get-ChildItem -Path $DirToCompress -Directory | Where-Object { $_.Name -notin $DirsToExclude } | Compress-Archive -DestinationPath $ZipFileResult -Update
# Get all Files that are not in the exclude list and compress them
Get-ChildItem -Path $DirToCompress -File | Where-Object { $_.Name -notin $FilesToExclude } | Compress-Archive -DestinationPath $ZipFileResult -Update
Move-Item -Path ..\app.zip -Destination AzerothAuctionAssassin-windows\AzerothAuctionAssassin\Resources\app.zip -Force
shell: pwsh
- name: update version number
run: |
echo $env:AAA_VERSION > AzerothAuctionAssassin-windows\AzerothAuctionAssassin\Resources\appVersion.txt
shell: pwsh
- name: Build EXE
run: |
msbuild AzerothAuctionAssassin-windows\AzerothAuctionAssassin.sln -restore -t:Publish /p:Configuration=Release /p:PublishProfile=".\AzerothAuctionAssassin\Properties\PublishProfiles\FolderProfile.pubxml"
- name: Decode Certificate
run: |
$cert_content = '${{ secrets.CERT_BASE64 }}'
$cert_bytes = [Convert]::FromBase64String($cert_content)
$cert_path = "certificate.pfx"
[IO.File]::WriteAllBytes($cert_path, $cert_bytes)
shell: pwsh
- name: Sign Executable
run: |
$cert_path = "certificate.pfx"
$password = "${{ secrets.CERT_PASSWORD }}"
$timestamp_url = "http://timestamp.digicert.com"
$executable_path = ".\AzerothAuctionAssassin-windows\AzerothAuctionAssassin\bin\Release\net8.0-windows\publish\win-x86\AzerothAuctionAssassin.exe"
$signtoolPath = Resolve-Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe" | Select-Object -Last 1
& $signtoolPath sign /f $cert_path /p $password /tr $timestamp_url /td sha256 /fd sha256 /v $executable_path
shell: pwsh
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "v${{env.AAA_VERSION}}"
release_name: "Release v${{env.AAA_VERSION}}"
draft: false
prerelease: false
- name: Encode and Save Upload URL as Base64
id: b64encode_upload_url
run: echo "::set-output name=upload_url_base64::$(echo -n '${{ steps.create_release.outputs.upload_url }}' | base64 --wrap=0)"
- name: Upload Executable to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: .\AzerothAuctionAssassin-windows\AzerothAuctionAssassin\bin\Release\net8.0-windows\publish\win-x86\AzerothAuctionAssassin.exe
asset_name: AzerothAuctionAssassin.exe
asset_content_type: application/octet-stream
build-mac:
needs: build-windows
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Install dependencies
run: pip install -r requirements.in
- name: Build macOS executable
run: |
python -m pip install pyinstaller
pyinstaller --onefile --add-data "AzerothAuctionAssassinData:./AzerothAuctionAssassinData" --add-data "utils:./utils" --add-data "icon.png:." --icon=icon.ico AzerothAuctionAssassin.py
chmod +x ./dist/AzerothAuctionAssassin
- name: Decode macOS Certificate
run: |
echo "${{ secrets.CERT_BASE64 }}" | base64 -d > certificate.p12
### broken probably needs a different cert
# - name: Sign macOS Executable
# run: |
# security create-keychain -p "" build.keychain
# security default-keychain -s build.keychain
# security unlock-keychain -p "" build.keychain
# security import certificate.p12 -k build.keychain -P ${{ secrets.CERT_PASSWORD }} -T /usr/bin/codesign
# codesign --deep --force --verify --verbose --sign "Developer ID Application" dist/AzerothAuctionAssassin
# - name: Upload macOS Executable to Release
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ needs.build-windows.steps.create_release.outputs.upload_url }}
# asset_path: ./dist/AzerothAuctionAssassin
# asset_name: AzerothAuctionAssassin-macOS
# asset_content_type: application/octet-stream
# Step to decode Base64 upload URL
- name: Decode Upload URL
run: |
echo "decoded_upload_url=$(echo ${{ needs.build-windows.outputs.upload_url_base64 }} | base64 --decode)" >> $GITHUB_ENV
- name: Upload macOS Executable to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.decoded_upload_url }}
asset_path: ./dist/AzerothAuctionAssassin
asset_name: AzerothAuctionAssassin-macOS
asset_content_type: application/octet-stream