fix(ci): resolve workspace integrity issues and enforce formatting #8
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: Release Node.js SDK | ||
| # Triggered by version tags: v1.2.3 | ||
| on: | ||
| push: | ||
| tags: ["v*.*.*"] | ||
| jobs: | ||
| # --------------------------------------------------------------------------- | ||
| # Build the native .node binary for each platform in parallel | ||
| # --------------------------------------------------------------------------- | ||
| build-native: | ||
| name: Build — ${{ matrix.target }} | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| # Linux x64 (glibc) | ||
| - os: ubuntu-latest | ||
| target: x86_64-unknown-linux-gnu | ||
| artifact: checkgate.linux-x64-gnu.node | ||
| # Linux arm64 (glibc) — cross-compile via napi-rs cross toolchain | ||
| - os: ubuntu-latest | ||
| target: aarch64-unknown-linux-gnu | ||
| artifact: checkgate.linux-arm64-gnu.node | ||
| cross: true | ||
| # Linux x64 (musl — Alpine) — cross-compile via napi-rs cross toolchain | ||
| - os: ubuntu-latest | ||
| target: x86_64-unknown-linux-musl | ||
| artifact: checkgate.linux-x64-musl.node | ||
| cross: true | ||
| # Linux arm64 (musl — Alpine) — zig linker required, no musl aarch64 gcc in napi-cross | ||
| - os: ubuntu-latest | ||
| target: aarch64-unknown-linux-musl | ||
| artifact: checkgate.linux-arm64-musl.node | ||
| zig: true | ||
| # macOS x64 — cross-compile natively from arm64 runner | ||
| - os: macos-latest | ||
| target: x86_64-apple-darwin | ||
| artifact: checkgate.darwin-x64.node | ||
| # macOS arm64 (Apple Silicon) | ||
| - os: macos-latest | ||
| target: aarch64-apple-darwin | ||
| artifact: checkgate.darwin-arm64.node | ||
| # Windows x64 | ||
| - os: windows-latest | ||
| target: x86_64-pc-windows-msvc | ||
| artifact: checkgate.win32-x64-msvc.node | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| targets: ${{ matrix.target }} | ||
| - name: Cache Rust build artifacts | ||
| uses: Swatinem/rust-cache@v2 | ||
| with: | ||
| key: ${{ matrix.target }} | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
| - name: Install @napi-rs/cli | ||
| working-directory: sdks/nodejs | ||
| run: npm install -g @napi-rs/cli | ||
| - name: Install Zig (musl aarch64 only) | ||
| if: matrix.target == 'aarch64-unknown-linux-musl' | ||
| uses: goto-bus-stop/setup-zig@v2 | ||
| with: | ||
| version: 0.13.0 | ||
| - name: Install cargo-zigbuild (musl aarch64 only) | ||
| if: matrix.target == 'aarch64-unknown-linux-musl' | ||
| run: cargo install cargo-zigbuild | ||
| - name: Build | ||
| working-directory: sdks/nodejs | ||
| run: | | ||
| if [ "${{ matrix.target }}" = "aarch64-unknown-linux-musl" ]; then | ||
| # Manual zigbuild to bypass NAPI CLI linker detection | ||
| cargo zigbuild --target aarch64-unknown-linux-musl --release | ||
| mv ../../target/aarch64-unknown-linux-musl/release/libnodejs.so checkgate.linux-arm64-musl.node | ||
| elif [ "${{ matrix.cross }}" = "true" ]; then | ||
| napi build --platform --release --target ${{ matrix.target }} --use-napi-cross | ||
| else | ||
| napi build --platform --release --target ${{ matrix.target }} | ||
| fi | ||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: node-${{ matrix.target }} | ||
| path: sdks/nodejs/${{ matrix.artifact }} | ||
| if-no-files-found: error | ||
| # --------------------------------------------------------------------------- | ||
| # Publish Job — waits for all native builds above | ||
| # --------------------------------------------------------------------------- | ||
| publish: | ||
| name: Publish to npm | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
| registry-url: https://registry.npmjs.org | ||
| - name: Download all native artifacts | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: node-* | ||
| merge-multiple: true | ||
| path: sdks/nodejs/ | ||
| - name: Validate native binaries count | ||
| working-directory: sdks/nodejs | ||
| run: | | ||
| COUNT=$(ls *.node | wc -l) | ||
| echo "Found $COUNT native binaries." | ||
| if [ "$COUNT" -ne 7 ]; then | ||
| echo "Error: Expected 7 native binaries, found $COUNT." | ||
| ls -l *.node | ||
| exit 1 | ||
| fi | ||
| - name: Install dependencies | ||
| working-directory: sdks/nodejs | ||
| run: npm install | ||
| - name: Set version from tag | ||
| working-directory: sdks/nodejs | ||
| run: | | ||
| TAG="${{ github.ref_name }}" | ||
| VERSION="${TAG#v}" | ||
| npm version "$VERSION" --no-git-tag-version --allow-same-version | ||
| - name: Publish @checkgate/node | ||
| working-directory: sdks/nodejs | ||
| run: npm publish --access public | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||