name: Publish NPM Package

on:
  push:
    branches:
      - main

jobs:
  release:
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 'lts/*'
          cache: 'npm'

      - name: Install dependencies
        run: npm install

      - name: Configure Git
        run: |
          git config --global user.email "<>"
          git config --global user.name "GitHub Actions"

      - name: Generate version and changelog
        run: |
          npx standard-version
          git push --follow-tags origin main

      - name: Install dependencies
        run: npm run build

      - uses: actions/setup-node@v4
        with:
          node-version: '20.x'
          registry-url: 'https://registry.npmjs.org'

      - run: npm ci
      - run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

