ci: fix prebuild workflow to handle submodules and publish #2
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 Prebuilds | |
| on: | |
| push: | |
| branches: [main, master] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - run: npm install | |
| - run: npx prebuildify --napi --strip || echo "Prebuildify failed, prebuilds may already exist" | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: prebuilds-${{ matrix.os }} | |
| path: prebuilds/ | |
| if-no-files-found: ignore | |
| publish: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| registry-url: https://registry.npmjs.org | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - run: | | |
| mkdir -p prebuilds | |
| find artifacts -name "*.node" -exec sh -c 'cp "$1" prebuilds/$(basename $(dirname "$1"))/' _ {} \; | |
| - run: npm install | |
| - run: npm version patch | |
| - run: git push && git push --tags | |
| - run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |