name: Publish npm package

on:
  push:
    tags:
      - 'v*.*.*'

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Set version from tag
        run: npm version "${GITHUB_REF_NAME#v}" --no-git-tag-version

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Configure Gitea npm auth
        run: |
          echo "//git.ollyhearn.ru/api/packages/olly/npm/:_authToken=${NODE_AUTH_TOKEN}" >> ~/.npmrc
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

      - name: Publish
        run: npm publish
