# This workflow will install Node.js dependencies and publish to npm

name: Publish

on:
  push:
    tags: "*"

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - name: Check out
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Get tag version
        if: startsWith(github.ref, 'refs/tags/')
        id: get_tag_version
        run: echo TAG_VERSION=${GITHUB_REF/refs\/tags\//} >> $GITHUB_OUTPUT
      - uses: actions/setup-node@v4
        with:
          node-version: "22.x"
          registry-url: "https://registry.npmjs.org"
      - name: Install dependencies
        run: npm ci
      - name: Run checks
        run: npm test
      - name: Build
        run: npm run build
      - name: Publish to npm
        if: startsWith(github.ref, 'refs/tags/')
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npm publish --access public
