name: Node.js Package

on:
  release:
    types: [created]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - run: npm ci
      - run: npm test
      - run: npm run build
      - uses: actions/upload-artifact@v3
        with:
          name: dist
          path: dist
      - uses: actions/upload-artifact@v3
        with:
          name: types
          path: types

  publish-npm:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          registry-url: https://registry.npmjs.org/
      - uses: actions/download-artifact@v3
        with:
          name: dist
          path: dist
      - uses: actions/download-artifact@v3
        with:
          name: types
          path: types
      - run: npm ci
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}
