name: Publish React package to npm

on:
  push:
    tags:
      - 'react/v*'

jobs:
  publish:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: frontends/mizan-react
    steps:
      - uses: actions/checkout@v4

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

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Configure Gitea npm registry
        env:
          REGISTRY_URL: ${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/npm/
          PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
        run: |
          npm config set @rythazhur:registry "${REGISTRY_URL}"
          npm config set -- "${REGISTRY_URL#https:}:_authToken" "${PUBLISH_TOKEN}"

      - name: Publish
        run: npm publish
