fix: harden get_version_name against missing file and extraction failures

Made-with: Cursor
This commit is contained in:
cottongin
2026-03-11 04:25:48 -04:00
parent 9b3e943eea
commit 1825b7930e

View File

@@ -35,7 +35,17 @@ warn() { echo -e "${YELLOW}⚠${NC} $1"; }
error() { echo -e "${RED}${NC} $1"; }
get_version_name() {
grep 'versionName' "$GRADLE_BUILD_FILE" | head -1 | sed 's/.*"\(.*\)".*/\1/'
if [[ ! -f "$GRADLE_BUILD_FILE" ]]; then
error "Build file not found: $GRADLE_BUILD_FILE"
exit 1
fi
local v
v=$(grep 'versionName' "$GRADLE_BUILD_FILE" | head -1 | sed 's/.*"\([^"]*\)".*/\1/')
if [[ -z "$v" ]]; then
error "Could not extract version from $GRADLE_BUILD_FILE"
exit 1
fi
echo "$v"
}
preflight_check() {