name: Publish to npm

# Controls when the action will run.  
# In this case, I'm saying on each release event when it's specifically a new release publish, the types: [published] is required here, 
# since releases could also be updated or deleted, we only want to publish to npm when a new release is created (published).
on:
  release:
    types: [published, edited]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v2
    #Install Node.js, with the version 14 and using the registry URL of npm, this could be changed to a custom registry or the GitHub registry.
    - uses: actions/setup-node@v1
      with:
        node-version: 14
        registry-url: https://registry.npmjs.org/
      
    # Publish to npm
    - run: npm publish --access public
      env:
        NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
