name: Publish

on:
  push:
    branches:
      - main
    tags:
      - v*

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup Node.js 16.x
        uses: actions/setup-node@v3
        with:
          node-version: 16.x
          registry-url: https://registry.npmjs.org

      - name: Install dependencies
        run: npm install --frozen-lockfile

      - name: Update CHANGELOG
        uses: changesets/action@v1
        with:
          commit: Update CHANGELOG
          title: Update CHANGELOG for Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Publish to NPM
        run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
