---
name: Publish Nodejs DAL Client

on:
  push:
    tags:
      - '**service-dal-grpc-client**' # client published when tag created (ex. @pluto-tv/service-dal-grpc-client@1.14.0)

jobs:
  Publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-node@v5
        with:
          node-version: 22.11.0
      - uses: actions/checkout@v5
      - uses: ./.github/actions/setup-ssh
        with:
          key: ${{ secrets.PLUTO_DEPLOY_SSH_KEY }}
      - name: NPM Configure
        env:
          NPM_TOKEN: ${{ secrets.GH_PKG_REPO_TOKEN }}
        run: |
          echo '@pluto-tv:registry=https://npm.pkg.github.com/' > "$HOME/.npmrc"
          echo "//npm.pkg.github.com/:_authToken=${NPM_TOKEN}" >> "$HOME/.npmrc"
          pwd
      - name: Publish NPM Package
        env:
          NPM_TOKEN: ${{ secrets.GH_PKG_REPO_TOKEN }}
        run: |
          env
          npm run client:nodejs:publish
      - name: Check Publish Status
        if: ${{ failure() }}
        run: |
          echo "Error: Failed to publish Node client package."
          exit 1
