name: Publish Package to npmjs
on:
  # Runs when release activity occurs.
  release:
    types: [published]
jobs:
  test:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [20.x]

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}

      - name: Install packages
        run: yarn

      - name: Compile code
        run: yarn build:clean

      - name: Format
        run: yarn format:check

      - name: Lint
        run: yarn lint

      - name: Test
        run: yarn test

  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      # Setup .npmrc file to publish to npm
      - uses: actions/setup-node@v3
        with:
          node-version: "20.x"
          registry-url: "https://registry.npmjs.org"
      - run: yarn
      - run: yarn build:clean
      - run: yarn publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
