Skip to content
Open
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
84 changes: 69 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ name: Build
on:
push:
branches: [ main ]
tags: [ '*' ]
pull_request:
branches: [ main ]
workflow_dispatch:

permissions:
contents: write

jobs:
build-macos:
name: Build macOS Universal Binary (x86_64 + arm64)
Expand Down Expand Up @@ -107,8 +111,15 @@ jobs:
retention-days: 30

build-windows:
name: Build Windows (x64)
runs-on: windows-latest
name: Build Windows (${{ matrix.arch }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: windows-latest
arch: x64
- os: windows-11-arm
arch: arm64

steps:
- name: Checkout code
Expand All @@ -118,6 +129,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '22'
architecture: ${{ matrix.arch }}

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
Expand All @@ -130,15 +142,50 @@ jobs:

- name: Verify build output
shell: pwsh
env:
TARGET_ARCH: ${{ matrix.arch }}
run: |
Write-Host "Checking build output..."

if (Test-Path "build/Release/ztools_native.node") {
Write-Host "✅ .node file built successfully"
Get-Item "build/Release/ztools_native.node" | Format-List
} else {
Write-Host "❌ .node file not found"
exit 1
if (!(Test-Path "build/Release/ztools_native.node")) {
throw ".node file not found"
}

Get-Item "build/Release/ztools_native.node" | Format-List

$peCheck = @'
const fs = require('node:fs');

const file = 'build/Release/ztools_native.node';
const expectedMachines = { x64: 0x8664, arm64: 0xaa64 };
const arch = process.env.TARGET_ARCH;
const expected = expectedMachines[arch];
const binary = fs.readFileSync(file);

if (expected === undefined) {
throw new Error(`Unsupported target architecture: ${arch}`);
}
if (binary.length < 0x40 || binary.readUInt16LE(0) !== 0x5a4d) {
throw new Error(`${file} does not have a valid DOS header`);
}

const peOffset = binary.readUInt32LE(0x3c);
if (peOffset + 6 > binary.length || binary.readUInt32LE(peOffset) !== 0x00004550) {
throw new Error(`${file} does not have a valid PE header`);
}

const machine = binary.readUInt16LE(peOffset + 4);
console.log(`PE machine for ${arch}: 0x${machine.toString(16)}`);
if (machine !== expected) {
throw new Error(
`Expected PE machine 0x${expected.toString(16)} for ${arch}, got 0x${machine.toString(16)}`,
);
}
'@

$peCheck | node -
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

- name: Run tests
Expand All @@ -149,12 +196,12 @@ jobs:
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path artifacts
Copy-Item "build/Release/ztools_native.node" "artifacts/ztools_native-win-x64.node"
Copy-Item "build/Release/ztools_native.node" "artifacts/ztools_native-win-${{ matrix.arch }}.node"

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ztools-native-windows
name: ztools-native-windows-${{ matrix.arch }}
path: artifacts/
retention-days: 30

Expand All @@ -171,18 +218,25 @@ jobs:
name: ztools-native-macos
path: macos-artifacts

- name: Download Windows artifacts
- name: Download Windows x64 artifacts
uses: actions/download-artifact@v4
with:
name: ztools-native-windows-x64
path: windows-x64-artifacts

- name: Download Windows arm64 artifacts
uses: actions/download-artifact@v4
with:
name: ztools-native-windows
path: windows-artifacts
name: ztools-native-windows-arm64
path: windows-arm64-artifacts

- name: Create Release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
files: |
macos-artifacts/ztools_native-macos-universal.node
macos-artifacts/libZToolsNative-macos-universal.dylib
windows-artifacts/ztools_native-win-x64.node
windows-x64-artifacts/ztools_native-win-x64.node
windows-arm64-artifacts/ztools_native-win-arm64.node
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}