name: publish_npm

on:
  release:
    types: [published]
  workflow_dispatch:

jobs:
  publish_npm:
    runs-on: ubuntu-22.04

    steps:
    - uses: actions/checkout@v4

    - name: Setup Node
      uses: actions/setup-node@v4
      with:
        node-version: 20
        registry-url: 'https://registry.npmjs.org'

    - name: Download built examples
      uses: dawidd6/action-download-artifact@v6
      with:
        workflow: manifold.yml
        workflow_conclusion: completed
        branch: master
        check_artifacts: true
        name: wasm
        path: ./bindings/wasm/

    - name: Publish to npm
      run: |
        cd ./bindings/wasm/
        npm publish
      env:
        NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
