release.sh: arrow navigation, barra fija, sin residuos

This commit is contained in:
Super User
2026-06-17 21:05:33 -04:00
parent a15f81d1fc
commit 7e40f61924

View File

@@ -5,134 +5,190 @@ ROOT="$(cd "$(dirname "$0")" && pwd)"
AAB_DIR="$ROOT/build/app/outputs/bundle/release" AAB_DIR="$ROOT/build/app/outputs/bundle/release"
FLUTTER="/opt/flutter/bin/flutter" FLUTTER="/opt/flutter/bin/flutter"
JAVA_HOME="/root/.sdkman/candidates/java/21.0.11-amzn" JAVA_HOME="/root/.sdkman/candidates/java/21.0.11-amzn"
ADB="/opt/android-sdk/platform-tools/adb"
RED='\033[0;31m' # ── colors ──
GREEN='\033[0;32m' R='\033[0;31m' G='\033[0;32m' Y='\033[1;33m'
YELLOW='\033[1;33m' C='\033[0;36m' B='\033[1m' N='\033[0m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
bar="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" bar="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
len=${#bar} blen=${#bar}
progress() { # ── helpers ──
local pct=$1 cleanup() { tput cnorm; exit; }
local msg=$2 trap cleanup EXIT INT TERM
local filled=$(( pct * len / 100 ))
local empty=$(( len - filled )) cursor_off() { tput civis; }
printf "\r${CYAN}[${bar:0:filled}${NC}${bar:0:empty}${CYAN}]${NC} %3d%% %s" "$pct" "$msg" cursor_on() { tput cnorm; }
# ── arrow selector ──
# usage: select_arrow "opt1" "opt2" ... → prints chosen, returns 0
select_arrow() {
local opts=("$@")
local sel=0
local row
row=$(tput lines)
row=$(( row - ${#opts[@]} - 1 ))
local col=4
local key
cursor_off
while true; do
for i in "${!opts[@]}"; do
tput cup "$(( row + i ))" "$col"
if [ "$i" -eq "$sel" ]; then
printf "${C} ${opts[$i]}${N} \033[K"
else
printf " ${opts[$i]} \033[K"
fi
done
IFS= read -rsn1 key
if [[ $key == $'\x1b' ]]; then
read -rsn2 key
case "$key" in
'[A') (( sel > 0 )) && (( sel-- )) ;;
'[B') (( sel < ${#opts[@]} - 1 )) && (( sel++ )) ;;
esac
elif [[ $key == "" ]]; then
# clear selection lines
for i in "${!opts[@]}"; do
tput cup "$(( row + i ))" "$col"
printf " \033[K"
done
cursor_on
echo "${opts[$sel]}"
return 0
fi
done
} }
clear # ── progress bar (fixed position) ──
echo -e "${BOLD}═══════════════════════════════════════${NC}" PROGRESS_ROW=0
echo -e "${BOLD} Factura del Hogar — Release Builder ${NC}" set_progress_row() { PROGRESS_ROW=$(tput lines); }
echo -e "${BOLD}═══════════════════════════════════════${NC}" progress() {
echo local pct=$1 msg=$2
local filled=$(( pct * blen / 100 ))
local empty=$(( blen - filled ))
local offset=$(( PROGRESS_ROW - 2 ))
tput cup "$offset" 0
printf "${C}[${bar:0:filled}${N}${bar:0:empty}${C}]${N} %3d%% %s\033[K" "$pct" "$msg"
}
# --- Verify project root --- # ── ── ── ── ── ── ── ── ──
clear
cat <<EOF
${B}═══════════════════════════════════════${N}
${B} Factura del Hogar — Release Builder ${N}
${B}═══════════════════════════════════════${N}
EOF
# ── verify project ──
if [ ! -f "$ROOT/pubspec.yaml" ] || ! grep -q "flutter" "$ROOT/pubspec.yaml" 2>/dev/null; then if [ ! -f "$ROOT/pubspec.yaml" ] || ! grep -q "flutter" "$ROOT/pubspec.yaml" 2>/dev/null; then
echo -e "${RED}This is not a Flutter project root (pubspec.yaml not found).${NC}" echo -e "${R}Not a Flutter project root.${N}"
exit 1 exit 1
fi fi
NAME=$(grep "^name:" "$ROOT/pubspec.yaml" | head -1 | awk '{print $2}' | tr -d '"') NAME=$(grep "^name:" "$ROOT/pubspec.yaml" | head -1 | awk '{print $2}' | tr -d '"')
VERSION=$(grep "^version:" "$ROOT/pubspec.yaml" | head -1 | awk '{print $2}') VERSION=$(grep "^version:" "$ROOT/pubspec.yaml" | head -1 | awk '{print $2}')
echo -e " Project ${CYAN}$NAME${NC}"
echo -e " Version ${CYAN}$VERSION${NC}" printf " Project ${C}%s${N}\n" "$NAME"
echo -e " Output ${CYAN}$AAB_DIR${NC}" printf " Version ${C}%s${N}\n" "$VERSION"
printf " Output ${C}%s${N}\n" "$AAB_DIR"
echo echo
# --- Confirm --- # ── confirm with arrows ──
echo -e "${YELLOW}⚠ A release build will be created for Play Store.${NC}" echo -e " ${Y}Build release for Play Store?${N}"
read -rp "$(echo -e ${BOLD}"Continue? [Y/n]: "${NC})" REPLY CHOICE=$(select_arrow "Yes" "No")
REPLY="${REPLY:-y}" if [ "$CHOICE" != "Yes" ]; then
if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then echo -e "${Y}Canceled.${N}"
echo -e "${YELLOW}Canceled.${NC}"
exit 0 exit 0
fi fi
echo
set_progress_row
export JAVA_HOME="$JAVA_HOME" export JAVA_HOME="$JAVA_HOME"
# --- Clean --- # ── clean ──
progress 5 "Cleaning previous build..." progress 3 "Cleaning..."
"$FLUTTER" clean > /dev/null 2>&1 "$FLUTTER" clean > /dev/null 2>&1 || true
sleep 0.3 progress 6 "Cleaning... done"
progress 8 "Done"
# --- Pub get --- # ── pub get ──
echo progress 8 "Dependencies..."
progress 8 "Fetching dependencies..."
"$FLUTTER" pub get > /dev/null 2>&1 "$FLUTTER" pub get > /dev/null 2>&1
progress 12 "Done" progress 12 "Dependencies... done"
# --- Build AAB --- # ── build AAB ──
echo
progress 12 "Building release AAB..." progress 12 "Building release AAB..."
BUILD_OUTPUT=$("$FLUTTER" build appbundle --release 2>&1) BUILD_OUTPUT=$("$FLUTTER" build appbundle --release 2>&1) || {
if [ $? -ne 0 ]; then echo
echo -e "\n${RED}✗ Build failed:${NC}" tput cup "$(( PROGRESS_ROW - 1 ))" 0
echo -e "${R}✗ Build failed:${N}"
echo "$BUILD_OUTPUT" echo "$BUILD_OUTPUT"
exit 1 exit 1
fi }
progress 70 "AAB built successfully" progress 75 "AAB built successfully"
# --- Native debug symbols --- # ── native debug symbols ──
echo
SYMBOLS_DIR="$ROOT/build/app/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib" SYMBOLS_DIR="$ROOT/build/app/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib"
progress 70 "Packaging native debug symbols..." progress 78 "Packaging symbols..."
if [ -d "$SYMBOLS_DIR" ]; then if [ -d "$SYMBOLS_DIR" ]; then
cd "$SYMBOLS_DIR" cd "$SYMBOLS_DIR"
rm -f "$AAB_DIR/native-debug-symbols.zip" rm -f "$AAB_DIR/native-debug-symbols.zip"
zip -r "$AAB_DIR/native-debug-symbols.zip" . > /dev/null 2>&1 zip -r "$AAB_DIR/native-debug-symbols.zip" . > /dev/null 2>&1
cd "$ROOT" cd "$ROOT"
progress 90 "Symbols packaged" progress 95 "Symbols packaged"
else else
echo -e "\n${YELLOW}⚠ No native libs found at $SYMBOLS_DIR${NC}" echo
tput cup "$(( PROGRESS_ROW - 1 ))" 0
echo -e "${Y}⚠ No native libs found${N}"
fi fi
# --- Verify output --- # ── verify ──
echo progress 98 "Verifying..."
progress 95 "Verifying..." sleep 0.2
sleep 0.3
progress 100 "Complete!" progress 100 "Complete!"
echo -e "\n\n"
# --- Results ---
echo -e "${BOLD}═══════════════════════════════════════${NC}"
echo -e "${GREEN}✓ Build successful!${NC}"
echo echo
# ── results ──
AAB_FILE="$AAB_DIR/app-release.aab" AAB_FILE="$AAB_DIR/app-release.aab"
SYM_FILE="$AAB_DIR/native-debug-symbols.zip" SYM_FILE="$AAB_DIR/native-debug-symbols.zip"
echo -e " ${CYAN}App Bundle${NC} ${AAB_FILE:+$AAB_FILE}"
echo -e " ${CYAN}Debug Symbols${NC} ${SYM_FILE:+$SYM_FILE}"
echo -e " ${CYAN}Version${NC} ${VERSION}"
size_aab=$(du -sh "$AAB_FILE" 2>/dev/null | cut -f1) size_aab=$(du -sh "$AAB_FILE" 2>/dev/null | cut -f1)
size_sym=$(du -sh "$SYM_FILE" 2>/dev/null | cut -f1) size_sym=$(du -sh "$SYM_FILE" 2>/dev/null | cut -f1)
echo -e " ${CYAN}AAB size${NC} ${size_aab:-N/A}"
echo -e " ${CYAN}Symbols size${NC} ${size_sym:-N/A}"
echo
# --- Move prompt --- cat <<EOF
read -rp "$(echo -e ${BOLD}"Move files to another location? [y/N]: "${NC})" MOVE_REPLY
MOVE_REPLY="${MOVE_REPLY:-n}" ${B}═══════════════════════════════════════${N}
if [[ "$MOVE_REPLY" =~ ^[Yy]$ ]]; then ${G}✓ Build successful!${N}
read -rp "$(echo -e ${BOLD}"Destination directory: "${NC})" DEST
${C}App Bundle${N} $AAB_FILE
${C}Debug Symbols${N} ${SYM_FILE}
${C}Version${N} $VERSION
${C}AAB size${N} ${size_aab:-N/A}
${C}Symbols size${N} ${size_sym:-N/A}
EOF
# ── move prompt with arrows ──
echo -e " ${B}Move files to another location?${N}"
MOVE_CHOICE=$(select_arrow "No" "Yes")
if [ "$MOVE_CHOICE" = "Yes" ]; then
read -rp " Destination: " DEST
DEST="${DEST/#\~/$HOME}" DEST="${DEST/#\~/$HOME}"
if [ -d "$DEST" ]; then if [ -d "$DEST" ]; then
cp "$AAB_FILE" "$DEST/" 2>/dev/null && echo -e "${GREEN}✓ AAB copied to $DEST${NC}" || echo -e "${RED}✗ Failed to copy AAB${NC}" cp "$AAB_FILE" "$DEST/" 2>/dev/null \
&& echo -e " ${G}✓ AAB copied${N}" \
|| echo -e " ${R}✗ Failed to copy AAB${N}"
if [ -f "$SYM_FILE" ]; then if [ -f "$SYM_FILE" ]; then
cp "$SYM_FILE" "$DEST/" 2>/dev/null && echo -e "${GREEN}✓ Symbols copied to $DEST${NC}" || echo -e "${RED}✗ Failed to copy symbols${NC}" cp "$SYM_FILE" "$DEST/" 2>/dev/null \
&& echo -e " ${G}✓ Symbols copied${N}" \
|| echo -e " ${R}✗ Failed to copy symbols${N}"
fi fi
else else
echo -e "${RED}✗ Directory does not exist: $DEST${NC}" echo -e " ${R}✗ Directory not found: $DEST${N}"
fi fi
fi fi
echo echo
echo -e "${BOLD}═══════════════════════════════════════${NC}" echo -e "${B}═══════════════════════════════════════${N}"
echo -e "${GREEN}Ready to upload to Play Console!${NC}" echo -e "${G}Ready to upload to Play Console!${N}"
echo -e "${BOLD}═══════════════════════════════════════${NC}" echo -e "${B}═══════════════════════════════════════${N}"