-
Notifications
You must be signed in to change notification settings - Fork 120
143 lines (123 loc) · 5.48 KB
/
Copy pathversion-bump-check.yml
File metadata and controls
143 lines (123 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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