Skip to content

Commit 858799c

Browse files
fix: update version extraction to be more robust, ensure compatibility (#337)
## Description Update version detection to always detect named module block, and extract version from same module block. Ensure that script is completely compatible for all Unix environments. <!-- Briefly describe what this PR does and why --> ## Type of Change - [ ] New module - [X] Bug fix - [ ] Feature/enhancement - [ ] Documentation - [ ] Other ## Testing & Validation - [ ] Tests pass (`bun test`) - [X] Code formatted (`bun run fmt`) - [X] Changes tested locally
1 parent 32246a9 commit 858799c

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

scripts/tag_release.sh

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ JSON_OUTPUT='{
2828
readonly EXIT_SUCCESS=0
2929
readonly EXIT_ERROR=1
3030
readonly EXIT_NO_ACTION_NEEDED=2
31-
readonly EXIT_VALIDATION_FAILED=3
3231

3332
usage() {
3433
cat << EOF
@@ -52,7 +51,7 @@ EXAMPLES:
5251
$0 -m code-server -d # Target specific module
5352
$0 -n coder -m code-server -d # Target module in namespace
5453
55-
Exit codes: 0=success, 1=error, 2=no action needed, 3=validation failed
54+
Exit codes: 0=success, 1=error, 2=no action needed
5655
EOF
5756
exit 0
5857
}
@@ -230,29 +229,38 @@ extract_version_from_readme() {
230229
return 1
231230
}
232231

233-
local version_line
234-
version_line=$(grep -E "source[[:space:]]*=[[:space:]]*\"registry\.coder\.com/${namespace}/${module_name}" "$readme_path" | head -1 || echo "")
232+
local version
233+
version=$(extract_version_from_module_block "$readme_path" "$namespace" "$module_name")
235234

236-
if [ -n "$version_line" ]; then
237-
local version
238-
version=$(echo "$version_line" | sed -n 's/.*version[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p')
239-
if [ -n "$version" ]; then
240-
log "DEBUG" "Found version '$version' from source line: $version_line"
241-
echo "$version"
242-
return 0
243-
fi
235+
if [ -n "$version" ]; then
236+
log "DEBUG" "Found version '$version' from module block for $namespace/$module_name"
237+
echo "$version"
238+
return 0
244239
fi
245240

246-
local fallback_version
247-
fallback_version=$(grep -E 'version[[:space:]]*=[[:space:]]*"[0-9]+\.[0-9]+\.[0-9]+"' "$readme_path" | head -1 | sed 's/.*version[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/' || echo "")
241+
log "DEBUG" "No version found in module block for $namespace/$module_name in $readme_path"
242+
return 1
243+
}
244+
245+
extract_version_from_module_block() {
246+
local readme_path="$1"
247+
local namespace="$2"
248+
local module_name="$3"
249+
250+
local version
251+
version=$(grep -A 10 "source[[:space:]]*=[[:space:]]*\"registry\.coder\.com/${namespace}/${module_name}/coder" "$readme_path" \
252+
| sed '/^[[:space:]]*}/q' \
253+
| grep -E "version[[:space:]]*=[[:space:]]*\"[^\"]+\"" \
254+
| head -1 \
255+
| sed 's/.*version[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/')
248256

249-
if [ -n "$fallback_version" ]; then
250-
log "DEBUG" "Found fallback version '$fallback_version'"
251-
echo "$fallback_version"
257+
if [ -n "$version" ]; then
258+
log "DEBUG" "Found version '$version' for $namespace/$module_name"
259+
echo "$version"
252260
return 0
253261
fi
254262

255-
log "DEBUG" "No version found in $readme_path"
263+
log "DEBUG" "No version found within module block for $namespace/$module_name"
256264
return 1
257265
}
258266

@@ -546,7 +554,7 @@ create_and_push_tags() {
546554
echo ""
547555
fi
548556

549-
if [ $pushed_tags -gt 0 ]; then
557+
if [ "$pushed_tags" -gt 0 ]; then
550558
if [[ "$OUTPUT_FORMAT" != "json" ]]; then
551559
log "SUCCESS" "🎉 Successfully created and pushed $pushed_tags release tags!"
552560
echo ""
@@ -606,15 +614,15 @@ main() {
606614
detect_exit_code=$?
607615

608616
case $detect_exit_code in
609-
$EXIT_NO_ACTION_NEEDED)
617+
"$EXIT_NO_ACTION_NEEDED")
610618
if [[ "$OUTPUT_FORMAT" == "json" ]]; then
611619
finalize_json_output "$@"
612620
else
613621
log "SUCCESS" "✨ No modules need tagging. All done!"
614622
fi
615623
exit $EXIT_SUCCESS
616624
;;
617-
$EXIT_ERROR)
625+
"$EXIT_ERROR")
618626
if [[ "$OUTPUT_FORMAT" == "json" ]]; then
619627
JSON_OUTPUT=$(echo "$JSON_OUTPUT" | jq '.summary.operation_status = "scan_failed"')
620628
finalize_json_output "$@"

0 commit comments

Comments
 (0)