name: Publish JS SDK

on:
  push:
    branches:
      - main
    paths:
      - apps/js-sdk/firecrawl/package.json

env:
  TEST_API_KEY: ${{ secrets.TEST_API_KEY }}

jobs:
  publish:
    name: Publish
    runs-on: blacksmith-2vcpu-ubuntu-2404
    steps:
      - uses: actions/checkout@v5
      - name: Install pnpm
        uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4
        with:
          version: 10
      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: "pnpm"
          cache-dependency-path: './apps/js-sdk/firecrawl/pnpm-lock.yaml'
      - name: Authenticate
        run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      - name: Publish
        run: |
          pnpm install
          pnpm run build
          pnpm publish --access public --no-git-checks
          sed -i 's/"name": "@mendable\/firecrawl-js"/"name": "@mendable\/firecrawl"/g' package.json
          pnpm publish --access public --no-git-checks
          sed -i 's/"name": "@mendable\/firecrawl"/"name": "firecrawl"/g' package.json
          sed -i '/"firecrawl":/d' package.json
          pnpm publish --access public --no-git-checks
        working-directory: ./apps/js-sdk/firecrawl
