Agrega release.sh: script interactivo para build + símbolos

This commit is contained in:
Super User
2026-06-17 21:01:51 -04:00
parent 5b24a79d5a
commit a15f81d1fc

138
release.sh Executable file
View File

@@ -0,0 +1,138 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
AAB_DIR="$ROOT/build/app/outputs/bundle/release"
FLUTTER="/opt/flutter/bin/flutter"
JAVA_HOME="/root/.sdkman/candidates/java/21.0.11-amzn"
ADB="/opt/android-sdk/platform-tools/adb"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
bar="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
len=${#bar}
progress() {
local pct=$1
local msg=$2
local filled=$(( pct * len / 100 ))
local empty=$(( len - filled ))
printf "\r${CYAN}[${bar:0:filled}${NC}${bar:0:empty}${CYAN}]${NC} %3d%% %s" "$pct" "$msg"
}
clear
echo -e "${BOLD}═══════════════════════════════════════${NC}"
echo -e "${BOLD} Factura del Hogar — Release Builder ${NC}"
echo -e "${BOLD}═══════════════════════════════════════${NC}"
echo
# --- Verify project root ---
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}"
exit 1
fi
NAME=$(grep "^name:" "$ROOT/pubspec.yaml" | head -1 | awk '{print $2}' | tr -d '"')
VERSION=$(grep "^version:" "$ROOT/pubspec.yaml" | head -1 | awk '{print $2}')
echo -e " Project ${CYAN}$NAME${NC}"
echo -e " Version ${CYAN}$VERSION${NC}"
echo -e " Output ${CYAN}$AAB_DIR${NC}"
echo
# --- Confirm ---
echo -e "${YELLOW}⚠ A release build will be created for Play Store.${NC}"
read -rp "$(echo -e ${BOLD}"Continue? [Y/n]: "${NC})" REPLY
REPLY="${REPLY:-y}"
if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}Canceled.${NC}"
exit 0
fi
echo
export JAVA_HOME="$JAVA_HOME"
# --- Clean ---
progress 5 "Cleaning previous build..."
"$FLUTTER" clean > /dev/null 2>&1
sleep 0.3
progress 8 "Done"
# --- Pub get ---
echo
progress 8 "Fetching dependencies..."
"$FLUTTER" pub get > /dev/null 2>&1
progress 12 "Done"
# --- Build AAB ---
echo
progress 12 "Building release AAB..."
BUILD_OUTPUT=$("$FLUTTER" build appbundle --release 2>&1)
if [ $? -ne 0 ]; then
echo -e "\n${RED}✗ Build failed:${NC}"
echo "$BUILD_OUTPUT"
exit 1
fi
progress 70 "AAB built successfully"
# --- Native debug symbols ---
echo
SYMBOLS_DIR="$ROOT/build/app/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib"
progress 70 "Packaging native debug symbols..."
if [ -d "$SYMBOLS_DIR" ]; then
cd "$SYMBOLS_DIR"
rm -f "$AAB_DIR/native-debug-symbols.zip"
zip -r "$AAB_DIR/native-debug-symbols.zip" . > /dev/null 2>&1
cd "$ROOT"
progress 90 "Symbols packaged"
else
echo -e "\n${YELLOW}⚠ No native libs found at $SYMBOLS_DIR${NC}"
fi
# --- Verify output ---
echo
progress 95 "Verifying..."
sleep 0.3
progress 100 "Complete!"
echo -e "\n\n"
# --- Results ---
echo -e "${BOLD}═══════════════════════════════════════${NC}"
echo -e "${GREEN}✓ Build successful!${NC}"
echo
AAB_FILE="$AAB_DIR/app-release.aab"
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_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 ---
read -rp "$(echo -e ${BOLD}"Move files to another location? [y/N]: "${NC})" MOVE_REPLY
MOVE_REPLY="${MOVE_REPLY:-n}"
if [[ "$MOVE_REPLY" =~ ^[Yy]$ ]]; then
read -rp "$(echo -e ${BOLD}"Destination directory: "${NC})" DEST
DEST="${DEST/#\~/$HOME}"
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}"
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}"
fi
else
echo -e "${RED}✗ Directory does not exist: $DEST${NC}"
fi
fi
echo
echo -e "${BOLD}═══════════════════════════════════════${NC}"
echo -e "${GREEN}Ready to upload to Play Console!${NC}"
echo -e "${BOLD}═══════════════════════════════════════${NC}"