Build Native Modules #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: Build Native Modules | |
| on: | |
| # Trigger after CI workflow completes successfully | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: | |
| - completed | |
| branches: [main, master] | |
| # Also trigger on version tags (for releases) | |
| push: | |
| tags: | |
| - 'v*' | |
| env: | |
| APP_NAME: opencontext-node | |
| MACOSX_DEPLOYMENT_TARGET: '10.13' | |
| defaults: | |
| run: | |
| working-directory: crates/opencontext-node | |
| jobs: | |
| build: | |
| name: Build - ${{ matrix.settings.target }} | |
| runs-on: ${{ matrix.settings.host }} | |
| # Only run if CI succeeded (for workflow_run trigger) or if it's a tag push | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'push' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| settings: | |
| # macOS | |
| - host: macos-latest | |
| target: x86_64-apple-darwin | |
| build: npm run build -- --target x86_64-apple-darwin | |
| - host: macos-latest | |
| target: aarch64-apple-darwin | |
| build: npm run build -- --target aarch64-apple-darwin | |
| # Windows | |
| - host: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| build: npm run build -- --target x86_64-pc-windows-msvc | |
| - host: windows-latest | |
| target: aarch64-pc-windows-msvc | |
| build: npm run build -- --target aarch64-pc-windows-msvc | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| cache-dependency-path: crates/opencontext-node/package-lock.json | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.settings.target }} | |
| - name: Cache Rust | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| workspaces: crates/opencontext-node -> target | |
| key: ${{ matrix.settings.target }} | |
| - name: Install Protobuf (macOS) | |
| if: runner.os == 'macOS' | |
| run: brew install protobuf | |
| working-directory: . | |
| - name: Install Protobuf (Windows) | |
| if: runner.os == 'Windows' | |
| run: choco install protoc -y | |
| working-directory: . | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build native module | |
| run: ${{ matrix.settings.build }} | |
| shell: bash | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: bindings-${{ matrix.settings.target }} | |
| path: crates/opencontext-node/*.node | |
| if-no-files-found: error | |
| # Publish to npm when tag is pushed | |
| publish: | |
| name: Publish to npm | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: https://registry.npmjs.org/ | |
| - name: Install dependencies | |
| run: npm ci | |
| working-directory: crates/opencontext-node | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: crates/opencontext-node/artifacts | |
| - name: Move artifacts | |
| run: | | |
| cd crates/opencontext-node | |
| npm run artifacts | |
| shell: bash | |
| - name: List packages | |
| run: ls -la npm | |
| working-directory: crates/opencontext-node | |
| - name: Publish native packages | |
| run: | | |
| cd crates/opencontext-node | |
| npm run prepublishOnly | |
| for dir in npm/*/; do | |
| cd "$dir" | |
| npm publish --access public || true | |
| cd ../.. | |
| done | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Publish main package | |
| run: | | |
| cd crates/opencontext-node | |
| npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |