name: Publish branch package

on:
  workflow_dispatch:
    inputs:
      commit_hash:
        description: 'SHA-1 hash of the commit to publish'
        required: true

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref }}
  cancel-in-progress: true

permissions:
  contents: read
  pull-requests: write

jobs:
  publish-branch-package:
    runs-on: ubuntu-22.04
    timeout-minutes: 5
    steps:
      - name: Check out Git repository
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          ref: ${{ github.event.inputs.commit_hash || github.event.pull_request.head.sha || github.sha }}

      - name: Install Node and npm packages
        uses: ./.github/actions/setup-node-env

      - name: Publish branch package to npm
        uses: wistia/publish-branch-to-npm@b0e3b0aa93e1b6ab1a305d0f61653e78cecbc87a # v2.3.6
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          npm_token: ${{ secrets.NPM_AUTH_TOKEN }}
          commit_hash: ${{ github.event.inputs.commit_hash || github.event.pull_request.head.sha || github.sha }}
