Files
OpenZen/.github/workflows/build-loader.yml
T
Shirona1337 4634789ae0 ci(loader): build-loader workflow + git revision stamp + UPX task
GitHub Actions (.github/workflows/build-loader.yml)
  - Runs on every push to master and on workflow_dispatch.
  - windows-2022 runner: setup-java 17 (Temurin), ilammy/msvc-dev-cmd
    for MSVC x64, clones + bootstraps microsoft/vcpkg into the
    workspace, installs UPX via choco, caches Gradle, then runs
    `gradlew --no-daemon clean dll upxCompress` with VCPKG_ROOT and
    OPENZEN_BUILD_REVISION exported.
  - vcpkg's x-gha binary cache is wired in via VCPKG_BINARY_SOURCES +
    ACTIONS_CACHE_URL / ACTIONS_RUNTIME_TOKEN, so the first run pays
    the Qt static-build cost (~30 min - 2 h) and every push after
    that pulls cached qtbase artifacts.
  - Publishes build/dist/OpenZenLoader.exe as the
    OpenZenLoader-<sha> artifact (30 day retention).

Git revision in window title
  - build.gradle: gitShortRevision() prefers OPENZEN_BUILD_REVISION
    from the environment (set by CI) and falls back to
    `git rev-parse --short=7 HEAD` for local builds.
  - configureNative passes -DOPENZEN_BUILD_REVISION=<sha> to CMake
    and logs the resolved value.
  - native/loader/CMakeLists.txt forwards it as a compile definition.
  - MainWindow.buildUi sets the window title to
    "OpenZen Loader (build abc1234)" when the macro is defined, plain
    "OpenZen Loader" otherwise.

UPX compression
  - New upxCompress Gradle task: locates upx on PATH, runs
    `upx --best --lzma` on build/dist/OpenZenLoader.exe and logs the
    before/after size. Skips with a warning (not an error) when upx
    is missing so local builds keep working without it. CI's
    `gradlew clean dll upxCompress` always shrinks the artifact.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 14:50:12 +08:00

105 lines
3.2 KiB
YAML

name: Build Loader
on:
push:
branches: [master]
workflow_dispatch: {}
# Needed for vcpkg's GitHub Actions binary cache (x-gha backend).
permissions:
contents: read
actions: write
jobs:
build:
runs-on: windows-2022
timeout-minutes: 180
env:
VCPKG_ROOT: ${{ github.workspace }}\vcpkg
# Push to / pull from the GitHub Actions binary cache so a fresh
# checkout reuses already-built Qt instead of rebuilding from
# source on every push.
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Resolve git revision
id: rev
shell: pwsh
run: |
$sha = git rev-parse --short=7 HEAD
"sha=$sha" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "Build revision: $sha"
- name: Setup JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup MSVC (x64)
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
# Expose ACTIONS_CACHE_URL / ACTIONS_RUNTIME_TOKEN to subsequent
# steps so vcpkg's x-gha cache backend works. These are set by
# the runner but only exposed to actions via the toolkit; we
# forward them manually for the shell-based vcpkg calls below.
- name: Export GitHub Actions cache tokens
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Clone & bootstrap vcpkg
shell: pwsh
run: |
git clone --depth=1 https://github.com/microsoft/vcpkg.git "$env:VCPKG_ROOT"
& "$env:VCPKG_ROOT\bootstrap-vcpkg.bat" -disableMetrics
Write-Host "vcpkg at $env:VCPKG_ROOT"
& "$env:VCPKG_ROOT\vcpkg.exe" version
- name: Install UPX
shell: pwsh
run: choco install upx -y --no-progress
- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Build (clean dll upxCompress)
shell: pwsh
env:
OPENZEN_BUILD_REVISION: ${{ steps.rev.outputs.sha }}
run: |
.\gradlew.bat --no-daemon clean dll upxCompress
- name: Show artifact info
shell: pwsh
run: |
$exe = "build\dist\OpenZenLoader.exe"
if (-not (Test-Path $exe)) { throw "missing $exe" }
$sz = (Get-Item $exe).Length
Write-Host ("OpenZenLoader.exe: {0:N0} bytes ({1:N2} MB)" -f $sz, ($sz/1MB))
- name: Upload OpenZenLoader.exe
uses: actions/upload-artifact@v4
with:
name: OpenZenLoader-${{ steps.rev.outputs.sha }}
path: build/dist/OpenZenLoader.exe
if-no-files-found: error
retention-days: 30