|
| 1 | +name: Build Native Modules |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + tags: |
| 7 | + - 'v*' |
| 8 | + pull_request: |
| 9 | + branches: [main, master] |
| 10 | + |
| 11 | +env: |
| 12 | + APP_NAME: opencontext-node |
| 13 | + MACOSX_DEPLOYMENT_TARGET: '10.13' |
| 14 | + |
| 15 | +defaults: |
| 16 | + run: |
| 17 | + working-directory: crates/opencontext-node |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + name: Build - ${{ matrix.settings.target }} |
| 22 | + runs-on: ${{ matrix.settings.host }} |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + settings: |
| 27 | + # macOS |
| 28 | + - host: macos-latest |
| 29 | + target: x86_64-apple-darwin |
| 30 | + build: npm run build -- --target x86_64-apple-darwin |
| 31 | + - host: macos-latest |
| 32 | + target: aarch64-apple-darwin |
| 33 | + build: npm run build -- --target aarch64-apple-darwin |
| 34 | + |
| 35 | + # Linux |
| 36 | + - host: ubuntu-latest |
| 37 | + target: x86_64-unknown-linux-gnu |
| 38 | + build: npm run build -- --target x86_64-unknown-linux-gnu |
| 39 | + - host: ubuntu-latest |
| 40 | + target: aarch64-unknown-linux-gnu |
| 41 | + build: | |
| 42 | + sudo apt-get update |
| 43 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 44 | + export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc |
| 45 | + npm run build -- --target aarch64-unknown-linux-gnu |
| 46 | + |
| 47 | + # Windows |
| 48 | + - host: windows-latest |
| 49 | + target: x86_64-pc-windows-msvc |
| 50 | + build: npm run build -- --target x86_64-pc-windows-msvc |
| 51 | + - host: windows-latest |
| 52 | + target: aarch64-pc-windows-msvc |
| 53 | + build: npm run build -- --target aarch64-pc-windows-msvc |
| 54 | + |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + |
| 58 | + - name: Setup Node.js |
| 59 | + uses: actions/setup-node@v4 |
| 60 | + with: |
| 61 | + node-version: 20 |
| 62 | + cache: 'npm' |
| 63 | + cache-dependency-path: crates/opencontext-node/package-lock.json |
| 64 | + |
| 65 | + - name: Install Rust |
| 66 | + uses: dtolnay/rust-action@stable |
| 67 | + with: |
| 68 | + targets: ${{ matrix.settings.target }} |
| 69 | + |
| 70 | + - name: Install dependencies |
| 71 | + run: npm ci |
| 72 | + |
| 73 | + - name: Build native module |
| 74 | + run: ${{ matrix.settings.build }} |
| 75 | + shell: bash |
| 76 | + |
| 77 | + - name: Upload artifact |
| 78 | + uses: actions/upload-artifact@v4 |
| 79 | + with: |
| 80 | + name: bindings-${{ matrix.settings.target }} |
| 81 | + path: crates/opencontext-node/*.node |
| 82 | + if-no-files-found: error |
| 83 | + |
| 84 | + # Publish to npm when tag is pushed |
| 85 | + publish: |
| 86 | + name: Publish to npm |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: build |
| 89 | + if: startsWith(github.ref, 'refs/tags/v') |
| 90 | + |
| 91 | + steps: |
| 92 | + - uses: actions/checkout@v4 |
| 93 | + |
| 94 | + - name: Setup Node.js |
| 95 | + uses: actions/setup-node@v4 |
| 96 | + with: |
| 97 | + node-version: 20 |
| 98 | + registry-url: https://registry.npmjs.org/ |
| 99 | + |
| 100 | + - name: Install dependencies |
| 101 | + run: npm ci |
| 102 | + working-directory: crates/opencontext-node |
| 103 | + |
| 104 | + - name: Download all artifacts |
| 105 | + uses: actions/download-artifact@v4 |
| 106 | + with: |
| 107 | + path: crates/opencontext-node/artifacts |
| 108 | + |
| 109 | + - name: Move artifacts |
| 110 | + run: | |
| 111 | + cd crates/opencontext-node |
| 112 | + npm run artifacts |
| 113 | + shell: bash |
| 114 | + |
| 115 | + - name: List packages |
| 116 | + run: ls -la npm |
| 117 | + working-directory: crates/opencontext-node |
| 118 | + |
| 119 | + - name: Publish native packages |
| 120 | + run: | |
| 121 | + cd crates/opencontext-node |
| 122 | + npm run prepublishOnly |
| 123 | + for dir in npm/*/; do |
| 124 | + cd "$dir" |
| 125 | + npm publish --access public || true |
| 126 | + cd ../.. |
| 127 | + done |
| 128 | + env: |
| 129 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 130 | + |
| 131 | + - name: Publish main package |
| 132 | + run: | |
| 133 | + cd crates/opencontext-node |
| 134 | + npm publish --access public |
| 135 | + env: |
| 136 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 137 | + |
0 commit comments