Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 199 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
104 changes: 104 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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<version from src/CMakeLists.txt>)
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[@]}"
33 changes: 33 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<thumbprint>` - certificate in `Cert:\CurrentUser\My` to sign with (default: `signtool /a` picks one).
- `-DIMAGER_SIGN_TIMESTAMP_URL=<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 <files>` 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
Expand All @@ -86,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<version>` 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
Expand Down
Loading
Loading