Skip to content

Commit 6a1d6a5

Browse files
committed
fix: simplify script to only support patch/minor/major, workflow checks diff
- Remove all check mode logic from version-bump.sh script - Script now only supports patch, minor, major (as requested) - Workflow runs script with patch and checks if diff exists - If diff exists, CI fails and tells user to add version label - Much simpler implementation: script updates, workflow checks diff - Updated documentation to remove check mode references - This is exactly what was requested: same script, check diff for validation
1 parent b56adc5 commit 6a1d6a5

File tree

3 files changed

+58
-97
lines changed

3 files changed

+58
-97
lines changed

.github/scripts/version-bump.sh

Lines changed: 41 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22

33
# Version Bump Script
44
# Extracts version bump logic from GitHub Actions workflow
5-
# Usage: ./version-bump.sh <bump_type> [base_ref] [--check]
6-
# bump_type: patch, minor, major, or check
5+
# Usage: ./version-bump.sh <bump_type> [base_ref]
6+
# bump_type: patch, minor, or major
77
# base_ref: base reference for diff (default: origin/main)
8-
# --check: only check if versions need updating, don't modify files
98

109
set -euo pipefail
1110

1211
# Function to print usage
1312
usage() {
14-
echo "Usage: $0 <bump_type> [base_ref] [--check]"
15-
echo " bump_type: patch, minor, major, or check"
13+
echo "Usage: $0 <bump_type> [base_ref]"
14+
echo " bump_type: patch, minor, or major"
1615
echo " base_ref: base reference for diff (default: origin/main)"
17-
echo " --check: only check if versions need updating, don't modify files"
1816
echo ""
1917
echo "Examples:"
2018
echo " $0 patch # Update versions with patch bump"
21-
echo " $0 check # Check if versions need updating"
22-
echo " $0 patch origin/main --check # Check what patch bump would do"
19+
echo " $0 minor # Update versions with minor bump"
20+
echo " $0 major # Update versions with major bump"
2321
exit 1
2422
}
2523

