|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Verifies plugin/.claude-plugin/plugin.json version is consistent with |
| 3 | +# package.json and plugin content changes in git history. |
| 4 | +# |
| 5 | +# Checks: |
| 6 | +# - plugin major.minor must match package major.minor |
| 7 | +# - no commits since the last release tag changed plugin content without |
| 8 | +# also updating plugin.json in the same commit |
| 9 | +# |
| 10 | +# Intended for pre-push and release checks — does NOT modify any files. |
| 11 | + |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +PLUGIN_JSON="plugin/.claude-plugin/plugin.json" |
| 15 | + |
| 16 | +BUN=$(command -v bun 2>/dev/null || echo "$HOME/.bun/bin/bun") |
| 17 | +if ! "$BUN" --version >/dev/null 2>&1; then |
| 18 | + echo "check-plugin-version: bun not found, cannot verify" >&2 |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +pkg_version=$("$BUN" -e "process.stdout.write(JSON.parse(require('fs').readFileSync('package.json','utf8')).version)") |
| 23 | +plugin_version=$("$BUN" -e "process.stdout.write(JSON.parse(require('fs').readFileSync('$PLUGIN_JSON','utf8')).version)") |
| 24 | + |
| 25 | +IFS='.' read -r pkg_major pkg_minor _pkg_patch <<< "$pkg_version" |
| 26 | +IFS='.' read -r plugin_major plugin_minor _plugin_patch <<< "$plugin_version" |
| 27 | + |
| 28 | +fail=0 |
| 29 | + |
| 30 | +# Check major.minor sync |
| 31 | +if [ "$pkg_major" -gt "$plugin_major" ] || { [ "$pkg_major" -eq "$plugin_major" ] && [ "$pkg_minor" -gt "$plugin_minor" ]; }; then |
| 32 | + echo "ERROR: plugin version ($plugin_version) major.minor is behind package ($pkg_version)." >&2 |
| 33 | + fail=1 |
| 34 | +fi |
| 35 | + |
| 36 | +# Find the most recent release tag to use as the search baseline |
| 37 | +last_tag=$(git describe --tags --abbrev=0 2>/dev/null || true) |
| 38 | +range="${last_tag:+${last_tag}..}HEAD" |
| 39 | + |
| 40 | +# Find commits in range where plugin content changed but plugin.json did NOT |
| 41 | +unversioned="" |
| 42 | +while IFS= read -r hash; do |
| 43 | + changed=$(git diff-tree --no-commit-id -r "$hash" --name-only) |
| 44 | + plugin_content=$(echo "$changed" | grep "^plugin/" | grep -v "^plugin/\.claude-plugin/plugin\.json$" || true) |
| 45 | + plugin_json_changed=$(echo "$changed" | grep "^plugin/\.claude-plugin/plugin\.json$" || true) |
| 46 | + if [ -n "$plugin_content" ] && [ -z "$plugin_json_changed" ]; then |
| 47 | + subject=$(git log -1 --format="%s" "$hash") |
| 48 | + unversioned="${unversioned} ${hash:0:7} ${subject}"$'\n' |
| 49 | + fi |
| 50 | +done < <(git log "$range" --format="%H") |
| 51 | + |
| 52 | +if [ -n "$unversioned" ]; then |
| 53 | + echo "ERROR: plugin content changed without a version bump in:" >&2 |
| 54 | + echo "$unversioned" >&2 |
| 55 | + echo "Run 'bash scripts/sync-plugin-version.sh' staged with any plugin change to fix, then commit." >&2 |
| 56 | + fail=1 |
| 57 | +fi |
| 58 | + |
| 59 | +if [ "$fail" -eq 1 ]; then |
| 60 | + exit 1 |
| 61 | +fi |
| 62 | + |
| 63 | +echo "Plugin version ($plugin_version) is consistent." |
0 commit comments