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
202 changes: 64 additions & 138 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: Build Precompiled Binaries
name: Build and Publish

on:
push:
branches: [ main, develop ]
tags: [ 'v*' ]
branches: [main, develop]
tags: ['v*']
pull_request:
branches: [ main ]
branches: [main]

jobs:
build:
env:
HAMLIB_VERSION: '4.6.5'
PTHREADS_SOURCEWARE_DIR: 'prebuilt-dll-2-9-1-release'

strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
Expand All @@ -38,6 +38,9 @@ jobs:
node-version: '18'
cache: 'npm'

- name: Install Python setuptools (for node-gyp)
run: pip3 install setuptools --break-system-packages || pip3 install setuptools || true

- name: Install system dependencies (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
Expand Down Expand Up @@ -76,177 +79,100 @@ jobs:
Write-Host "HAMLIB root: $root"
"HAMLIB_ROOT=$root" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Setup Windows pthread
- name: Setup MSYS2 MinGW (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$dir = $env:PTHREADS_SOURCEWARE_DIR
$base = "https://sourceware.org/pub/pthreads-win32/$dir"
$root = Join-Path $env:RUNNER_TEMP 'pthreads-root'
New-Item -ItemType Directory -Path (Join-Path $root 'lib/x64') -Force | Out-Null

foreach ($f in @('pthread.h','sched.h','semaphore.h')) {
Invoke-WebRequest -Uri "$base/include/$f" -OutFile (Join-Path $root $f)
}
Invoke-WebRequest -Uri "$base/lib/x64/pthreadVC2.lib" -OutFile (Join-Path $root 'lib/x64/pthreadVC2.lib')
"PTHREAD_ROOT=$root" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
location: D:\msys2
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-binutils

- name: Setup MSVC (Windows)
if: matrix.os == 'windows-latest'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64

- name: Fix Hamlib import library (Windows)
- name: Install Node.js dependencies
run: npm ci --ignore-scripts

- name: Build shim DLL (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
env:
MINGW_CC: D:\msys2\msys64\mingw64\bin\gcc.exe
run: |
$dllPath = Get-ChildItem -Path (Join-Path $env:HAMLIB_ROOT 'bin') -Filter 'libhamlib-*.dll' | Select-Object -First 1
$defPath = Join-Path $env:RUNNER_TEMP 'libhamlib-4.def'
$libPath = Join-Path $env:HAMLIB_ROOT 'lib/libhamlib-4.lib'

$exports = dumpbin /exports $dllPath.FullName
$defContent = "LIBRARY libhamlib-4.dll`nEXPORTS`n"
$inExports = $false
foreach ($line in $exports -split "`n") {
if ($line -match '^\s+ordinal\s+hint\s+RVA\s+name') { $inExports = $true; continue }
if ($inExports -and $line -match '^\s+\d+\s+[0-9A-F]+\s+[0-9A-F]+\s+(\S+)') {
$defContent += " $($matches[1])`n"
}
}

Set-Content -Path $defPath -Value $defContent -Encoding ASCII
$libDir = Join-Path $env:HAMLIB_ROOT 'lib'
if (-not (Test-Path $libDir)) { New-Item -ItemType Directory -Path $libDir -Force | Out-Null }
lib /def:$defPath /out:$libPath /machine:x64
$env:Path = "D:\msys2\msys64\mingw64\bin;$env:Path"
node scripts/build-shim.js --verbose

- name: Install Node.js dependencies
run: npm ci --ignore-scripts
- name: Build (Windows)
if: matrix.os == 'windows-latest'
run: npm run build:all -- --skip-hamlib --skip-shim --minimal

- name: Build (Linux/macOS - unified)
- name: Build (Unix)
if: matrix.os != 'windows-latest'
run: |
npm run build:all -- --minimal
npm run verify
run: npm run build:all -- --minimal

- name: Build (Windows - staged)
if: matrix.os == 'windows-latest'
- name: Run tests
run: |
node scripts/run-prebuildify.js
npm run bundle
npm run verify
node test/test_loader.js
node test/test_ci_functional.js

- name: Upload prebuilds artifact
- name: Upload prebuilds
uses: actions/upload-artifact@v4
with:
name: prebuilds-${{ matrix.target }}
path: prebuilds/**
retention-days: 1
name: prebuilt-${{ matrix.target }}
path: prebuilds/
retention-days: 7

package:
publish:
name: Publish
needs: build
runs-on: ubuntu-latest

if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'

- name: Download all prebuilds
uses: actions/download-artifact@v4
- uses: actions/download-artifact@v4
with:
path: prebuilds-temp
path: all-artifacts

- name: Organize prebuilds
run: |
mkdir -p prebuilds
for platform_dir in prebuilds-temp/prebuilds-*/; do
if [ -d "$platform_dir/prebuilds" ]; then
mv "$platform_dir/prebuilds"/* prebuilds/ 2>/dev/null || true
else
mv "$platform_dir"/* prebuilds/ 2>/dev/null || true
fi
for dir in all-artifacts/prebuilt-*/; do
[ -d "$dir" ] && cp -r "$dir"/* prebuilds/
done

- name: Install dependencies
run: npm ci --ignore-scripts

- name: Verify build
run: npm run verify:all

- name: Create build info
- name: Validate prebuilds
run: |
cat > prebuilds/BUILD_INFO.txt << EOF
Node-HamLib Precompiled Binaries
================================
Build Time: $(date -u)
Git Commit: ${{ github.sha }}
Git Ref: ${{ github.ref }}

Supported Platforms:
EOF

for dir in prebuilds/*/; do
if [ -d "$dir" ]; then
echo "- $(basename "$dir")" >> prebuilds/BUILD_INFO.txt
fi
for p in linux-x64 linux-arm64 darwin-arm64 darwin-x64 win32-x64; do
test -f "prebuilds/$p/node.napi.node" || { echo "Missing: $p"; exit 1; }
done
echo "All 5 platform prebuilds verified."
find prebuilds -name "*.node" -exec ls -la {} \;

echo "" >> prebuilds/BUILD_INFO.txt
echo "Installation: Extract to your project's prebuilds/ directory" >> prebuilds/BUILD_INFO.txt
- run: npm ci --ignore-scripts

cd prebuilds
zip -r ../node-hamlib-prebuilds.zip . -x "*.DS_Store"
cd ..

- name: Upload unified package
uses: actions/upload-artifact@v4
with:
name: node-hamlib-prebuilds
path: node-hamlib-prebuilds.zip
retention-days: 90
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/v')
uses: ncipollo/release-action@v1
with:
tag: ${{ github.ref_name }}
name: "Node-HamLib ${{ github.ref_name }}"
artifacts: node-hamlib-prebuilds.zip
body: |
# Node-HamLib ${{ github.ref_name }}

## Precompiled Binaries

Includes precompiled binaries for:
- Linux x64/ARM64
- macOS ARM64 (Apple Silicon) & x64 (Intel)
- Windows x64

### Installation

```bash
npm install node-hamlib
```

Binaries are automatically detected and used when available.

cleanup:
needs: [build, package]
runs-on: ubuntu-latest
if: always()

steps:
- name: Delete temporary artifacts
uses: geekyeggo/delete-artifact@v5
with:
name: |
prebuilds-linux-x64
prebuilds-linux-arm64
prebuilds-darwin-arm64
prebuilds-darwin-x64
prebuilds-win32-x64
failOnError: false
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION=${GITHUB_REF#refs/tags/}
for dir in prebuilds/*/; do
platform=$(basename "$dir")
tar -czf "node-hamlib-${VERSION}-${platform}.tar.gz" -C prebuilds "$platform"
done
gh release create "$VERSION" --title "Node-HamLib $VERSION" --generate-notes \
node-hamlib-${VERSION}-*.tar.gz
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Build outputs
build/
shim-build/
*.node
prebuilds/

Expand Down Expand Up @@ -50,4 +51,5 @@ temp/
build.sh
Dockerfile

Hamlib/
Hamlib/
hamlib/
Loading
Loading