name: Continuous deployment

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  publish_npm:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
      - name: Set .npmrc
        run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

      - name: Checkout the repo
        uses: actions/checkout@v3

      - name: Publish to NPM
        run: npm publish # This will fail w/ if the version number in package.json is not updated (i.e. if same as on npm)
  deploy_github_pages:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    needs: [publish_npm]
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3

      - name: Install packages
        run: npm install

      - name: Build docs
        run: npm run typedoc

      - name: Deploy documentation to GitHub Pages
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: docs
