From e7f20c8aa8a41aaf4d9c1ecd96a176d774470bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=AA=20de=20Souza=20Pinto?= Date: Thu, 19 Nov 2026 14:02:29 +0100 Subject: [PATCH 1/3] CMakeLists.txt: call qt_add_lupdate after creating the target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qt_add_lupdate(SOURCE_TARGETS zflash) was called before add_executable(zflash). Newer Qt LinguistTools query the target's autogen build directory immediately, so configuring fails with: get_property could not find TARGET zflash. Perhaps it has not yet been created. Older Qt versions resolved the target lazily, which hid the ordering problem. Move the call after add_executable() so it works with both. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Renê de Souza Pinto --- src/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fc0f61aa3..f94c60341 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -672,9 +672,6 @@ qt_add_translation(QM_FILES ${TRANSLATIONS}) configure_file(i18n/translations.qrc "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY) set(SOURCES ${SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc ${QM_FILES}) -# Create an rpi-imager_lupdate target -qt_add_lupdate(TS_FILES ${TRANSLATIONS} SOURCE_TARGETS ${PROJECT_NAME} OPTIONS -no-obsolete -locations none) - if (WIN32) # Adding WIN32 prevents a console window being opened on Windows add_executable(${PROJECT_NAME} WIN32 ${SOURCES} ${HEADERS} ${DEPENDENCIES}) @@ -682,6 +679,9 @@ else() add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${DEPENDENCIES}) endif() +# Create a zflash_lupdate target (must come after the target exists) +qt_add_lupdate(TS_FILES ${TRANSLATIONS} SOURCE_TARGETS ${PROJECT_NAME} OPTIONS -no-obsolete -locations none) + set_property(TARGET ${PROJECT_NAME} PROPERTY AUTOMOC ON) set_property(TARGET ${PROJECT_NAME} PROPERTY AUTORCC ON) set_property(TARGET ${PROJECT_NAME} PROPERTY AUTOUIC ON) From 8d5a8f9f5e74cf5da2eceb6cc1ef2bd036a63ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=AA=20de=20Souza=20Pinto?= Date: Thu, 19 Nov 2026 14:11:15 +0100 Subject: [PATCH 2/3] windows: support self-signed code signing builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signing always used `signtool /a` with the DigiCert timestamp server, hard-coded in the post-build step and in both installer scripts, so there was no way to choose a specific certificate or to sign offline. Add two CMake options, used everywhere signtool is invoked: - IMAGER_SIGN_CERT_SHA1: thumbprint of the certificate to sign with (empty keeps the previous /a behaviour). - IMAGER_SIGN_TIMESTAMP_URL: RFC 3161 timestamp server (defaults to DigiCert; empty disables timestamping). Add build-win-selfsigned.ps1, which creates (or reuses/imports) a self-signed code signing certificate in Cert:\CurrentUser\My, exports its public part, optionally trusts it locally, and builds the signed application and installer. It can also sign arbitrary files. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Renê de Souza Pinto --- DEVELOPER.md | 22 ++++ build-win-selfsigned.ps1 | 189 ++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 19 +++- src/windows/rpi-imager.nsi.in | 4 +- 4 files changed, 230 insertions(+), 4 deletions(-) create mode 100644 build-win-selfsigned.ps1 diff --git a/DEVELOPER.md b/DEVELOPER.md index c58db9fcf..195666ef6 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -62,6 +62,28 @@ Building ZFlash on Windows is best done with Visual Studio Code (or a derivative - In the CMake plugin tab, select the 'inno_installer' target, and build it - Your resultant installer will be located in `%WORKSPACE%\build\installer` +Signing can be tuned with: + +- `-DIMAGER_SIGN_CERT_SHA1=` - certificate in `Cert:\CurrentUser\My` to sign with (default: `signtool /a` picks one). +- `-DIMAGER_SIGN_TIMESTAMP_URL=` - RFC 3161 timestamp server (default: `http://timestamp.digicert.com`; empty disables timestamping). + +#### Self-signed builds + +For test/internal builds without a commercial certificate, run from a PowerShell prompt: + +```powershell +.\build-win-selfsigned.ps1 -TrustLocally +``` + +It creates (or reuses) a self-signed code signing certificate in `Cert:\CurrentUser\My`, exports the +public part to `certs\zflash-codesign.cer`, and builds the signed application and installer in +`src\build-w64`. See `Get-Help .\build-win-selfsigned.ps1 -Full` for options (`-TimestampUrl ""` for +offline builds, `-PfxFile` to use an existing certificate, `-SignOnly ` to just sign files). + +Windows only trusts the result on machines where `zflash-codesign.cer` has been imported into the +`Trusted Root Certification Authorities` and `Trusted Publishers` stores. SmartScreen will still warn, +since it relies on reputation that self-signed certificates do not have. + ### macOS #### Get dependencies diff --git a/build-win-selfsigned.ps1 b/build-win-selfsigned.ps1 new file mode 100644 index 000000000..bfda85953 --- /dev/null +++ b/build-win-selfsigned.ps1 @@ -0,0 +1,189 @@ +<# +.SYNOPSIS + Build ZFlash on Windows and sign it with a self-signed code signing certificate. + +.DESCRIPTION + 1. Looks for a valid code signing certificate with the given subject in + Cert:\CurrentUser\My. If none is found (or -Regenerate is given), a new + self-signed one is created there. Alternatively, -PfxFile imports an + existing certificate (e.g. certs\sign.pfx from gen-certs.sh). + 2. Exports the public certificate (.cer) to -CertDir, so it can be + installed on the machines that should trust the build. + 3. Optionally trusts the certificate on this machine (-TrustLocally). + 4. Configures and builds the project with signing enabled, pointing signtool + at the certificate by its thumbprint. The application, the installer and + its uninstaller are all signed. + + With -SignOnly, no build is done and the given files are signed instead. + +.EXAMPLE + .\build-win-selfsigned.ps1 -TrustLocally + +.EXAMPLE + # Offline build, no timestamp server + .\build-win-selfsigned.ps1 -TimestampUrl "" + +.EXAMPLE + # Sign already built files + .\build-win-selfsigned.ps1 -SignOnly src\build-w64\installer\imager-1.0.0.exe +#> +[CmdletBinding()] +param( + [string] $Subject = "CN=ZFlash Self-Signed Code Signing, O=Zededa Inc., L=San Jose, S=California, C=US", + [int] $ValidYears = 3, + [string] $CertDir = (Join-Path $PSScriptRoot "certs"), + [switch] $Regenerate, + [string] $PfxFile, + [SecureString] $PfxPassword, + [switch] $ExportPfx, + [switch] $TrustLocally, + # RFC 3161 timestamp server. Pass "" to skip timestamping (e.g. offline builds). + [AllowEmptyString()] + [string] $TimestampUrl = "http://timestamp.digicert.com", + [string] $QtRoot = "C:\Qt\6.9.1\mingw_64", + [string] $MingwRoot = "C:\Qt\Tools\mingw1310_64", + [string] $BuildDir = (Join-Path $PSScriptRoot "src\build-w64"), + [string] $Target = "inno_installer", + [int] $Jobs = 8, + [string] $SignTool, + [string[]] $SignOnly +) + +$ErrorActionPreference = "Stop" + +function Find-SignTool { + if ($SignTool) { return $SignTool } + $cmd = Get-Command signtool.exe -ErrorAction SilentlyContinue + if ($cmd) { return $cmd.Source } + $kitsRoot = (Get-ItemProperty -ErrorAction SilentlyContinue ` + "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots").KitsRoot10 + if (-not $kitsRoot) { $kitsRoot = "${env:ProgramFiles(x86)}\Windows Kits\10\" } + $found = Get-ChildItem -Path (Join-Path $kitsRoot "bin") -Filter signtool.exe -Recurse -ErrorAction SilentlyContinue | + Where-Object { $_.Directory.Name -eq "x64" } | + Sort-Object { $_.Directory.Parent.Name } -Descending | + Select-Object -First 1 + if (-not $found) { + throw "signtool.exe not found. Install the Windows 10/11 SDK or pass -SignTool ." + } + return $found.FullName +} + +function Get-SigningCertificate { + if ($PfxFile) { + Write-Host "Importing $PfxFile into Cert:\CurrentUser\My" + if (-not $PfxPassword) { $PfxPassword = Read-Host -AsSecureString "Password for $PfxFile" } + $imported = Import-PfxCertificate -FilePath $PfxFile -Password $PfxPassword ` + -CertStoreLocation Cert:\CurrentUser\My -Exportable + # A PFX may also carry CA certificates; pick the one with a private key. + return $imported | Where-Object { $_.HasPrivateKey } | Select-Object -First 1 + } + + if (-not $Regenerate) { + $existing = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert | + Where-Object { $_.Subject -eq $Subject -and $_.HasPrivateKey -and $_.NotAfter -gt (Get-Date).AddDays(1) } | + Sort-Object NotAfter -Descending | + Select-Object -First 1 + if ($existing) { + Write-Host "Reusing existing certificate $($existing.Thumbprint) (expires $($existing.NotAfter))" + return $existing + } + } + + Write-Host "Creating self-signed code signing certificate: $Subject" + return New-SelfSignedCertificate ` + -Type CodeSigningCert ` + -Subject $Subject ` + -FriendlyName "ZFlash self-signed code signing" ` + -KeyAlgorithm RSA -KeyLength 3072 -HashAlgorithm SHA256 ` + -KeyUsage DigitalSignature ` + -KeyExportPolicy Exportable ` + -CertStoreLocation Cert:\CurrentUser\My ` + -NotAfter (Get-Date).AddYears($ValidYears) +} + +function Get-SignArgs([string] $Thumbprint) { + $a = @("sign", "/fd", "sha256", "/sha1", $Thumbprint) + if ($TimestampUrl) { $a += @("/tr", $TimestampUrl, "/td", "sha256") } + return $a +} + +# --- Certificate ------------------------------------------------------------- + +$cert = Get-SigningCertificate +if (-not $cert) { throw "No usable code signing certificate (with private key) found." } +$thumb = $cert.Thumbprint + +New-Item -ItemType Directory -Force -Path $CertDir | Out-Null +$cerPath = Join-Path $CertDir "zflash-codesign.cer" +Export-Certificate -Cert $cert -FilePath $cerPath -Force | Out-Null +Write-Host "Public certificate exported to $cerPath" + +if ($ExportPfx) { + $pfxOut = Join-Path $CertDir "zflash-codesign.pfx" + $pw = Read-Host -AsSecureString "Password to protect $pfxOut" + Export-PfxCertificate -Cert $cert -FilePath $pfxOut -Password $pw -Force | Out-Null + Write-Host "Certificate and private key exported to $pfxOut (keep it private!)" +} + +if ($TrustLocally) { + # Root makes the signature chain valid; TrustedPublisher suppresses the + # "unknown publisher" prompt. Windows asks for confirmation on the Root import. + if ($cert.Subject -ne $cert.Issuer) { + Write-Warning "Certificate is issued by '$($cert.Issuer)'; import that CA certificate into Root instead for full trust." + } else { + Import-Certificate -FilePath $cerPath -CertStoreLocation Cert:\CurrentUser\Root | Out-Null + } + Import-Certificate -FilePath $cerPath -CertStoreLocation Cert:\CurrentUser\TrustedPublisher | Out-Null + Write-Host "Certificate trusted for the current user." +} + +# --- Sign-only mode ---------------------------------------------------------- + +if ($SignOnly) { + $st = Find-SignTool + foreach ($f in $SignOnly) { + & $st @(Get-SignArgs $thumb) $f + if ($LASTEXITCODE -ne 0) { throw "signtool failed on $f" } + } + Write-Host "Signed $($SignOnly.Count) file(s) with $thumb" + return +} + +# --- Build ------------------------------------------------------------------- + +$st = Find-SignTool +$env:PATH = "$MingwRoot\bin;${env:ProgramFiles}\CMake\bin;$env:PATH" +New-Item -ItemType Directory -Force -Path $BuildDir | Out-Null + +$cmakeArgs = @( + "-S", (Join-Path $PSScriptRoot "src"), + "-B", $BuildDir, + "-G", "MinGW Makefiles", + "-DQt6_ROOT=$QtRoot", + "-DMINGW64_ROOT=$MingwRoot", + "-DENABLE_INNO_INSTALLER=ON", + "-DIMAGER_SIGNED_APP=ON", + "-DSIGNTOOL=$st", + "-DIMAGER_SIGN_CERT_SHA1=$thumb", + "-DIMAGER_SIGN_TIMESTAMP_URL=$TimestampUrl" +) +& cmake @cmakeArgs +if ($LASTEXITCODE -ne 0) { throw "CMake configure failed" } + +& cmake --build $BuildDir --target $Target -j $Jobs +if ($LASTEXITCODE -ne 0) { throw "Build failed" } + +# --- Verify ------------------------------------------------------------------ + +$toCheck = @(Get-ChildItem (Join-Path $BuildDir "deploy\*.exe") -ErrorAction SilentlyContinue) + + @(Get-ChildItem (Join-Path $BuildDir "installer\*.exe") -ErrorAction SilentlyContinue) +foreach ($f in $toCheck) { + $sig = Get-AuthenticodeSignature $f.FullName + $signer = if ($sig.SignerCertificate) { $sig.SignerCertificate.Thumbprint } else { "-" } + Write-Host ("{0,-60} {1,-14} {2}" -f $f.Name, $sig.Status, $signer) +} +Write-Host "" +Write-Host "Done. Signed with $thumb." +Write-Host "To trust these binaries on another machine (as administrator):" +Write-Host " Import-Certificate -FilePath zflash-codesign.cer -CertStoreLocation Cert:\LocalMachine\Root" +Write-Host " Import-Certificate -FilePath zflash-codesign.cer -CertStoreLocation Cert:\LocalMachine\TrustedPublisher" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f94c60341..fbe29423f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,8 @@ set(Qt6_ROOT "/opt/Qt/6.9.0/gcc_arm64" CACHE PATH "Your Qt6 root path") if (WIN32) set(MINGW64_ROOT "" CACHE PATH "Your MinGW64 root path, likely provided by QtCreator") set(IMAGER_SIGNED_APP OFF CACHE BOOL "Sign Imager and its installer as part of the build. Requires a valid Code Signing certificate.") + set(IMAGER_SIGN_CERT_SHA1 "" CACHE STRING "SHA1 thumbprint of the code signing certificate (CurrentUser\\My store). Empty: let signtool pick the best one (/a).") + set(IMAGER_SIGN_TIMESTAMP_URL "http://timestamp.digicert.com" CACHE STRING "RFC 3161 timestamp server used when signing. Empty: do not timestamp.") endif() if (APPLE) @@ -800,9 +802,22 @@ if (WIN32) endif() add_definitions(-DSIGNTOOL="${SIGNTOOL}") + # signtool arguments, shared by the post-build step and the installers + set(SIGNTOOL_ARGS sign /fd sha256) + if (IMAGER_SIGN_TIMESTAMP_URL) + list(APPEND SIGNTOOL_ARGS /tr ${IMAGER_SIGN_TIMESTAMP_URL} /td sha256) + endif() + if (IMAGER_SIGN_CERT_SHA1) + list(APPEND SIGNTOOL_ARGS /sha1 ${IMAGER_SIGN_CERT_SHA1}) + else() + list(APPEND SIGNTOOL_ARGS /a) + endif() + list(JOIN SIGNTOOL_ARGS " " SIGNTOOL_ARGS_STR) + message(STATUS "Code signing command: ${SIGNTOOL} ${SIGNTOOL_ARGS_STR}") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND "${SIGNTOOL}" sign /tr http://timestamp.digicert.com /td sha256 /fd sha256 /a "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.exe") + COMMAND "${SIGNTOOL}" ${SIGNTOOL_ARGS} "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.exe") endif(IMAGER_SIGNED_APP) @@ -844,7 +859,7 @@ if (WIN32) if(INNO_COMPILER) if(IMAGER_SIGNED_APP) add_custom_target(inno_installer - COMMAND "${INNO_COMPILER}" "${CMAKE_CURRENT_BINARY_DIR}/rpi-imager.iss" "/DSIGNING_ENABLED" "/Ssign=${SIGNTOOL} sign /tr http://timestamp.digicert.com /td sha256 /fd sha256 /a $p" + COMMAND "${INNO_COMPILER}" "${CMAKE_CURRENT_BINARY_DIR}/rpi-imager.iss" "/DSIGNING_ENABLED" "/Ssign=${SIGNTOOL} ${SIGNTOOL_ARGS_STR} $p" DEPENDS ${PROJECT_NAME} COMMENT "Building Inno Setup installer" VERBATIM) diff --git a/src/windows/rpi-imager.nsi.in b/src/windows/rpi-imager.nsi.in index 1b40e668d..2234ea8ae 100644 --- a/src/windows/rpi-imager.nsi.in +++ b/src/windows/rpi-imager.nsi.in @@ -64,13 +64,13 @@ InstallDir "$PROGRAMFILES\ZFlash Imager" ; That will have written an uninstaller binary for us. Now we sign it with your ; favorite code signing tool. - !system '"@SIGNTOOL@" sign /tr http://timestamp.digicert.com /td sha256 /fd sha256 /a "$%TEMP%\uninstall.exe"' = 0 + !system '"@SIGNTOOL@" @SIGNTOOL_ARGS_STR@ "$%TEMP%\uninstall.exe"' = 0 ; Good. Now we can carry on writing the real installer. OutFile "${INSTALLER_NAME}" SetCompressor /SOLID lzma - !finalize '"@SIGNTOOL@" sign /tr http://timestamp.digicert.com /td sha256 /fd sha256 /a "%1"' + !finalize '"@SIGNTOOL@" @SIGNTOOL_ARGS_STR@ "%1"' !endif ### From 9973fe5d86a6c44c1c9328ceba355ce03f050361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=AA=20de=20Souza=20Pinto?= Date: Thu, 19 Nov 2026 14:28:08 +0100 Subject: [PATCH 3/3] github: add build and release workflows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a build workflow that runs on every pull request and builds: - Linux: x86_64 AppImage (via create-appimage.sh, on Ubuntu 22.04) - Windows: x64 Inno Setup installer (Qt MinGW toolchain) - macOS: universal DMG Packages are attached to the run as artifacts. Add a manually triggered release workflow that reuses the build workflow, creates the GitHub release (tag defaults to v from src/CMakeLists.txt, draft by default) and uploads the packages plus a SHA256SUMS file. Windows binaries can optionally be signed with a certificate provided through the WINDOWS_SIGNING_PFX and WINDOWS_SIGNING_PFX_PASSWORD secrets. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Renê de Souza Pinto --- .github/workflows/build.yml | 199 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 104 ++++++++++++++++++ DEVELOPER.md | 11 ++ 3 files changed, 314 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..65d953725 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,199 @@ +name: Build + +# Builds ZFlash for Linux (AppImage), Windows (installer) and macOS (DMG). +# Runs on every pull request, and is reused by the release workflow. + +on: + pull_request: + workflow_call: + inputs: + sign-windows: + description: Sign the Windows binaries (needs the WINDOWS_SIGNING_PFX secrets) + type: boolean + default: false + secrets: + WINDOWS_SIGNING_PFX: + description: Base64-encoded .pfx code signing certificate + required: false + WINDOWS_SIGNING_PFX_PASSWORD: + description: Password of the .pfx + required: false + +permissions: + contents: read + +concurrency: + # Cancel superseded PR builds; never cancel release builds (unique run_id). + group: build-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: true + +env: + # Qt >= 6.9.2 is needed on macOS: older releases link the AGL framework, + # which the Xcode 26 SDK no longer ships. + QT_VERSION: "6.9.3" + +jobs: + linux: + name: Linux (x86_64 AppImage) + # Oldest supported runner: the AppImage only runs on glibc >= the build host's. + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v7 + + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + build-essential g++-12 cmake git file curl libfuse2 \ + libgnutls28-dev libdrm-dev libgl1-mesa-dev libegl1 libopengl0 \ + libxkbcommon-dev libxkbcommon-x11-0 libxcb-cursor0 libxcb-icccm4 \ + libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 \ + libxcb-shape0 libxcb-xinerama0 libxcb-xfixes0 libxcb-xkb1 \ + libfontconfig1 libdbus-1-3 + + - name: Install Qt + uses: jurplel/install-qt-action@v4 + with: + version: ${{ env.QT_VERSION }} + host: linux + target: desktop + arch: linux_gcc_64 + cache: true + + - name: Build AppImage + env: + CC: gcc-12 + CXX: g++-12 + run: ./create-appimage.sh --arch=x86_64 --qt-root="$QT_ROOT_DIR" + + - name: Collect artifact + run: | + mkdir -p dist + mv ZFlash-*-x86_64.AppImage dist/ + ls -l dist + + - uses: actions/upload-artifact@v7 + with: + name: zflash-linux-x86_64 + path: dist/* + if-no-files-found: error + retention-days: 14 + + windows: + name: Windows (x64 installer) + runs-on: windows-2022 + steps: + - uses: actions/checkout@v7 + + - name: Install Qt and MinGW + uses: jurplel/install-qt-action@v4 + with: + version: ${{ env.QT_VERSION }} + host: windows + target: desktop + arch: win64_mingw + tools: tools_mingw1310,qt.tools.win64_mingw1310 + cache: true + + - name: Install Inno Setup + shell: pwsh + run: | + if (-not (Test-Path "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe")) { + choco install innosetup --no-progress -y + } + + - name: Import signing certificate + id: cert + if: inputs.sign-windows + shell: pwsh + env: + PFX_B64: ${{ secrets.WINDOWS_SIGNING_PFX }} + PFX_PASSWORD: ${{ secrets.WINDOWS_SIGNING_PFX_PASSWORD }} + run: | + if (-not $env:PFX_B64) { throw "sign-windows requested but the WINDOWS_SIGNING_PFX secret is not set" } + $pfx = Join-Path $env:RUNNER_TEMP "sign.pfx" + [IO.File]::WriteAllBytes($pfx, [Convert]::FromBase64String($env:PFX_B64)) + $pw = ConvertTo-SecureString $env:PFX_PASSWORD -AsPlainText -Force + $cert = Import-PfxCertificate -FilePath $pfx -Password $pw -CertStoreLocation Cert:\CurrentUser\My | + Where-Object { $_.HasPrivateKey } | Select-Object -First 1 + Remove-Item $pfx + if (-not $cert) { throw "No certificate with a private key found in WINDOWS_SIGNING_PFX" } + Write-Host "Signing with $($cert.Subject) ($($cert.Thumbprint))" + "thumbprint=$($cert.Thumbprint)" >> $env:GITHUB_OUTPUT + + - name: Build installer + shell: pwsh + env: + THUMBPRINT: ${{ steps.cert.outputs.thumbprint }} + run: | + $mingw = Join-Path $env:RUNNER_WORKSPACE "Qt\Tools\mingw1310_64" + if (-not (Test-Path "$mingw\bin\g++.exe")) { throw "MinGW not found at $mingw" } + # Put Qt's MinGW first so the runner's other GCC toolchains are not picked up. + $env:PATH = "$mingw\bin;$env:PATH" + + $cmakeArgs = @( + "-S", "src", "-B", "build", "-G", "MinGW Makefiles", + "-DCMAKE_BUILD_TYPE=MinSizeRel", + "-DCMAKE_C_COMPILER=$mingw\bin\gcc.exe", + "-DCMAKE_CXX_COMPILER=$mingw\bin\g++.exe", + "-DQt6_ROOT=$env:QT_ROOT_DIR", + "-DMINGW64_ROOT=$mingw", + "-DENABLE_INNO_INSTALLER=ON" + ) + if ($env:THUMBPRINT) { + $cmakeArgs += @("-DIMAGER_SIGNED_APP=ON", "-DIMAGER_SIGN_CERT_SHA1=$env:THUMBPRINT") + } + cmake @cmakeArgs + if ($LASTEXITCODE -ne 0) { throw "CMake configure failed" } + cmake --build build --target inno_installer -j 4 + if ($LASTEXITCODE -ne 0) { throw "Build failed" } + + - name: Collect artifact + shell: bash + run: | + ver=$(sed -nE 's/^set\(IMAGER_VERSION_(MAJOR|MINOR|PATCH) ([0-9]+)\)/\2/p' src/CMakeLists.txt | paste -sd. -) + mkdir -p dist + mv build/installer/imager-*.exe "dist/ZFlash-${ver}-windows-x64-setup.exe" + ls -l dist + + - uses: actions/upload-artifact@v7 + with: + name: zflash-windows-x64 + path: dist/* + if-no-files-found: error + retention-days: 14 + + macos: + name: macOS (universal DMG) + runs-on: macos-latest + steps: + - uses: actions/checkout@v7 + + - name: Install Qt + uses: jurplel/install-qt-action@v4 + with: + version: ${{ env.QT_VERSION }} + host: mac + target: desktop + arch: clang_64 + cache: true + + - name: Build DMG + run: | + cmake -S src -B build -DCMAKE_BUILD_TYPE=MinSizeRel -DQt6_ROOT="$QT_ROOT_DIR" + cmake --build build -j "$(sysctl -n hw.ncpu)" + cmake --build build --target dmg + + - name: Collect artifact + run: | + ver=$(sed -nE 's/^set\(IMAGER_VERSION_(MAJOR|MINOR|PATCH) ([0-9]+)\)/\2/p' src/CMakeLists.txt | paste -sd. -) + mkdir -p dist + mv "build/ZFlash Imager-${ver}.dmg" "dist/ZFlash-${ver}-macos-universal.dmg" + ls -l dist + + - uses: actions/upload-artifact@v7 + with: + name: zflash-macos-universal + path: dist/* + if-no-files-found: error + retention-days: 14 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..aa8f396a3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,104 @@ +name: Release + +# Manually triggered: builds ZFlash for Linux, Windows and macOS, creates the +# GitHub release and uploads the packages to it. + +on: + workflow_dispatch: + inputs: + tag: + description: Release tag (default v) + required: false + type: string + draft: + description: Create the release as a draft + type: boolean + default: true + prerelease: + description: Mark the release as a pre-release + type: boolean + default: false + sign-windows: + description: Sign the Windows binaries (needs the WINDOWS_SIGNING_PFX secrets) + type: boolean + default: false + +permissions: + contents: read + +concurrency: + group: release + cancel-in-progress: false + +jobs: + prepare: + name: Prepare + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + tag: ${{ steps.version.outputs.tag }} + steps: + - uses: actions/checkout@v7 + + - name: Determine version and tag + id: version + env: + GH_TOKEN: ${{ github.token }} + TAG_INPUT: ${{ inputs.tag }} + run: | + ver=$(sed -nE 's/^set\(IMAGER_VERSION_(MAJOR|MINOR|PATCH) ([0-9]+)\)/\2/p' src/CMakeLists.txt | paste -sd. -) + tag="${TAG_INPUT:-v$ver}" + echo "Version: $ver, tag: $tag, commit: $GITHUB_SHA" + if gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then + echo "::error::Release $tag already exists. Delete it or pick another tag." + exit 1 + fi + echo "version=$ver" >> "$GITHUB_OUTPUT" + echo "tag=$tag" >> "$GITHUB_OUTPUT" + + build: + name: Build + needs: prepare + uses: ./.github/workflows/build.yml + with: + sign-windows: ${{ inputs.sign-windows }} + secrets: inherit + + release: + name: Publish release + needs: [prepare, build] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Download artifacts + uses: actions/download-artifact@v8 + with: + pattern: zflash-* + path: dist + merge-multiple: true + + - name: Generate checksums + working-directory: dist + run: | + sha256sum * > SHA256SUMS + cat SHA256SUMS + + - name: Create release + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ needs.prepare.outputs.tag }} + VERSION: ${{ needs.prepare.outputs.version }} + DRAFT: ${{ inputs.draft }} + PRERELEASE: ${{ inputs.prerelease }} + run: | + flags=() + [ "$DRAFT" = "true" ] && flags+=(--draft) + [ "$PRERELEASE" = "true" ] && flags+=(--prerelease) + # Creates the tag on the built commit if it does not exist yet. + gh release create "$TAG" dist/* \ + --repo "$GITHUB_REPOSITORY" \ + --target "$GITHUB_SHA" \ + --title "ZFlash $VERSION" \ + --generate-notes \ + "${flags[@]}" diff --git a/DEVELOPER.md b/DEVELOPER.md index 195666ef6..c31d2e793 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -108,6 +108,17 @@ Building ZFlash on Windows is best done with Visual Studio Code (or a derivative - In the CMake plugin tab, select the 'zflash' target, and build it - Your resultant DMG will be located at `$WORKSPACE\build\ZFlash Imager-$VERSION.dmg` +## Continuous integration and releases + +- `.github/workflows/build.yml` builds the Linux AppImage (x86_64), Windows installer (x64) and + macOS DMG (universal) for every pull request. The packages are attached to the workflow run as artifacts. +- `.github/workflows/release.yml` is started manually (Actions → Release → Run workflow). It builds + the same packages, creates the GitHub release (tag defaults to `v` from `src/CMakeLists.txt`, + created as a draft by default) and uploads the packages plus a `SHA256SUMS` file. +- To sign the Windows binaries in a release, add the repository secrets `WINDOWS_SIGNING_PFX` + (the .pfx file, base64-encoded: `base64 -w0 sign.pfx`) and `WINDOWS_SIGNING_PFX_PASSWORD`, then + tick "Sign the Windows binaries" when running the workflow. + ## Other notes ### Custom repository