name: Publish Package to npmjs
on:
  release:
    types: [published]
  workflow_dispatch:
    inputs:
      tag:
        description: 'The tag to publish with'
        required: true
        default: 'latest'

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: read
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: "18.x"
          registry-url: "https://registry.npmjs.org"
          scope: "@airdao"

      - run: npm install
      - run: |
          if [ "${{ github.event_name }}" == "release" ]; then
            npm publish --access public
          else
            npm publish --access public --tag ${{ github.event.inputs.tag }}
          fi
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
