# This GitHub Actions workflow automates the deployment of an NPM package upon pushes to the main branch.

name: Deploy (main branch)

on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: deploy
    environment: production
    runs-on: ubuntu-latest

    env:
      GIT_COMMITTER_NAME: github-actions[bot]
      GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
      GIT_AUTHOR_NAME: github-actions[bot]
      GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0 # Fetch Depth 0 ensures that backmerging to develop will work a few steps later.

      - name: Setup Node Version ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          registry-url: 'https://registry.npmjs.org'

      - name: Publish if version has been updated
        uses: pascalgn/npm-publish-action@1.3.9
        env: 
          NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # You need to set this in your repo settings
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated
