Publish to npm #4
Workflow file for this run
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: Publish to npm | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| publish_target: | |
| description: 'Publish target' | |
| required: true | |
| default: 'dry-run' | |
| type: choice | |
| options: | |
| - dry-run | |
| - npm | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| build: | |
| name: Build - ${{ matrix.target }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| - os: macos-13 | |
| target: x86_64-apple-darwin | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| - os: ubuntu-latest | |
| target: aarch64-unknown-linux-gnu | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Checkout nono library | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| repository: always-further/nono | |
| path: nono | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7 # stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install system dependencies (Linux) | |
| if: runner.os == 'Linux' | |
| run: sudo apt-get update && sudo apt-get install -y libdbus-1-dev pkg-config | |
| - name: Install cross-compilation tools (aarch64-linux) | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: sudo apt-get install -y gcc-aarch64-linux-gnu | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| with: | |
| node-version: 22 | |
| - run: npm ci | |
| - name: Build native module | |
| run: | | |
| if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then | |
| export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc | |
| fi | |
| npx napi build --platform --release --target ${{ matrix.target }} | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: bindings-${{ matrix.target }} | |
| path: "*.node" | |
| if-no-files-found: error | |
| publish: | |
| name: Publish to npm | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_target == 'npm') | |
| environment: | |
| name: npm | |
| url: https://www.npmjs.com/package/nono-ts | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| with: | |
| node-version: 22 | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| pattern: bindings-* | |
| path: artifacts | |
| merge-multiple: true | |
| - run: npm ci | |
| - name: Move artifacts into platform packages | |
| run: npx napi artifacts --output-dir artifacts --npm-dir npm | |
| - name: List platform packages | |
| run: | | |
| for dir in npm/*/; do | |
| echo "=== $dir ===" | |
| ls -la "$dir" | |
| done | |
| - name: Publish platform packages | |
| run: | | |
| for dir in npm/*/; do | |
| if [ -f "$dir/package.json" ]; then | |
| echo "Publishing $dir..." | |
| npm publish "$dir" --provenance --access public | |
| fi | |
| done | |
| - name: Publish main package | |
| run: npm publish --provenance --access public | |
| dry-run: | |
| name: Dry run (no publish) | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.publish_target == 'dry-run' | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| with: | |
| node-version: 22 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| pattern: bindings-* | |
| path: artifacts | |
| merge-multiple: true | |
| - run: npm ci | |
| - name: Move artifacts into platform packages | |
| run: npx napi artifacts --output-dir artifacts --npm-dir npm | |
| - name: List platform packages | |
| run: | | |
| for dir in npm/*/; do | |
| echo "=== $dir ===" | |
| ls -la "$dir" | |
| done | |
| - name: Dry run publish (platform packages) | |
| run: | | |
| for dir in npm/*/; do | |
| if [ -f "$dir/package.json" ]; then | |
| echo "Dry run: $dir" | |
| npm publish "$dir" --dry-run --access public | |
| fi | |
| done | |
| - name: Dry run publish (main package) | |
| run: npm publish --dry-run --access public |