Skip to content

Disable hooks for nested Codex helpers #241

Disable hooks for nested Codex helpers

Disable hooks for nested Codex helpers #241

name: Version Bump Check
on:
pull_request:
branches: [main]
jobs:
version-bump-check:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check version bump
run: |
echo "Checking that all version numbers have been incremented..."
# Get the base branch (main)
git fetch origin main:refs/remotes/origin/main
# Function to validate version bump (X.Y.Z format)
# Valid bumps:
# - X.Y.Z -> X.Y.(Z+1) patch bump
# - X.Y.Z -> X.(Y+1).0 minor bump
# - X.Y.Z -> (X+1).0.0 major bump
# Returns: 0 if valid bump, 1 if invalid
# Sets global BUMP_ERROR with error message on failure
validate_version_bump() {
local main_ver="$1"
local pr_ver="$2"
BUMP_ERROR=""
# Split versions into components
local main_x main_y main_z pr_x pr_y pr_z
IFS='.' read -r main_x main_y main_z <<< "$main_ver"
IFS='.' read -r pr_x pr_y pr_z <<< "$pr_ver"
# Case 1: Major bump (X+1).0.0
if [ "$pr_x" -eq $((main_x + 1)) ] && [ "$pr_y" -eq 0 ] && [ "$pr_z" -eq 0 ]; then
return 0
fi
# Case 2: Minor bump X.(Y+1).0
if [ "$pr_x" -eq "$main_x" ] && [ "$pr_y" -eq $((main_y + 1)) ] && [ "$pr_z" -eq 0 ]; then
return 0
fi
# Case 3: Patch bump X.Y.(Z+1)
if [ "$pr_x" -eq "$main_x" ] && [ "$pr_y" -eq "$main_y" ] && [ "$pr_z" -eq $((main_z + 1)) ]; then
return 0
fi
# Invalid bump - determine error message
if [ "$pr_x" -lt "$main_x" ] || \
([ "$pr_x" -eq "$main_x" ] && [ "$pr_y" -lt "$main_y" ]) || \
([ "$pr_x" -eq "$main_x" ] && [ "$pr_y" -eq "$main_y" ] && [ "$pr_z" -le "$main_z" ]); then
BUMP_ERROR="Version must be incremented, not decreased or unchanged"
elif [ "$pr_x" -gt $((main_x + 1)) ]; then
BUMP_ERROR="Major version can only increase by 1 (expected $((main_x + 1)).0.0)"
elif [ "$pr_x" -eq $((main_x + 1)) ]; then
BUMP_ERROR="Major bump requires Y=0 and Z=0 (expected $((main_x + 1)).0.0)"
elif [ "$pr_y" -gt $((main_y + 1)) ]; then
BUMP_ERROR="Minor version can only increase by 1 (expected $main_x.$((main_y + 1)).0)"
elif [ "$pr_y" -eq $((main_y + 1)) ]; then
BUMP_ERROR="Minor bump requires Z=0 (expected $main_x.$((main_y + 1)).0)"
elif [ "$pr_z" -gt $((main_z + 1)) ]; then
BUMP_ERROR="Patch version can only increase by 1 (expected $main_x.$main_y.$((main_z + 1)))"
else
BUMP_ERROR="Invalid version bump pattern"
fi
return 1
}
# Files to check
FILES=(
".claude-plugin/plugin.json"
".claude-plugin/marketplace.json"
"README.md"
)
exit_code=0
for file in "${FILES[@]}"; do
echo ""
echo "=== Checking $file ==="
# Get version from main branch
if [ "$file" = "README.md" ]; then
# Extract version from README.md format: **Current Version: X.Y.Z**
main_version=$(git show origin/main:"$file" 2>/dev/null | grep -oP '\*\*Current Version: \K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
pr_version=$(grep -oP '\*\*Current Version: \K[0-9]+\.[0-9]+\.[0-9]+' "$file" | head -1)
else
# Extract version from JSON files
main_version=$(git show origin/main:"$file" 2>/dev/null | grep -oP '"version":\s*"\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
pr_version=$(grep -oP '"version":\s*"\K[0-9]+\.[0-9]+\.[0-9]+' "$file" | head -1)
fi
echo " Main branch version: $main_version"
echo " PR branch version: $pr_version"
if [ -z "$main_version" ]; then
echo " WARNING: Could not find version in main branch (new file?)"
continue
fi
if [ -z "$pr_version" ]; then
echo " ERROR: Could not find version in PR branch"
exit_code=1
continue
fi
if validate_version_bump "$main_version" "$pr_version"; then
echo " OK: Valid version bump"
else
echo " ERROR: $BUMP_ERROR"
exit_code=1
fi
done
echo ""
if [ $exit_code -ne 0 ]; then
echo "========================================"
echo "FAILED: Version bump validation failed."
echo ""
echo "Valid version bump patterns (exactly +1):"
echo " - Patch: X.Y.Z -> X.Y.(Z+1)"
echo " - Minor: X.Y.Z -> X.(Y+1).0"
echo " - Major: X.Y.Z -> (X+1).0.0"
echo ""
echo "Please update version in ALL of these files:"
echo " - .claude-plugin/plugin.json"
echo " - .claude-plugin/marketplace.json"
echo " - README.md (Current Version line)"
echo "========================================"
else
echo "========================================"
echo "PASSED: All version bumps are valid (+1 increment)."
echo "========================================"
fi
exit $exit_code