Skip to content

Commit 925c71e

Browse files
fix: improve version extraction logic to prevent false positives (#511)
## Description Makes the version extract and replace logic more specific so it wont replace any field that does is not specifically `field` under the detected modules. <!-- Briefly describe what this PR does and why --> ## Type of Change - [ ] New module - [ ] New template - [X] Bug fix - [ ] Feature/enhancement - [ ] Documentation - [ ] Other ## Testing & Validation - [X] Tests pass (`bun test`) - [X] Code formatted (`bun fmt`) - [X] Changes tested locally ## Related Issues #510 <!-- Link related issues or write "None" if not applicable --> --------- Co-authored-by: Atif Ali <atif@coder.com>
1 parent 5450113 commit 925c71e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

.github/scripts/version-bump.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,19 @@ update_readme_version() {
7777
in_target_module = 0
7878
}
7979
}
80-
/version.*=.*"/ {
80+
/^[[:space:]]*version[[:space:]]*=/ {
8181
if (in_target_module) {
82-
gsub(/version[[:space:]]*=[[:space:]]*"[^"]*"/, "version = \"" new_version "\"")
82+
match($0, /^[[:space]]*/
83+
indent = substr($0, 1, RLENGTH)
84+
print indent "version = \"" new_version "\""
8385
in_target_module = 0
86+
next
8487
}
8588
}
8689
{ print }
8790
' "$readme_path" > "${readme_path}.tmp" && mv "${readme_path}.tmp" "$readme_path"
8891
return 0
89-
elif grep -q 'version\s*=\s*"' "$readme_path"; then
92+
elif grep -q '^[[:space:]]*version[[:space:]]*=' "$readme_path"; then
9093
echo "⚠️ Found version references but no module source match for $namespace/$module_name"
9194
return 1
9295
fi
@@ -148,9 +151,9 @@ main() {
148151
local current_version
149152

150153
if [ -z "$latest_tag" ]; then
151-
if [ -f "$readme_path" ] && grep -q 'version\s*=\s*"' "$readme_path"; then
154+
if [ -f "$readme_path" ] && grep -q '^[[:space:]]*version[[:space:]]*=' "$readme_path"; then
152155
local readme_version
153-
readme_version=$(grep 'version\s*=\s*"' "$readme_path" | head -1 | sed 's/.*version\s*=\s*"\([^"]*\)".*/\1/')
156+
readme_version=$(awk '/^[[:space:]]*version[[:space:]]*=/ { match($0, /"[^"]*"/); print substr($0, RSTART+1, RLENGTH-2); exit }' "$readme_path")
154157
echo "No git tag found, but README shows version: $readme_version"
155158

156159
if ! validate_version "$readme_version"; then

0 commit comments

Comments
 (0)