From d6c4c6d2289063a4737411df9d937f15a595e670 Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 26 Jan 2026 12:14:54 +0100 Subject: [PATCH] feat: Versioning automatique YY.MM.DD.NN pour DEV MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Système 100% automatique de numérotation de version - Format : YY.MM.DD.NN (ex: 26.01.27.01) - Détection automatique de la date du jour - Incrémentation auto du build number (.01 → .02 → .03...) - Reset auto à .01 lors d'un changement de date - Compatible avec ancien format (conversion auto) Logique : 1. Récupération date système : date +%y.%m.%d 2. Si date différente de VERSION → YY.MM.DD.01 3. Si même date → incrémenter dernier nombre 4. Écriture dans VERSION et pubspec.yaml Exemple : - 26/01 build 1 → 26.01.26.01 - 26/01 build 2 → 26.01.26.02 - 27/01 build 1 → 26.01.27.01 (reset auto) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/deploy-app.sh | 201 +++++++++++++++++++++++++++++++--------------- 1 file changed, 136 insertions(+), 65 deletions(-) diff --git a/app/deploy-app.sh b/app/deploy-app.sh index e75ba1f8..029c9eee 100755 --- a/app/deploy-app.sh +++ b/app/deploy-app.sh @@ -15,7 +15,8 @@ set -euo pipefail START_TIME=$(($(date +%s%N)/1000000)) echo "[$(date '+%H:%M:%S.%3N')] Début du script deploy-app.sh" -cd /home/pierre/dev/geosector/app +# Note: Le code source est sur IN1:/home/pierre/dev/geosector/app +# Ce script peut être lancé depuis n'importe où (desktop/laptop) # ===================================== # Configuration générale @@ -144,51 +145,114 @@ ARCHIVE_NAME="app-deploy-${TIMESTAMP}.tar.gz" TEMP_ARCHIVE="/tmp/${ARCHIVE_NAME}" if [ "$SOURCE_TYPE" = "local_build" ]; then - # DEV: Build Flutter et créer une archive - echo_step "Building Flutter app for DEV..." + # DEV: Build Flutter sur IN1 et créer une archive + echo_step "Building Flutter app on IN1 for DEV..." - # Configuration du cache local (partagé web + iOS/Android) - echo_info "📦 Configuration du cache local pour builds web et mobile..." - export PUB_CACHE="$PWD/.pub-cache-local" - export GRADLE_USER_HOME="$PWD/.gradle-local" - mkdir -p "$PUB_CACHE" "$GRADLE_USER_HOME" + # Variables pour IN1 + IN1_HOST="IN1" + IN1_PROJECT_PATH="/home/pierre/dev/geosector/app" - echo_info " Cache Pub: $PUB_CACHE" - echo_info " Cache Gradle: $GRADLE_USER_HOME" - echo_info " → Packages patchés seront prêts pour transfert iOS/Android" + echo_info "🖥️ Compilation distante sur IN1:${IN1_PROJECT_PATH}" - # Charger les variables d'environnement + # Charger les variables d'environnement localement pour la version if [ ! -f .env-deploy-dev ]; then echo_error "Missing .env-deploy-dev file" fi source .env-deploy-dev - # Mise à jour de la version - echo_info "Managing version..." + # Système automatique de versioning YY.MM.DD.NN + echo_info "Managing version (automatic YY.MM.DD.NN)..." + + # Date du jour au format YY.MM.DD + TODAY=$(date +%y.%m.%d) + if [ -f ../VERSION ]; then - VERSION=$(cat ../VERSION | tr -d '\n\r' | tr -d ' ') - echo_info "Version found: $VERSION" - else - echo_warning "VERSION file not found" - read -p "Enter version number (x.x.x format): " VERSION - if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "$VERSION" > ../VERSION - echo_info "VERSION file created with $VERSION" + CURRENT_VERSION=$(cat ../VERSION | tr -d '\n\r' | tr -d ' ') + echo_info "Current version: $CURRENT_VERSION" + + # Extraire la partie date et le build number + if [[ $CURRENT_VERSION =~ ^([0-9]{2}\.[0-9]{2}\.[0-9]{2})\.([0-9]{2})$ ]]; then + VERSION_DATE="${BASH_REMATCH[1]}" + BUILD_NUM="${BASH_REMATCH[2]}" + + # Si la date a changé, reset à .01 + if [ "$VERSION_DATE" != "$TODAY" ]; then + NEW_BUILD="01" + echo_info "Date changed: $VERSION_DATE → $TODAY, resetting build to 01" + else + # Incrémenter le build number + NEW_BUILD=$(printf "%02d" $((10#$BUILD_NUM + 1))) + echo_info "Same date, incrementing build: $BUILD_NUM → $NEW_BUILD" + fi else - echo_error "Invalid version format" + # Format ancien ou invalide, créer nouveau format + NEW_BUILD="01" + echo_warning "Old version format detected, creating new format" fi + else + # Pas de fichier VERSION, créer avec .01 + NEW_BUILD="01" + echo_warning "VERSION file not found, creating new one" fi - + + # Construire la nouvelle version complète + VERSION="${TODAY}.${NEW_BUILD}" + echo "$VERSION" > ../VERSION + echo_success "✅ New version: $VERSION" + # Génération du build number et mise à jour du pubspec.yaml BUILD_NUMBER=$(echo $VERSION | tr -d '.') FULL_VERSION="${VERSION}+${BUILD_NUMBER}" - echo_info "Full version: $FULL_VERSION" + echo_info "Full version for pubspec.yaml: $FULL_VERSION" sed -i "s/^version: .*/version: $FULL_VERSION/" pubspec.yaml || echo_error "Failed to update pubspec.yaml" - # Génération automatique du fichier AppInfoService (remplace package_info_plus) - echo_info "Auto-generating app_info_service.dart with version $VERSION+$BUILD_NUMBER..." - cat > lib/core/services/app_info_service.dart < lib/core/services/app_info_service.dart </dev/null || true - flutter clean || echo_warning "Flutter clean partially failed" +# Nettoyage +echo "[IN1] Cleaning previous builds..." +rm -rf .dart_tool build .packages pubspec.lock 2>/dev/null || true +flutter clean - # Build - echo_info "Getting dependencies..." - flutter pub get || echo_error "Flutter pub get failed" +# Build +echo "[IN1] Getting dependencies..." +flutter pub get - # Patch nfc_manager 3.3.0 (AndroidManifest namespace) - echo_info "Applying nfc_manager 3.3.0 patch..." - ./fastlane/scripts/commun/fix-nfc-manager.sh || echo_error "nfc_manager patch failed" - - echo_info "Cleaning generated files..." - dart run build_runner clean || echo_error "Build runner clean failed" - - echo_info "Generating code files..." - dart run build_runner build --delete-conflicting-outputs || echo_error "Code generation failed" - - echo_info "Building Flutter web application..." - # Mesure du temps de compilation Flutter - BUILD_START=$(($(date +%s%N)/1000000)) - echo_info "[$(date '+%H:%M:%S.%3N')] Début de la compilation Flutter (Mode: RELEASE)" +# Patch nfc_manager 3.3.0 +echo "[IN1] Applying nfc_manager patch..." +./fastlane/scripts/commun/fix-nfc-manager.sh - flutter build web $BUILD_FLAGS || echo_error "Flutter build failed" +echo "[IN1] Cleaning generated files..." +dart run build_runner clean + +echo "[IN1] Generating code files..." +dart run build_runner build --delete-conflicting-outputs + +# Mode de compilation en RELEASE +echo "[IN1] 🏁 Building Flutter web (RELEASE mode)..." +flutter build web --release + +echo "[IN1] Fixing web assets structure..." +./copy-web-images.sh + +# Créer l'archive sur IN1 +echo "[IN1] Creating deployment archive..." +tar -czf /tmp/app-deploy-build.tar.gz -C build/web \ + --exclude='*.symbols' \ + --exclude='*.kra' \ + --exclude='.DS_Store' \ + . + +echo "[IN1] Build completed successfully!" +REMOTE_SCRIPT BUILD_END=$(($(date +%s%N)/1000000)) BUILD_TIME=$((BUILD_END - BUILD_START)) - echo_info "[$(date '+%H:%M:%S.%3N')] Fin de la compilation Flutter" - echo_info "⏱️ Temps de compilation Flutter: ${BUILD_TIME} ms ($((BUILD_TIME/1000)) secondes)" + echo_info "⏱️ Temps de compilation sur IN1: ${BUILD_TIME} ms ($((BUILD_TIME/1000)) secondes)" - echo_info "Fixing web assets structure..." - ./copy-web-images.sh || echo_error "Failed to fix web assets" + # Récupérer l'archive depuis IN1 + echo_info "📥 Downloading archive from IN1..." + scp ${IN1_HOST}:/tmp/app-deploy-build.tar.gz ${TEMP_ARCHIVE} || echo_error "Failed to download archive from IN1" - # Créer l'archive depuis le build (avec exclusions pour réduire la taille) - echo_info "Creating archive from build..." - tar -czf "${TEMP_ARCHIVE}" -C ${FLUTTER_BUILD_DIR} \ - --exclude='*.symbols' \ - --exclude='*.kra' \ - --exclude='.DS_Store' \ - . || echo_error "Failed to create archive" + # Nettoyer sur IN1 + ssh ${IN1_HOST} "rm -f /tmp/app-deploy-build.tar.gz" create_local_backup "${TEMP_ARCHIVE}" "dev"