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
This commit is contained in:
parent
32246a99c1
commit
858799ce20
@ -28,7 +28,6 @@ JSON_OUTPUT='{
|
|||||||
readonly EXIT_SUCCESS=0
|
readonly EXIT_SUCCESS=0
|
||||||
readonly EXIT_ERROR=1
|
readonly EXIT_ERROR=1
|
||||||
readonly EXIT_NO_ACTION_NEEDED=2
|
readonly EXIT_NO_ACTION_NEEDED=2
|
||||||
readonly EXIT_VALIDATION_FAILED=3
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
@ -52,7 +51,7 @@ EXAMPLES:
|
|||||||
$0 -m code-server -d # Target specific module
|
$0 -m code-server -d # Target specific module
|
||||||
$0 -n coder -m code-server -d # Target module in namespace
|
$0 -n coder -m code-server -d # Target module in namespace
|
||||||
|
|
||||||
Exit codes: 0=success, 1=error, 2=no action needed, 3=validation failed
|
Exit codes: 0=success, 1=error, 2=no action needed
|
||||||
EOF
|
EOF
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
@ -230,29 +229,38 @@ extract_version_from_readme() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
local version_line
|
|
||||||
version_line=$(grep -E "source[[:space:]]*=[[:space:]]*\"registry\.coder\.com/${namespace}/${module_name}" "$readme_path" | head -1 || echo "")
|
|
||||||
|
|
||||||
if [ -n "$version_line" ]; then
|
|
||||||
local version
|
local version
|
||||||
version=$(echo "$version_line" | sed -n 's/.*version[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p')
|
version=$(extract_version_from_module_block "$readme_path" "$namespace" "$module_name")
|
||||||
|
|
||||||
if [ -n "$version" ]; then
|
if [ -n "$version" ]; then
|
||||||
log "DEBUG" "Found version '$version' from source line: $version_line"
|
log "DEBUG" "Found version '$version' from module block for $namespace/$module_name"
|
||||||
echo "$version"
|
echo "$version"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
local fallback_version
|
log "DEBUG" "No version found in module block for $namespace/$module_name in $readme_path"
|
||||||
fallback_version=$(grep -E 'version[[:space:]]*=[[:space:]]*"[0-9]+\.[0-9]+\.[0-9]+"' "$readme_path" | head -1 | sed 's/.*version[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/' || echo "")
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
if [ -n "$fallback_version" ]; then
|
extract_version_from_module_block() {
|
||||||
log "DEBUG" "Found fallback version '$fallback_version'"
|
local readme_path="$1"
|
||||||
echo "$fallback_version"
|
local namespace="$2"
|
||||||
|
local module_name="$3"
|
||||||
|
|
||||||
|
local version
|
||||||
|
version=$(grep -A 10 "source[[:space:]]*=[[:space:]]*\"registry\.coder\.com/${namespace}/${module_name}/coder" "$readme_path" \
|
||||||
|
| sed '/^[[:space:]]*}/q' \
|
||||||
|
| grep -E "version[[:space:]]*=[[:space:]]*\"[^\"]+\"" \
|
||||||
|
| head -1 \
|
||||||
|
| sed 's/.*version[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/')
|
||||||
|
|
||||||
|
if [ -n "$version" ]; then
|
||||||
|
log "DEBUG" "Found version '$version' for $namespace/$module_name"
|
||||||
|
echo "$version"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "DEBUG" "No version found in $readme_path"
|
log "DEBUG" "No version found within module block for $namespace/$module_name"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,7 +554,7 @@ create_and_push_tags() {
|
|||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $pushed_tags -gt 0 ]; then
|
if [ "$pushed_tags" -gt 0 ]; then
|
||||||
if [[ "$OUTPUT_FORMAT" != "json" ]]; then
|
if [[ "$OUTPUT_FORMAT" != "json" ]]; then
|
||||||
log "SUCCESS" "🎉 Successfully created and pushed $pushed_tags release tags!"
|
log "SUCCESS" "🎉 Successfully created and pushed $pushed_tags release tags!"
|
||||||
echo ""
|
echo ""
|
||||||
@ -606,7 +614,7 @@ main() {
|
|||||||
detect_exit_code=$?
|
detect_exit_code=$?
|
||||||
|
|
||||||
case $detect_exit_code in
|
case $detect_exit_code in
|
||||||
$EXIT_NO_ACTION_NEEDED)
|
"$EXIT_NO_ACTION_NEEDED")
|
||||||
if [[ "$OUTPUT_FORMAT" == "json" ]]; then
|
if [[ "$OUTPUT_FORMAT" == "json" ]]; then
|
||||||
finalize_json_output "$@"
|
finalize_json_output "$@"
|
||||||
else
|
else
|
||||||
@ -614,7 +622,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
exit $EXIT_SUCCESS
|
exit $EXIT_SUCCESS
|
||||||
;;
|
;;
|
||||||
$EXIT_ERROR)
|
"$EXIT_ERROR")
|
||||||
if [[ "$OUTPUT_FORMAT" == "json" ]]; then
|
if [[ "$OUTPUT_FORMAT" == "json" ]]; then
|
||||||
JSON_OUTPUT=$(echo "$JSON_OUTPUT" | jq '.summary.operation_status = "scan_failed"')
|
JSON_OUTPUT=$(echo "$JSON_OUTPUT" | jq '.summary.operation_status = "scan_failed"')
|
||||||
finalize_json_output "$@"
|
finalize_json_output "$@"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user