name: Release prelude
description: >
  Release-job bootstrap — validates BOT_PAT presence (unless dry-run), runs
  setup-workspace with the npm registry URL, and configures git identity.

  IMPORTANT: callers MUST run actions/checkout before this action, using
  fetch-depth=0, persist-credentials=true, and token=BOT_PAT (with GITHUB_TOKEN
  fallback) so the release commit can be pushed back to the protected branch.

inputs:
  dry_run:
    description: When 'true', the BOT_PAT prerequisite check and git identity config are skipped.
    required: true
  bot_pat:
    description: Personal access token with repo scope and branch-protection bypass. Pass secrets.BOT_PAT. Required when dry_run='false'.
    required: false
    default: ''
  node-version:
    description: Node.js version.
    required: false
    default: '22'

runs:
  using: composite
  steps:
    - name: Check release prerequisites
      if: inputs.dry_run != 'true'
      shell: bash
      env:
        BOT_PAT: ${{ inputs.bot_pat }}
      run: |
        set -euo pipefail
        if [[ -z "$BOT_PAT" ]]; then
          echo "::error::BOT_PAT secret is not set. A PAT with repo scope and branch-protection bypass is required to push release commits to the protected main branch."
          exit 1
        fi

    - name: Setup workspace
      uses: ./.github/actions/setup-workspace
      with:
        registry-url: https://registry.npmjs.org
        node-version: ${{ inputs.node-version }}

    - name: Configure git identity
      if: inputs.dry_run != 'true'
      shell: bash
      run: |
        git config user.name 'github-actions[bot]'
        git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
