Skip to content

Publish

Publish #8

Workflow file for this run

name: Publish
on:
workflow_dispatch:
inputs:
bump:
description: "Version bump type (ignored if version is set)"
required: false
type: choice
default: "patch"
options:
- patch
- minor
- major
- none
version:
description: "Custom version (e.g. 1.2.3) — overrides bump"
required: false
type: string
default: ""
tag:
description: "npm dist-tag (default: latest)"
required: false
type: string
default: "latest"
dry_run:
description: "Dry run — bump the version but do not publish"
required: false
type: boolean
default: false
permissions:
contents: write
id-token: write
jobs:
publish:
name: Build & Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Install deps
run: pnpm install --frozen-lockfile
- name: Determine target version
id: version
# Compute the next version in pure bash against the CLI subpackage.
# `npm version --dry-run` mutates package.json in npm 11.x, so we
# don't use it.
run: |
set -euo pipefail
CURRENT=$(node -p "require('./packages/cli/package.json').version")
bump_semver() {
local ver="$1" kind="$2"
local core="${ver%%-+}"
core="${core#v}"
local IFS='.'
read -r major minor patch <<< "$core"
case "$kind" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
*) echo "::error::Unknown bump kind: $kind" >&2; return 1 ;;
esac
printf '%d.%d.%d' "$major" "$minor" "$patch"
}
if [ -n "${{ inputs.version }}" ]; then
TARGET="${{ inputs.version }}"
BUMP_KIND="custom"
elif [ "${{ inputs.bump }}" != "none" ]; then
TARGET=$(bump_semver "$CURRENT" "${{ inputs.bump }}")
BUMP_KIND="${{ inputs.bump }}"
else
TARGET="$CURRENT"
BUMP_KIND="none"
fi
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
echo "target=$TARGET" >> "$GITHUB_OUTPUT"
echo "bump=$BUMP_KIND" >> "$GITHUB_OUTPUT"
- name: Bump version in packages/cli/package.json
if: steps.version.outputs.target != steps.version.outputs.current
run: |
set -euo pipefail
cd packages/cli
npm version "${{ steps.version.outputs.target }}" --no-git-tag-version --workspaces=false
- name: Build
run: pnpm --filter @iamcoder18/huly-cli build
- name: Publish to npm
if: ${{ !inputs.dry_run }}
# OIDC trusted publishing — npm exchanges a short-lived GitHub
# OIDC token for a publish token. No NPM_TOKEN secret required.
run: |
set -euo pipefail
pnpm publish --filter @iamcoder18/huly-cli --access public --tag "${{ inputs.tag }}" --no-git-checks
- name: Commit & tag version bump
if: ${{ !inputs.dry_run && steps.version.outputs.target != steps.version.outputs.current }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add packages/cli/package.json pnpm-lock.yaml
git commit -m "chore(release): v${{ steps.version.outputs.target }}"
git tag "v${{ steps.version.outputs.target }}"
git push
git push --tags
- name: Summary
if: always()
run: |
{
echo "### Publish summary"
echo
echo "- Previous version: \`${{ steps.version.outputs.current }}\`"
echo "- Target version: \`${{ steps.version.outputs.target }}\`"
echo "- Bump kind: \`${{ steps.version.outputs.bump }}\`"
echo "- Tag: \`${{ inputs.tag }}\`"
echo "- Dry run: \`${{ inputs.dry_run }}\`"
} >> "$GITHUB_STEP_SUMMARY"