name: Publish Package
description: Publish Package to NPM
inputs:
  token:
    description: NPM PUBLISH AUTOMATION TOKEN
    required: true
  tarball-name:
    description: Tarball name
    required: true
  package-directory:
    description: Package directory
    required: true
outputs:
  type:
    description: Semver release type, `initial` if first release, `different` if other change, or empty if no release.
    value: ${{ steps.publish.outputs.type }}
runs:
  using: composite
  steps:
    - name: Pack
      run: pnpm pack && mv *.tgz ${{ inputs.tarball-name }}.tgz
      shell: bash
      working-directory: ${{ inputs.package-directory }}
    - uses: actions/upload-artifact@v4
      with:
        name: ${{ inputs.tarball-name }}
        path: ${{ inputs.package-directory }}/${{ inputs.tarball-name }}.tgz
    - name: Publish
      id: publish
      uses: octokit/request-action@v2.x
      with:
        route: POST /repos/paritytech/npm_publish_automation/actions/workflows/publish.yml/dispatches
        ref: main
        inputs: '${{ format(''{{ "repo": "{0}", "run_id": "{1}", "artifact_name": "{2}" }}'', github.repository, github.run_id, inputs.tarball-name) }}'
      env:
        GITHUB_TOKEN: ${{ inputs.token }}