@@ -69,7 +67,6 @@ update_readme_version() {
6967
local namespace="$2"
7068
local module_name="$3"
7169
local new_version="$4"
72-
local check_mode="$5"
7370

7471
if [ ! -f "$readme_path" ]; then
7572
return 1
@@ -78,28 +75,24 @@ update_readme_version() {
7875
# Check if README contains version references for this specific module
7976
local module_source="registry.coder.com/${namespace}/${module_name}/coder"
8077
if grep -q "source.*${module_source}" "$readme_path"; then
81-
if [ "$check_mode" = "true" ]; then
82-
echo "Would update version references for $namespace/$module_name in $readme_path"
83-
else
84-
echo "Updating version references for $namespace/$module_name in $readme_path"
85-
# Use awk to only update versions that follow the specific module source
86-
awk -v module_source="$module_source" -v new_version="$new_version" '
87-
/source.*=.*/ {
88-
if ($0 ~ module_source) {
89-
in_target_module = 1
90-
} else {
91-
in_target_module = 0
92-
}
93-
}
94-
/version.*=.*"/ {
95-
if (in_target_module) {
96-
gsub(/version[[:space:]]*=[[:space:]]*"[^"]*"/, "version = \"" new_version "\"")
97-
in_target_module = 0
98-
}
99-
}
100-
{ print }
101-
' "$readme_path" > "${readme_path}.tmp" && mv "${readme_path}.tmp" "$readme_path"
102-
fi
78+
echo "Updating version references for $namespace/$module_name in $readme_path"
79+
# Use awk to only update versions that follow the specific module source
80+
awk -v module_source="$module_source" -v new_version="$new_version" '
81+
/source.*=.*/ {
82+
if ($0 ~ module_source) {
83+
in_target_module = 1
84+
} else {
85+
in_target_module = 0
86+
}
87+
}
88+
/version.*=.*"/ {
89+
if (in_target_module) {
90+
gsub(/version[[:space:]]*=[[:space:]]*"[^"]*"/, "version = \"" new_version "\"")
91+
in_target_module = 0
92+
}
93+
}
94+
{ print }
95+
' "$readme_path" > "${readme_path}.tmp" && mv "${readme_path}.tmp" "$readme_path"
10396
return 0
10497
elif grep -q 'version\s*=\s*"' "$readme_path"; then
10598
echo "⚠️ Found version references but no module source match for $namespace/$module_name"
@@ -112,40 +105,19 @@ update_readme_version() {
112105
# Main function
113106
main() {
114107
# Parse arguments
115-
if [ $# -lt 1 ] || [ $# -gt 3 ]; then
108+
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
116109
usage
117110
fi
118111

119112
local bump_type="$1"
120-
local base_ref="origin/main"
121-
local check_mode=false
122-
123-
# Parse remaining arguments
124-
shift
125-
while [ $# -gt 0 ]; do
126-
case "$1" in
127-
--check)
128-
check_mode=true
129-
;;
130-
*)
131-
base_ref="$1"
132-
;;
133-
esac
134-
shift
135-
done
136-
137-
# Handle "check" as bump type
138-
if [ "$bump_type" = "check" ]; then
139-
check_mode=true
140-
bump_type="patch" # Use patch as default for check mode
141-
fi
113+
local base_ref="${2:-origin/main}"
142114

143115
# Validate bump type
144116
case "$bump_type" in
145117
"patch"|"minor"|"major")
146118
;;
147119
*)
148-
echo "❌ Invalid bump type: '$bump_type'. Expected patch, minor, major, or check." >&2
120+
echo "❌ Invalid bump type: '$bump_type'. Expected patch, minor, or major." >&2
149121
exit 1
150122
;;
151123
esac
@@ -229,7 +201,7 @@ main() {
229201
echo "New version: $new_version"
230202

231203
# Update README if applicable
232-
if update_readme_version "$readme_path" "$namespace" "$module_name" "$new_version" "$check_mode"; then
204+
if update_readme_version "$readme_path" "$namespace" "$module_name" "$new_version"; then
233205
updated_readmes="$updated_readmes\n- $namespace/$module_name"
234206
has_changes=true
235207
fi
@@ -260,40 +232,20 @@ main() {
260232
echo ""
261233
fi
262234

263-
# Check for changes and provide guidance
264-
if [ "$check_mode" = "true" ]; then
265-
if [ "$has_changes" = true ]; then
266-
echo "❌ Module versions need to be updated!"
267-
echo "📝 The following modules would have their README files updated:"
268-
echo -e "$updated_readmes"
269-
echo ""
270-
echo "To fix this, run one of:"
271-
echo " ./.github/scripts/version-bump.sh patch"
272-
echo " ./.github/scripts/version-bump.sh minor"
273-
echo " ./.github/scripts/version-bump.sh major"
274-
echo ""
275-
echo "Or add a version label to your PR: version:patch, version:minor, or version:major"
276-
exit 1
277-
else
278-
echo "✅ Module versions are up to date!"
279-
echo "ℹ️ No version updates needed."
280-
exit 0
281-
fi
235+
# Provide guidance
236+
if [ "$has_changes" = true ]; then
237+
echo "✅ Version bump completed successfully!"
238+
echo "📝 README files have been updated with new versions."
239+
echo ""
240+
echo "Next steps:"
241+
echo "1. Review the changes: git diff"
242+
echo "2. Commit the changes: git add . && git commit -m 'chore: bump module versions ($bump_type)'"
243+
echo "3. Push the changes: git push"
244+
exit 0
282245
else
283-
if [ "$has_changes" = true ]; then
284-
echo "✅ Version bump completed successfully!"
285-
echo "📝 README files have been updated with new versions."
286-
echo ""
287-
echo "Next steps:"
288-
echo "1. Review the changes: git diff"
289-
echo "2. Commit the changes: git add . && git commit -m 'chore: bump module versions ($bump_type)'"
290-
echo "3. Push the changes: git push"
291-
exit 0
292-
else
293-
echo "ℹ️ No README files were updated (no version references found matching module sources)."
294-
echo "Version calculations completed, but no files were modified."
295-
exit 0
296-
fi
246+
echo "ℹ️ No README files were updated (no version references found matching module sources)."
247+
echo "Version calculations completed, but no files were modified."
248+
exit 0
297249
fi
298250
}
299251

.github/workflows/version-bump.yaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,24 @@ jobs:
2323
run: |
2424
echo "🔍 Checking if module versions need to be updated..."
2525
26-
# Run the script in check mode
27-
if ./.github/scripts/version-bump.sh check origin/main; then
28-
echo "✅ Module versions are up to date"
26+
# Run the script with patch to see if it would make changes
27+
if ./.github/scripts/version-bump.sh patch origin/main; then
28+
# Check if the script made any changes
29+
if git diff --quiet; then
30+
echo "✅ Module versions are up to date"
31+
else
32+
echo "❌ Module versions need to be updated!"
33+
echo "The script would make the following changes:"
34+
git diff --name-only
35+
echo ""
36+
echo "To fix this, add a version label to your PR:"
37+
echo "- version:patch (for bug fixes)"
38+
echo "- version:minor (for new features)"
39+
echo "- version:major (for breaking changes)"
40+
exit 1
41+
fi
2942
else
30-
echo "❌ Module versions need to be updated"
31-
exit 1
43+
echo "ℹ️ No modules detected in changes"
3244
fi
3345
3446
version-bump:

CONTRIBUTING.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,6 @@ Use the version bump script to automatically update module versions:
277277

278278
# For breaking changes
279279
./.github/scripts/version-bump.sh major
280-
281-
# To check if versions need updating (without making changes)
282-
./.github/scripts/version-bump.sh check
283280
```
284281

285282
The script will:

0 commit comments

Comments
 (0)