# NPM Publish is the name for this action
name: NPM Publish Main

# This action will trigger on every release get created
on:
  push:
    branches: [main]

# Job will run on a ubuntu instance
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # Checkout the code
      - uses: actions/checkout@v2
      # Setup node with version 14.x and NPM registry url
      - uses: actions/setup-node@v2
        with:
          node-version: '14.x'
          registry-url: 'https://registry.npmjs.org'
      # Run npm install to install project packages
      - run: npm install
      # tests
      - run: npm test
        env:
          FAUNA_ADMIN_KEY: ${{ secrets.FAUNA_ADMIN_KEY_MAIN }}
      # npm build to build the project
      - run: npm build
      # publish the files to NPM
      - run: npm publish --access public
        # for publishing, npm need authorization. We add the NPM token to the environment which will take care of authorization to publish to the package
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
