Files
kandev/scripts/release/package-npm-runtime.sh
T
José Almeida 8db50791d6 feat(release): unified vX.Y.Z release flow with brew + npm sibling channels
GitHub release artifacts become the canonical build output. npm and Homebrew
are independent sibling channels — both consume the same GitHub release
tarballs; neither depends on the other.

Workflow changes (.github/workflows/release.yml):

- Trigger is now workflow_dispatch only (maintainer-only, gated by repo write
  access). Inputs: bump dropdown (patch/minor/major) + dry_run checkbox.
- Single job graph orchestrates everything in one run:
  prepare (bump, PR, merge, tag) → build-web/build-cli → build-bundles (5
  platforms) → docker → publish-release → publish-npm + update-homebrew-tap.
- The prepare job inlines version bump, optionalDependencies sync, CHANGELOG
  generation, PR create + squash-merge, and tag push. Replaces what
  release-pr.sh used to do locally.
- Tag-push trigger removed; everything runs from the dispatch flow.

New scripts (called by the workflow):

- package-cli.sh: builds + esbuild-bundles the CLI for inclusion in release
  bundles (cli/bin/cli.js + cli/dist/cli.bundle.js + package.json).
- package-npm-runtime.sh: generates per-platform @kdlbs/runtime-* npm
  packages from release bundles. Sets npm os/cpu fields so npm 7+ skips
  non-matching platforms during npx kandev install.
- publish-npm.sh: verifies GitHub assets exist, downloads them, repackages,
  publishes all 5 @kdlbs/runtime-* packages + main kandev@X.Y.Z.
- update-homebrew-tap.sh: clones kdlbs/homebrew-kandev via SSH using the
  HOMEBREW_TAP_DEPLOY_KEY repo secret, generates Formula/kandev.rb pointing
  at the GitHub release assets, pushes directly to main.

Removed scripts:

- release.sh and release-pr.sh — both are redundant with the new workflow.

Required CI secrets:
- NPM_TOKEN: granular access token with publish access to kandev + @kdlbs/*
- HOMEBREW_TAP_DEPLOY_KEY: SSH private key for kdlbs/homebrew-kandev
2026-05-04 22:44:26 +01:00

111 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Generate per-platform npm runtime packages from built dist/release-assets.
#
# Each platform bundle (kandev-{platform}.tar.gz) is repackaged as an npm package
# containing only bin/ and web/ (no cli/). These are the @kdlbs/runtime-* packages
# that the main kandev npm package declares as optionalDependencies.
#
# Usage:
# package-npm-runtime.sh <version> <release-assets-dir> <output-dir>
#
# Arguments:
# version SemVer string (e.g. 0.17.0)
# release-assets-dir Directory containing kandev-*.tar.gz files
# output-dir Directory where per-platform npm packages are written
#
# Output (one directory per platform ready for npm publish):
# <output-dir>/@kdlbs/runtime-linux-x64/
# <output-dir>/@kdlbs/runtime-linux-arm64/
# <output-dir>/@kdlbs/runtime-darwin-x64/
# <output-dir>/@kdlbs/runtime-darwin-arm64/
# <output-dir>/@kdlbs/runtime-win32-x64/
set -euo pipefail
VERSION="${1:?Usage: $0 <version> <release-assets-dir> <output-dir>}"
ASSETS_DIR="${2:?Usage: $0 <version> <release-assets-dir> <output-dir>}"
OUT_DIR="${3:?Usage: $0 <version> <release-assets-dir> <output-dir>}"
# Maps platform dir name → npm package name + npm os/cpu fields
declare -A PLATFORM_TO_PACKAGE=(
["linux-x64"]="@kdlbs/runtime-linux-x64"
["linux-arm64"]="@kdlbs/runtime-linux-arm64"
["macos-x64"]="@kdlbs/runtime-darwin-x64"
["macos-arm64"]="@kdlbs/runtime-darwin-arm64"
["windows-x64"]="@kdlbs/runtime-win32-x64"
)
declare -A PLATFORM_TO_OS=(
["linux-x64"]='["linux"]'
["linux-arm64"]='["linux"]'
["macos-x64"]='["darwin"]'
["macos-arm64"]='["darwin"]'
["windows-x64"]='["win32"]'
)
declare -A PLATFORM_TO_CPU=(
["linux-x64"]='["x64"]'
["linux-arm64"]='["arm64"]'
["macos-x64"]='["x64"]'
["macos-arm64"]='["arm64"]'
["windows-x64"]='["x64"]'
)
echo "Packaging npm runtime packages for version $VERSION..."
echo " assets dir: $ASSETS_DIR"
echo " output dir: $OUT_DIR"
for platform in linux-x64 linux-arm64 macos-x64 macos-arm64 windows-x64; do
archive="$ASSETS_DIR/kandev-${platform}.tar.gz"
if [[ ! -f "$archive" ]]; then
echo "Error: missing archive $archive" >&2
exit 1
fi
package_name="${PLATFORM_TO_PACKAGE[$platform]}"
# @kdlbs/runtime-linux-x64 → scope=@kdlbs, name=runtime-linux-x64
scope_dir="${package_name%%/*}" # @kdlbs
pkg_dir="${package_name##*/}" # runtime-linux-x64
pkg_out="$OUT_DIR/${scope_dir}/${pkg_dir}"
rm -rf "$pkg_out"
mkdir -p "$pkg_out"
# Extract only bin/ and web/ from the archive (skip cli/)
local_tmp="$pkg_out/.extract_tmp"
mkdir -p "$local_tmp"
tar -xzf "$archive" -C "$local_tmp"
# Find the extracted bundle root (named "kandev" inside the archive)
bundle_root="$local_tmp/kandev"
if [[ ! -d "$bundle_root" ]]; then
echo "Error: expected kandev/ directory in $archive" >&2
exit 1
fi
cp -R "$bundle_root/bin" "$pkg_out/bin"
cp -R "$bundle_root/web" "$pkg_out/web"
rm -rf "$local_tmp"
os_field="${PLATFORM_TO_OS[$platform]}"
cpu_field="${PLATFORM_TO_CPU[$platform]}"
cat > "$pkg_out/package.json" <<EOF
{
"name": "$package_name",
"version": "$VERSION",
"description": "Kandev runtime bundle for $platform",
"license": "AGPL-3.0-only",
"os": $os_field,
"cpu": $cpu_field,
"files": [
"bin",
"web"
]
}
EOF
echo " packaged $package_name@$VERSION"
done
echo "Done. Runtime packages written to $OUT_DIR"