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
109set -euo pipefail
1110
1211# Function to print usage
1312usage () {
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
113106main () {
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
0 commit comments