|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Fail the PR when a changed publishable skill's package.json version was not |
| 3 | +# bumped. Pairs with publish-changed-skills.sh: that script silently skips an |
| 4 | +# unbumped version on merge, this one stops the unbumped change from landing. |
| 5 | +# |
| 6 | +# Reads one required env var: |
| 7 | +# BASE_REF - git ref to diff against (e.g. origin/main) |
| 8 | +# |
| 9 | +# Behaviour: |
| 10 | +# * For every skills/<name>/ directory the PR touches (ANY file inside the |
| 11 | +# folder counts), compares the version in HEAD's package.json against the |
| 12 | +# version in BASE_REF's package.json. |
| 13 | +# * Fails (and lists every offender) when the versions are equal. Bumping |
| 14 | +# the version is what ships a release - see CONTRIBUTING.md > Versioning. |
| 15 | +# * Skips brand-new skills (no package.json in BASE_REF) - there is no |
| 16 | +# previous version to compare against. |
| 17 | +# * Skips skill dirs that no longer have a package.json on HEAD - the spec |
| 18 | +# validator catches that as a separate error. |
| 19 | +# * Meta-skills under .github/skills/ are never published, so this check |
| 20 | +# does not apply to them. |
| 21 | + |
| 22 | +set -uo pipefail |
| 23 | + |
| 24 | +: "${BASE_REF:?BASE_REF is required}" |
| 25 | + |
| 26 | +# Only the root skills/ tree is published; .github/skills/ holds meta-skills |
| 27 | +# that are validated on PRs but never shipped, so unbumped meta-skill edits |
| 28 | +# are fine. |
| 29 | +mapfile -t changed < <( |
| 30 | + git diff --name-only "$BASE_REF"...HEAD \ |
| 31 | + | awk -F/ '$1 == "skills" && NF >= 2 { print "skills/" $2 }' \ |
| 32 | + | sort -u |
| 33 | +) |
| 34 | + |
| 35 | +if [ "${#changed[@]}" -eq 0 ]; then |
| 36 | + echo "No publishable skills changed; version bump check skipped." |
| 37 | + exit 0 |
| 38 | +fi |
| 39 | + |
| 40 | +failures=() |
| 41 | +for dir in "${changed[@]}"; do |
| 42 | + pkg="$dir/package.json" |
| 43 | + |
| 44 | + if [ ! -f "$pkg" ]; then |
| 45 | + echo "skip $dir: no package.json on HEAD" |
| 46 | + continue |
| 47 | + fi |
| 48 | + |
| 49 | + if ! git cat-file -e "$BASE_REF:$pkg" 2>/dev/null; then |
| 50 | + echo "skip $dir: new skill (no package.json in $BASE_REF)" |
| 51 | + continue |
| 52 | + fi |
| 53 | + |
| 54 | + new_version=$(jq -r .version "$pkg") |
| 55 | + old_version=$(git show "$BASE_REF:$pkg" | jq -r .version) |
| 56 | + |
| 57 | + if [ "$new_version" = "$old_version" ]; then |
| 58 | + echo "::error file=$pkg::skill '$dir' changed but version is still $new_version - run 'npm version patch|minor|major' inside $dir to bump it" |
| 59 | + failures+=("$dir (version $new_version unchanged)") |
| 60 | + else |
| 61 | + echo "ok $dir: $old_version -> $new_version" |
| 62 | + fi |
| 63 | +done |
| 64 | + |
| 65 | +if [ "${#failures[@]}" -ne 0 ]; then |
| 66 | + echo |
| 67 | + echo "Version bump check failed for ${#failures[@]} skill(s):" |
| 68 | + for f in "${failures[@]}"; do |
| 69 | + echo " - $f" |
| 70 | + done |
| 71 | + echo |
| 72 | + echo "Bump the version in each skill's package.json (npm version patch|minor|major)." |
| 73 | + echo "See CONTRIBUTING.md > Versioning." |
| 74 | + exit 1 |
| 75 | +fi |
| 76 | + |
| 77 | +echo |
| 78 | +echo "All ${#changed[@]} changed skill(s) have version bumps." |
0 commit comments