feat: add getSupportedModes method to retrieve supported radio modes #148
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Precompiled Binaries | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| tags: [ 'v*' ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| # 多平台并行构建 | |
| build: | |
| env: | |
| HAMLIB_VERSION: '4.6.5' | |
| PTHREADS_SOURCEWARE_DIR: 'prebuilt-dll-2-9-1-release' | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| arch: x64 | |
| target: linux-x64 | |
| hamlib_install: | | |
| sudo apt-get update | |
| sudo apt-get install -y libhamlib-dev libhamlib-utils patchelf | |
| # Install runtime dependencies for bundling | |
| sudo apt-get install -y libusb-1.0-0 libindi1 || true | |
| - os: ubuntu-24.04-arm | |
| arch: arm64 | |
| target: linux-arm64 | |
| hamlib_install: | | |
| sudo apt-get update | |
| sudo apt-get install -y libhamlib-dev libhamlib-utils patchelf | |
| # Install runtime dependencies for bundling | |
| sudo apt-get install -y libusb-1.0-0 libindi1 || true | |
| - os: windows-latest | |
| arch: x64 | |
| target: win32-x64 | |
| hamlib_install: | | |
| echo "Setting up Windows hamlib from repository folder or official zip" | |
| $ErrorActionPreference = 'Stop' | |
| $ver = $env:HAMLIB_VERSION | |
| $localFolder = Join-Path $env:GITHUB_WORKSPACE "hamlib-w64-$ver" | |
| if ((Test-Path $localFolder -PathType Container) -and (Test-Path (Join-Path $localFolder 'bin'))) { | |
| Write-Host "Found local hamlib folder: $localFolder" | |
| $root = $localFolder | |
| } else { | |
| $zipUrl = "https://github.com/Hamlib/Hamlib/releases/download/$ver/hamlib-w64-$ver.zip" | |
| $zipPath = Join-Path $env:RUNNER_TEMP "hamlib-w64-$ver.zip" | |
| Write-Host "Downloading $zipUrl" | |
| Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath | |
| $dest = Join-Path $env:GITHUB_WORKSPACE 'hamlib' | |
| if (Test-Path $dest) { Remove-Item -Recurse -Force $dest } | |
| New-Item -ItemType Directory -Path $dest | Out-Null | |
| Add-Type -AssemblyName System.IO.Compression.FileSystem | |
| [System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $dest) | |
| # Detect nested folder in zip (e.g., hamlib-w64-<ver>) | |
| $root = $dest | |
| if (!(Test-Path (Join-Path $root 'bin'))) { | |
| $child = Get-ChildItem -Path $dest -Directory | Select-Object -First 1 | |
| if ($null -ne $child -and (Test-Path (Join-Path $child.FullName 'bin'))) { | |
| $root = $child.FullName | |
| } | |
| } | |
| } | |
| Write-Host "HAMLIB root detected at: $root" | |
| "HAMLIB_ROOT=$root" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| (Join-Path $root 'bin') | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
| - os: macos-latest | |
| arch: arm64 | |
| target: darwin-arm64 | |
| hamlib_install: | | |
| brew install hamlib dylibbundler | |
| pip3 install setuptools --break-system-packages || true | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Prepare pthreads from Sourceware (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| $ErrorActionPreference = 'Stop' | |
| $dir = $env:PTHREADS_SOURCEWARE_DIR | |
| $base = "https://sourceware.org/pub/pthreads-win32/$dir" | |
| $root = Join-Path $env:RUNNER_TEMP 'pthreads-root' | |
| if (Test-Path $root) { Remove-Item -Recurse -Force $root } | |
| New-Item -ItemType Directory -Path (Join-Path $root 'lib/x64') -Force | Out-Null | |
| foreach ($f in @('pthread.h','sched.h','semaphore.h')) { | |
| $url = "$base/include/$f" | |
| $dst = Join-Path $root $f | |
| Write-Host "Downloading $url -> $dst" | |
| Invoke-WebRequest -Uri $url -OutFile $dst | |
| } | |
| $libUrl = "$base/lib/x64/pthreadVC2.lib" | |
| $libDst = Join-Path $root 'lib/x64/pthreadVC2.lib' | |
| Write-Host "Downloading $libUrl -> $libDst" | |
| Invoke-WebRequest -Uri $libUrl -OutFile $libDst | |
| "PTHREAD_ROOT=$root" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install Hamlib dependencies | |
| run: ${{ matrix.hamlib_install }} | |
| - name: Install Node.js dependencies (skip scripts) | |
| run: npm ci --ignore-scripts | |
| - name: Setup Developer Command Prompt (Windows) | |
| if: matrix.os == 'windows-latest' | |
| uses: ilammy/msvc-dev-cmd@v1 | |
| with: | |
| arch: x64 | |
| - name: Fix hamlib import library (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| $ErrorActionPreference = 'Stop' | |
| $hamlibRoot = $env:HAMLIB_ROOT | |
| Write-Host "Fixing hamlib import library at: $hamlibRoot" | |
| # Find the DLL | |
| $dllPath = Get-ChildItem -Path (Join-Path $hamlibRoot 'bin') -Filter 'libhamlib-*.dll' | Select-Object -First 1 | |
| if (-not $dllPath) { | |
| Write-Error "libhamlib DLL not found in $hamlibRoot/bin" | |
| exit 1 | |
| } | |
| Write-Host "Found DLL: $($dllPath.FullName)" | |
| # Generate .def file from DLL | |
| $defPath = Join-Path $env:RUNNER_TEMP 'libhamlib-4.def' | |
| $libPath = Join-Path $hamlibRoot 'lib/libhamlib-4.lib' | |
| Write-Host "Generating .def file..." | |
| $exports = dumpbin /exports $dllPath.FullName | |
| # Parse exports and create .def file | |
| $defHeader = "LIBRARY libhamlib-4.dll`nEXPORTS`n" | |
| $defContent = $defHeader | |
| $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+)') { | |
| $funcName = $matches[1] | |
| $defContent += " $funcName`n" | |
| } | |
| } | |
| Set-Content -Path $defPath -Value $defContent -Encoding ASCII | |
| $exportCount = ($defContent -split "`n").Count - 3 | |
| Write-Host "Generated .def file with $exportCount exports" | |
| # Create lib directory if it doesn't exist | |
| $libDir = Join-Path $hamlibRoot 'lib' | |
| if (-not (Test-Path $libDir)) { | |
| New-Item -ItemType Directory -Path $libDir -Force | Out-Null | |
| } | |
| # Generate import library using lib.exe | |
| Write-Host "Generating import library..." | |
| lib /def:$defPath /out:$libPath /machine:x64 | |
| if (Test-Path $libPath) { | |
| $libSize = (Get-Item $libPath).Length | |
| Write-Host "Successfully created import library: $libPath" | |
| Write-Host "Library size: $libSize bytes" | |
| } else { | |
| Write-Error "Failed to create import library" | |
| exit 1 | |
| } | |
| - name: Generate prebuilds (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: node scripts/run-prebuildify.js | |
| - name: Bundle dependencies (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: node scripts/bundle-windows.js | |
| - name: Generate prebuilds (macOS) | |
| if: matrix.os == 'macos-latest' | |
| run: npm run prebuild | |
| - name: Bundle dependencies (macOS) | |
| if: matrix.os == 'macos-latest' | |
| run: bash scripts/bundle-macos.sh | |
| - name: Generate prebuilds (Linux) | |
| if: startsWith(matrix.os, 'ubuntu') | |
| run: npm run prebuild | |
| - name: Bundle dependencies (Linux) | |
| if: startsWith(matrix.os, 'ubuntu') | |
| run: bash scripts/bundle-linux.sh | |
| - name: List generated prebuilds | |
| shell: bash | |
| run: | | |
| echo "Generated prebuilds:" | |
| find prebuilds -maxdepth 2 -type f \( -name "*.node" -o -name "*.so*" -o -name "*.dylib" -o -name "*.dll" \) -print || true | |
| - name: Verify dependencies (All platforms) | |
| run: node scripts/verify-dependencies.js | |
| # 上传每个平台的预编译产物 | |
| - name: Upload platform prebuilds artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: prebuilds-${{ matrix.target }} | |
| path: prebuilds/** | |
| retention-days: 1 # 只保留1天,因为最终会合并 | |
| # 收集所有平台构建产物并统一打包 | |
| package: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Prepare prebuilds directory | |
| run: | | |
| mkdir -p prebuilds | |
| echo "Prepared prebuilds directory for collecting platform prebuilds" | |
| # 下载所有平台的构建产物 | |
| - name: Download linux-x64 prebuilds | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: prebuilds-linux-x64 | |
| path: prebuilds | |
| - name: Download linux-arm64 prebuilds | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: prebuilds-linux-arm64 | |
| path: prebuilds | |
| - name: Download darwin-arm64 prebuilds | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: prebuilds-darwin-arm64 | |
| path: prebuilds | |
| - name: Flatten prebuilds directory | |
| shell: bash | |
| run: | | |
| if [ -d prebuilds/prebuilds ]; then | |
| echo "Flattening nested prebuilds directory..." | |
| shopt -s dotglob nullglob || true | |
| mv prebuilds/prebuilds/* prebuilds/ || true | |
| rm -rf prebuilds/prebuilds || true | |
| fi | |
| - name: Debug list prebuilds | |
| run: | | |
| echo "Listing prebuilds content before verify:" | |
| find prebuilds -maxdepth 4 -type f -print | sort || true | |
| - name: Download win32-x64 prebuilds | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: prebuilds-win32-x64 | |
| path: prebuilds | |
| - name: Verify collected prebuilds | |
| run: node .github/scripts/verify-build.js | |
| - name: Create unified prebuilds package | |
| 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" ] && [ "$(basename "$dir")" != "BUILD_INFO.txt" ]; then | |
| platform=$(basename "$dir") | |
| echo "- $platform" >> prebuilds/BUILD_INFO.txt | |
| fi | |
| done | |
| echo "" >> prebuilds/BUILD_INFO.txt | |
| echo "Installation: Extract to your project's prebuilds/ directory" >> prebuilds/BUILD_INFO.txt | |
| # 创建统一的zip包 | |
| cd prebuilds | |
| zip -r ../node-hamlib-prebuilds.zip . -x "*.DS_Store" "*/.*" | |
| cd .. | |
| echo "📦 Created unified package: node-hamlib-prebuilds.zip" | |
| ls -la node-hamlib-prebuilds.zip | |
| - name: Generate package summary | |
| id: package_info | |
| run: | | |
| PACKAGE_SIZE=$(ls -la node-hamlib-prebuilds.zip | awk '{print $5}') | |
| PLATFORM_COUNT=$(find prebuilds -name "*.node" | wc -l) | |
| echo "package_size=$PACKAGE_SIZE" >> $GITHUB_OUTPUT | |
| echo "platform_count=$PLATFORM_COUNT" >> $GITHUB_OUTPUT | |
| echo "build_date=$(date -u)" >> $GITHUB_OUTPUT | |
| # 上传最终的统一包 | |
| - name: Upload unified prebuilds package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: node-hamlib-prebuilds | |
| path: node-hamlib-prebuilds.zip | |
| retention-days: 90 | |
| # 如果是标签推送,创建GitHub Release | |
| - name: Create GitHub Release (on tags) | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: ${{ github.ref_name }} | |
| name: "Node-HamLib ${{ github.ref_name }}" | |
| draft: false | |
| prerelease: false | |
| artifacts: node-hamlib-prebuilds.zip | |
| body: | | |
| # Node-HamLib ${{ github.ref_name }} | |
| ## 📦 Precompiled Binaries Package | |
| This release includes precompiled binaries for multiple platforms: | |
| **Platforms included:** 4 platforms (Linux x64/ARM64, macOS ARM64, Windows x64) | |
| **Package size:** ${{ steps.package_info.outputs.package_size }} bytes | |
| **Build date:** ${{ steps.package_info.outputs.build_date }} | |
| ### Installation | |
| 1. Download `node-hamlib-prebuilds.zip` | |
| 2. Extract to your project's `prebuilds/` directory | |
| 3. The binaries will be automatically detected and used | |
| ### Supported Platforms | |
| - ✅ Linux x64 | |
| - ✅ Linux ARM64 | |
| - ✅ macOS ARM64 (Apple Silicon) | |
| - ✅ Windows x64 | |
| ### Usage | |
| ```bash | |
| npm install node-hamlib | |
| ``` | |
| The precompiled binaries will be automatically used if available for your platform, otherwise it will fall back to building from source. | |
| # 清理临时artifacts(可选) | |
| cleanup: | |
| needs: [build, package] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Delete temporary platform artifacts | |
| uses: geekyeggo/delete-artifact@v5 | |
| with: | |
| name: | | |
| prebuilds-linux-x64 | |
| prebuilds-linux-arm64 | |
| prebuilds-darwin-arm64 | |
| prebuilds-win32-x64 | |
| failOnError: false |