Files
actions/npm-publish/action.yml

76 lines
2.0 KiB
YAML

---
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
name: Publish to NPM
description: 'Publishes the package to the NPM registry with configurable scope and registry URL.'
author: 'Ismo Vuorinen'
branding:
icon: package
color: green
inputs:
registry-url:
description: 'Registry URL for publishing.'
required: false
default: 'https://registry.npmjs.org/'
scope:
description: 'Package scope to use.'
required: false
default: '@ivuorinen'
package-version:
description: 'The version to publish.'
required: false
default: ${{ github.event.release.tag_name }}
npm_token:
description: 'NPM token.'
required: true
default: ''
outputs:
registry-url:
description: 'Registry URL for publishing.'
value: ${{ inputs.registry-url }}
scope:
description: 'Package scope to use.'
value: ${{ inputs.scope }}
package-version:
description: 'The version to publish.'
value: ${{ inputs.package-version }}
npm_token:
description: 'NPM token.'
value: ${{ inputs.token }}
runs:
using: composite
steps:
- name: Setup Node.js
uses: ivuorinen/actions/node-setup@main
- name: Authenticate NPM
shell: bash
run: |
echo "//${{ inputs.registry-url }}/:_authToken=${{ inputs.npm_token }}" > ~/.npmrc
- name: Publish Package
shell: bash
env:
NPM_TOKEN: ${{ inputs.npm_token }}
run: |
pkg_version=$(node -p "require('./package.json').version")
if [ "$pkg_version" != "${{ inputs.package-version }}" ]; then
echo "Version mismatch: package.json ($pkg_version) != input (${{ inputs.package-version }})"
exit 1
fi
# Dry run first
npm publish \
--registry ${{ inputs.registry-url }} \
--dry-run \
--scope ${{ inputs.scope }}
npm publish \
--registry ${{ inputs.registry-url }} \
--verbose \
--scope ${{ inputs.scope }} \
--tag ${{ inputs.package-version }}