Skip to content

Publish npm

Publish npm #72

Workflow file for this run

name: Publish npm
on:
workflow_dispatch:
inputs:
force_update:
description: "Check and publish only if @firfi/huly-mcp has a newer version"
required: true
default: true
type: boolean
schedule:
- cron: "17 2 * * *"
permissions:
contents: write
id-token: write
concurrency:
group: publish-npm
cancel-in-progress: false
jobs:
publish:
name: Update huly-mcp and publish npm package
runs-on: ubuntu-latest
env:
HULY_MCP_PACKAGE: "@firfi/huly-mcp"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Setup pnpm
run: |
corepack enable
corepack prepare pnpm@10.29.3 --activate
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check versions
id: versions
shell: bash
run: |
set -euo pipefail
package_name="$(node -p "require('./package.json').name")"
current="$(node -p "require('./package.json').version")"
current_mcp="$(node -p "require('./package.json').dependencies[process.env.HULY_MCP_PACKAGE]")"
current_mcp="${current_mcp#^}"
current_mcp="${current_mcp#~}"
latest_mcp="$(npm view "$HULY_MCP_PACKAGE" version)"
echo "package_name=$package_name" >> "$GITHUB_OUTPUT"
echo "current=$current" >> "$GITHUB_OUTPUT"
echo "current_mcp=$current_mcp" >> "$GITHUB_OUTPUT"
echo "latest_mcp=$latest_mcp" >> "$GITHUB_OUTPUT"
echo "$package_name current CLI version: $current"
if [ "$current_mcp" = "$latest_mcp" ]; then
echo "mcp_update_available=false" >> "$GITHUB_OUTPUT"
echo "$HULY_MCP_PACKAGE is already up to date: $current_mcp"
else
echo "mcp_update_available=true" >> "$GITHUB_OUTPUT"
echo "$HULY_MCP_PACKAGE update available: $current_mcp -> $latest_mcp"
fi
- name: Stop when huly-mcp is current
if: steps.versions.outputs.mcp_update_available != 'true'
run: echo "@firfi/huly-mcp is already current; no CLI release needed."
- name: Update huly-mcp dependency
if: steps.versions.outputs.mcp_update_available == 'true'
run: pnpm add "$HULY_MCP_PACKAGE@${{ steps.versions.outputs.latest_mcp }}" --save-exact
- name: Determine CLI bump type
if: steps.versions.outputs.mcp_update_available == 'true'
id: bump_type
shell: bash
run: |
set -euo pipefail
current="${{ steps.versions.outputs.current_mcp }}"
latest="${{ steps.versions.outputs.latest_mcp }}"
current_major="${current%%.*}"
latest_major="${latest%%.*}"
current_rest="${current#*.}"
latest_rest="${latest#*.}"
current_minor="${current_rest%%.*}"
latest_minor="${latest_rest%%.*}"
if [ "$current_major" != "$latest_major" ]; then
bump_type="major"
elif [ "$current_minor" != "$latest_minor" ]; then
bump_type="minor"
else
bump_type="patch"
fi
echo "value=$bump_type" >> "$GITHUB_OUTPUT"
echo "MCP update $current -> $latest maps to CLI $bump_type release."
- name: Bump package version
if: steps.versions.outputs.mcp_update_available == 'true'
id: bump
shell: bash
run: |
set -euo pipefail
bump_type="${{ steps.bump_type.outputs.value }}"
npm version "$bump_type" --no-git-tag-version
version="$(node -p "require('./package.json').version")"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Bumped to $version"
- name: Verify package
if: steps.versions.outputs.mcp_update_available == 'true'
run: pnpm check
- name: Commit version bump
if: steps.versions.outputs.mcp_update_available == 'true'
shell: bash
run: |
set -euo pipefail
version="${{ steps.bump.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if ! git diff --quiet -- package.json pnpm-lock.yaml; then
git add package.json pnpm-lock.yaml
git commit -m "chore(release): v$version [skip ci]"
fi
if ! git rev-parse "v$version" >/dev/null 2>&1; then
git tag -a "v$version" -m "Release v$version"
fi
git push origin HEAD:main "v$version"
- name: Publish to npm
if: steps.versions.outputs.mcp_update_available == 'true'
run: pnpm publish --access public --provenance --no-git-checks
- name: Create GitHub release
if: steps.versions.outputs.mcp_update_available == 'true'
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
version="${{ steps.bump.outputs.version }}"
tag="v$version"
notes="Published @starhui/huly-cli@$version to npm."
if [ "${{ steps.versions.outputs.mcp_update_available }}" = "true" ]; then
notes="$notes\n\nUpdated @firfi/huly-mcp from ${{ steps.versions.outputs.current_mcp }} to ${{ steps.versions.outputs.latest_mcp }}."
fi
if gh release view "$tag" >/dev/null 2>&1; then
gh release edit "$tag" --title "$tag" --latest --notes "$notes"
else
gh release create "$tag" --title "$tag" --latest --notes "$notes"
fi