name: Publish to NPM
description: Publish js-eventsource to NPM.
inputs:
  prerelease:
    description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.'
    required: true
  dry_run:
    description: 'Is this a dry run. If so no package will be published.'
    required: true

runs:
  using: composite
  steps:
    - name: Publish
      shell: bash
      run: |
        if $LD_RELEASE_IS_DRYRUN ; then
          # Dry run just pack the workspace.
          echo "Doing a dry run of publishing."
        else
          if $LD_RELEASE_IS_PRERELEASE ; then
            echo "Publishing with prerelease tag."
            npm publish --tag prerelease --provenance --access public || { echo "npm publish failed" >&2; exit 1; }
          else
            npm publish --provenance --access public || { echo "npm publish failed" >&2; exit 1; }
          fi
        fi
      env:
        LD_RELEASE_IS_PRERELEASE: ${{ inputs.prerelease }}
        LD_RELEASE_IS_DRYRUN: ${{ inputs.dry_run }}
