name: Publish Dev Package to npm

on:
  push:
    branches:
      - develop

jobs:
  publish-dev:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          registry-url: 'https://registry.npmjs.org'

      - name: Install dependencies
        run: npm ci --ignore-scripts

      - name: Build
        run: npm run build

      - name: Set dev version
        run: |
          CURRENT_VERSION=$(node -p "require('./package.json').version")
          SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
          DEV_VERSION="${CURRENT_VERSION}-dev.${SHORT_SHA}"
          npm version "$DEV_VERSION" --no-git-tag-version

      - name: Publish to npm with dev tag
        run: npm publish --access public --tag dev
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
