name: Publish `librechat-data-provider` to NPM

on:
  push:
    branches:
      - main
    paths:
      - 'packages/data-provider/package.json'
  workflow_dispatch:
    inputs:
      reason:
        description: 'Reason for manual trigger'
        required: false
        default: 'Manual publish requested'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: cd packages/data-provider && npm ci
      - run: cd packages/data-provider && npm run build

  publish-npm:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          registry-url: 'https://registry.npmjs.org'
      - run: cd packages/data-provider && npm ci
      - run: cd packages/data-provider && npm run build
      - run: cd packages/data-provider && npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
