Skip to content

Publish to npm

Publish to npm #7

Workflow file for this run

name: Publish to npm
on:
workflow_dispatch:
inputs:
version:
description: "Version to publish (e.g., 0.1.0, 0.2.0-beta)"
required: false
default: ""
tag:
description: "NPM tag (e.g., latest, dev)"
required: false
default: "dev"
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
registry-url: "https://registry.npmjs.org/"
scope: "@bytebase"
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: latest
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm run build
- name: Update package.json for npm publishing
run: |
# Get the current version from package.json
CURRENT_VERSION=$(jq -r '.version' package.json)
# Use input version if provided, otherwise use current version
if [ -n "${{ inputs.version }}" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${CURRENT_VERSION}"
fi
echo "Publishing version: ${VERSION} with tag: ${{ inputs.tag }}"
# Update package.json to use @bytebase scope and set version
jq --arg version "$VERSION" '.name = "@bytebase/dbhub" | .version = $version' package.json > package.json.tmp
mv package.json.tmp package.json
# Set files to include in the package
jq '.files = ["dist/**/*", "LICENSE", "README.md"]' package.json > package.json.tmp
mv package.json.tmp package.json
# Add bin entry for CLI usage
jq '.bin = {"dbhub": "dist/index.js"}' package.json > package.json.tmp
mv package.json.tmp package.json
- name: Publish to npm
run: pnpm publish --no-git-checks --access public --tag ${{ inputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}