75 lines
2.3 KiB
YAML
75 lines
2.3 KiB
YAML
name: Build Release EXE
|
|
|
|
on:
|
|
release:
|
|
types: [published]
|
|
|
|
jobs:
|
|
build-windows-exe:
|
|
runs-on: windows-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
|
|
- name: Install build dependencies
|
|
shell: pwsh
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
python -m pip install -e ".[dev]"
|
|
|
|
- name: Build TraderAI.exe
|
|
shell: pwsh
|
|
run: |
|
|
pyinstaller TraderAI.spec --noconfirm
|
|
if (-not (Test-Path -LiteralPath "dist\TraderAI.exe")) {
|
|
throw "dist\TraderAI.exe was not created."
|
|
}
|
|
|
|
- name: Attach EXE to release
|
|
shell: pwsh
|
|
env:
|
|
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
$ErrorActionPreference = "Stop"
|
|
$event = Get-Content -LiteralPath $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json
|
|
$releaseId = $event.release.id
|
|
if (-not $releaseId) {
|
|
throw "Release id was not present in the release event payload."
|
|
}
|
|
|
|
$token = $env:RELEASE_TOKEN
|
|
if ([string]::IsNullOrWhiteSpace($token)) {
|
|
$token = $env:GITEA_TOKEN
|
|
}
|
|
if ([string]::IsNullOrWhiteSpace($token)) {
|
|
throw "Set a RELEASE_TOKEN secret or enable the built-in GITHUB_TOKEN for Actions."
|
|
}
|
|
|
|
$apiUrl = $env:GITHUB_API_URL
|
|
if ([string]::IsNullOrWhiteSpace($apiUrl)) {
|
|
$apiUrl = "$($env:GITHUB_SERVER_URL.TrimEnd('/'))/api/v1"
|
|
}
|
|
|
|
$repoParts = $env:GITHUB_REPOSITORY.Split("/", 2)
|
|
if ($repoParts.Length -ne 2) {
|
|
throw "GITHUB_REPOSITORY must look like owner/repo. Value: $env:GITHUB_REPOSITORY"
|
|
}
|
|
|
|
$owner = [uri]::EscapeDataString($repoParts[0])
|
|
$repo = [uri]::EscapeDataString($repoParts[1])
|
|
$assetPath = Resolve-Path -LiteralPath "dist\TraderAI.exe"
|
|
$uploadUrl = "$apiUrl/repos/$owner/$repo/releases/$releaseId/assets?name=TraderAI.exe"
|
|
|
|
Invoke-RestMethod `
|
|
-Method Post `
|
|
-Uri $uploadUrl `
|
|
-Headers @{ Authorization = "token $token" } `
|
|
-Form @{ attachment = Get-Item -LiteralPath $assetPath }
|