# Copyright (c) Microsoft Corporation. All rights reserved.
#
name: publish-wasm

permissions:
  pull-requests: write
  contents: write

on:
  workflow_dispatch:

jobs:
  publish-wasm:
    name: publish
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          fetch-depth: 0
      # Setup .npmrc file to publish to npm
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: '20.x'
          registry-url: 'https://registry.npmjs.org'
      - name: Install wasm-pack
        run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
      - name: Build
        run: wasm-pack build --target nodejs --release
        working-directory: ./bindings/wasm
      - name: Publish
        run: wasm-pack publish --target nodejs
        working-directory: ./bindings/wasm
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
