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>
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
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
|
||||
+66
-2
@@ -344,6 +344,24 @@ def vcpkgMissingMessage =
|
||||
'Then re-run ./gradlew dll - the first run will build static Qt\n' +
|
||||
'(can take 30 min to 2 h); subsequent builds are fast.'
|
||||
|
||||
ext.gitShortRevision = {
|
||||
// CI passes the resolved sha in OPENZEN_BUILD_REVISION so we don't have
|
||||
// to assume git is on PATH inside the runner image.
|
||||
def envRev = System.getenv('OPENZEN_BUILD_REVISION')
|
||||
if (envRev && !envRev.allWhitespace) return envRev.trim().take(7)
|
||||
try {
|
||||
def p = ['git', 'rev-parse', '--short=7', 'HEAD'].execute(null, project.rootDir)
|
||||
def out = new StringBuilder()
|
||||
p.consumeProcessOutput(out, new StringBuilder())
|
||||
p.waitForOrKill(2000)
|
||||
if (p.exitValue() == 0) {
|
||||
def v = out.toString().trim()
|
||||
if (v) return v
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
return null
|
||||
}
|
||||
|
||||
tasks.register('stageNativeJar', Copy) {
|
||||
group = 'openzen'
|
||||
description = 'Stage the freshly built mod jar at native/zen.jar so the DLL ' +
|
||||
@@ -365,12 +383,16 @@ tasks.register('configureNative', Exec) {
|
||||
if (!cmake) throw new GradleException(cmakeMissingMessage)
|
||||
def vcpkg = findVcpkg()
|
||||
if (!vcpkg) throw new GradleException(vcpkgMissingMessage)
|
||||
def rev = gitShortRevision()
|
||||
logger.lifecycle("Using CMake : ${cmake}")
|
||||
logger.lifecycle("Using vcpkg : ${vcpkg}")
|
||||
commandLine cmake, '-S', '.', '-B', 'build', '-A', 'x64',
|
||||
logger.lifecycle("Build rev : ${rev ?: '(unknown)'}")
|
||||
def args = [cmake, '-S', '.', '-B', 'build', '-A', 'x64',
|
||||
"-DCMAKE_TOOLCHAIN_FILE=${vcpkg}/scripts/buildsystems/vcpkg.cmake",
|
||||
'-DVCPKG_TARGET_TRIPLET=x64-windows-static',
|
||||
'-DVCPKG_HOST_TRIPLET=x64-windows-static'
|
||||
'-DVCPKG_HOST_TRIPLET=x64-windows-static']
|
||||
if (rev) args << "-DOPENZEN_BUILD_REVISION=${rev}"
|
||||
commandLine args
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,6 +433,48 @@ tasks.register('packageDist') {
|
||||
}
|
||||
}
|
||||
|
||||
ext.findUpx = {
|
||||
try {
|
||||
def p = ['cmd', '/c', 'where', 'upx'].execute()
|
||||
def out = new StringBuilder()
|
||||
p.consumeProcessOutput(out, new StringBuilder())
|
||||
p.waitForOrKill(2000)
|
||||
if (p.exitValue() == 0) {
|
||||
def first = out.toString().readLines().find { it?.trim() }
|
||||
if (first) return first.trim()
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
return null
|
||||
}
|
||||
|
||||
tasks.register('upxCompress') {
|
||||
group = 'openzen'
|
||||
description = 'Run UPX --best --lzma on the packaged OpenZenLoader.exe. ' +
|
||||
'No-op (warning only) when upx is not on PATH so local builds ' +
|
||||
'do not need it installed.'
|
||||
dependsOn 'packageDist'
|
||||
doLast {
|
||||
def exe = file("$buildDir/dist/OpenZenLoader.exe")
|
||||
if (!exe.isFile()) {
|
||||
throw new GradleException("packageDist did not produce ${exe}")
|
||||
}
|
||||
def upx = findUpx()
|
||||
if (!upx) {
|
||||
logger.warn("upx not on PATH; skipping compression. Install from " +
|
||||
"https://upx.github.io/ to enable.")
|
||||
return
|
||||
}
|
||||
def before = exe.length()
|
||||
exec {
|
||||
commandLine upx, '--best', '--lzma', exe.absolutePath
|
||||
}
|
||||
def after = exe.length()
|
||||
logger.lifecycle(String.format(
|
||||
"UPX: %,d -> %,d bytes (%.1f%% of original)",
|
||||
before, after, after * 100.0 / before))
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('dll') {
|
||||
group = 'openzen'
|
||||
description = 'Build the injectable DLL and GUI Loader (final dist artifacts).'
|
||||
|
||||
@@ -49,6 +49,14 @@ target_link_libraries(OpenZenLoader PRIVATE
|
||||
user32
|
||||
)
|
||||
|
||||
# Build-time git revision passed in by Gradle (gradle.properties /
|
||||
# CI). Stamped into the window title so a built loader can be
|
||||
# traced back to its source commit.
|
||||
if(DEFINED OPENZEN_BUILD_REVISION AND NOT OPENZEN_BUILD_REVISION STREQUAL "")
|
||||
target_compile_definitions(OpenZenLoader PRIVATE
|
||||
OPENZEN_BUILD_REVISION="${OPENZEN_BUILD_REVISION}")
|
||||
endif()
|
||||
|
||||
set_target_properties(OpenZenLoader PROPERTIES
|
||||
OUTPUT_NAME "OpenZenLoader"
|
||||
)
|
||||
|
||||
@@ -50,7 +50,12 @@ MainWindow::MainWindow(QWidget* parent)
|
||||
}
|
||||
|
||||
void MainWindow::buildUi() {
|
||||
#ifdef OPENZEN_BUILD_REVISION
|
||||
setWindowTitle(QStringLiteral("OpenZen Loader (build %1)")
|
||||
.arg(QString::fromLatin1(OPENZEN_BUILD_REVISION).left(7)));
|
||||
#else
|
||||
setWindowTitle(QStringLiteral("OpenZen Loader"));
|
||||
#endif
|
||||
resize(720, 460);
|
||||
|
||||
auto* central = new QWidget(this);
|
||||
|
||||
Reference in New Issue
Block a user