feat: Versioning automatique YY.MM.DD.NN pour DEV

- 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 <noreply@anthropic.com>
This commit is contained in:
2026-01-26 12:14:54 +01:00
parent b3e03ef6e6
commit d6c4c6d228

View File

@@ -15,7 +15,8 @@ set -euo pipefail
START_TIME=$(($(date +%s%N)/1000000)) START_TIME=$(($(date +%s%N)/1000000))
echo "[$(date '+%H:%M:%S.%3N')] Début du script deploy-app.sh" 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 # Configuration générale
@@ -144,51 +145,114 @@ ARCHIVE_NAME="app-deploy-${TIMESTAMP}.tar.gz"
TEMP_ARCHIVE="/tmp/${ARCHIVE_NAME}" TEMP_ARCHIVE="/tmp/${ARCHIVE_NAME}"
if [ "$SOURCE_TYPE" = "local_build" ]; then if [ "$SOURCE_TYPE" = "local_build" ]; then
# DEV: Build Flutter et créer une archive # DEV: Build Flutter sur IN1 et créer une archive
echo_step "Building Flutter app for DEV..." echo_step "Building Flutter app on IN1 for DEV..."
# Configuration du cache local (partagé web + iOS/Android) # Variables pour IN1
echo_info "📦 Configuration du cache local pour builds web et mobile..." IN1_HOST="IN1"
export PUB_CACHE="$PWD/.pub-cache-local" IN1_PROJECT_PATH="/home/pierre/dev/geosector/app"
export GRADLE_USER_HOME="$PWD/.gradle-local"
mkdir -p "$PUB_CACHE" "$GRADLE_USER_HOME"
echo_info " Cache Pub: $PUB_CACHE" echo_info "🖥️ Compilation distante sur IN1:${IN1_PROJECT_PATH}"
echo_info " Cache Gradle: $GRADLE_USER_HOME"
echo_info " → Packages patchés seront prêts pour transfert iOS/Android"
# Charger les variables d'environnement # Charger les variables d'environnement localement pour la version
if [ ! -f .env-deploy-dev ]; then if [ ! -f .env-deploy-dev ]; then
echo_error "Missing .env-deploy-dev file" echo_error "Missing .env-deploy-dev file"
fi fi
source .env-deploy-dev source .env-deploy-dev
# Mise à jour de la version # Système automatique de versioning YY.MM.DD.NN
echo_info "Managing version..." 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 if [ -f ../VERSION ]; then
VERSION=$(cat ../VERSION | tr -d '\n\r' | tr -d ' ') CURRENT_VERSION=$(cat ../VERSION | tr -d '\n\r' | tr -d ' ')
echo_info "Version found: $VERSION" echo_info "Current version: $CURRENT_VERSION"
else
echo_warning "VERSION file not found" # Extraire la partie date et le build number
read -p "Enter version number (x.x.x format): " VERSION if [[ $CURRENT_VERSION =~ ^([0-9]{2}\.[0-9]{2}\.[0-9]{2})\.([0-9]{2})$ ]]; then
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then VERSION_DATE="${BASH_REMATCH[1]}"
echo "$VERSION" > ../VERSION BUILD_NUM="${BASH_REMATCH[2]}"
echo_info "VERSION file created with $VERSION"
# 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 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 fi
else
# Pas de fichier VERSION, créer avec .01
NEW_BUILD="01"
echo_warning "VERSION file not found, creating new one"
fi 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 # Génération du build number et mise à jour du pubspec.yaml
BUILD_NUMBER=$(echo $VERSION | tr -d '.') BUILD_NUMBER=$(echo $VERSION | tr -d '.')
FULL_VERSION="${VERSION}+${BUILD_NUMBER}" 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" 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) # Lancer la compilation sur IN1 via SSH
echo_info "Auto-generating app_info_service.dart with version $VERSION+$BUILD_NUMBER..." echo_info "🚀 Lancement de la compilation sur IN1..."
cat > lib/core/services/app_info_service.dart <<EOF BUILD_START=$(($(date +%s%N)/1000000))
ssh ${IN1_HOST} "bash -l -s" <<'REMOTE_SCRIPT' || echo_error "Remote build failed on IN1"
set -euo pipefail
# Charger le profil utilisateur pour avoir Flutter dans le PATH
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
if [ -f ~/.profile ]; then
source ~/.profile
fi
cd /home/pierre/dev/geosector/app
echo "[IN1] Starting Flutter build process..."
# Charger les variables d'environnement
if [ ! -f .env-deploy-dev ]; then
echo "ERROR: Missing .env-deploy-dev file"
exit 1
fi
source .env-deploy-dev
# Lire la version
if [ -f ../VERSION ]; then
VERSION=$(cat ../VERSION | tr -d '\n\r' | tr -d ' ')
echo "[IN1] Version: $VERSION"
else
echo "ERROR: VERSION file not found"
exit 1
fi
# Génération du build number
BUILD_NUMBER=$(echo $VERSION | tr -d '.')
FULL_VERSION="${VERSION}+${BUILD_NUMBER}"
echo "[IN1] Full version: $FULL_VERSION"
# Mise à jour du pubspec.yaml
sed -i "s/^version: .*/version: $FULL_VERSION/" pubspec.yaml
# Génération automatique du fichier AppInfoService
echo "[IN1] Generating app_info_service.dart..."
cat > lib/core/services/app_info_service.dart <<EOF
// ⚠️ AUTO-GENERATED FILE - DO NOT EDIT MANUALLY // ⚠️ AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
// This file is automatically generated by deploy-app.sh script // This file is automatically generated by deploy-app.sh script
// Last update: $(date '+%Y-%m-%d %H:%M:%S') // Last update: $(date '+%Y-%m-%d %H:%M:%S')
@@ -214,53 +278,60 @@ class AppInfoService {
static const String packageName = 'fr.geosector.app3'; static const String packageName = 'fr.geosector.app3';
} }
EOF EOF
echo_info "✓ app_info_service.dart updated successfully"
# Mode de compilation en RELEASE (production) # Configuration du cache local
echo_info "🏁 Mode RELEASE - Compilation optimisée pour production" echo "[IN1] Configuring local cache..."
BUILD_FLAGS="--release" export PUB_CACHE="$PWD/.pub-cache-local"
export GRADLE_USER_HOME="$PWD/.gradle-local"
mkdir -p "$PUB_CACHE" "$GRADLE_USER_HOME"
# Nettoyage # Nettoyage
echo_info "Cleaning previous builds..." echo "[IN1] Cleaning previous builds..."
rm -rf .dart_tool build .packages pubspec.lock 2>/dev/null || true rm -rf .dart_tool build .packages pubspec.lock 2>/dev/null || true
flutter clean || echo_warning "Flutter clean partially failed" flutter clean
# Build # Build
echo_info "Getting dependencies..." echo "[IN1] Getting dependencies..."
flutter pub get || echo_error "Flutter pub get failed" flutter pub get
# Patch nfc_manager 3.3.0 (AndroidManifest namespace) # Patch nfc_manager 3.3.0
echo_info "Applying nfc_manager 3.3.0 patch..." echo "[IN1] Applying nfc_manager patch..."
./fastlane/scripts/commun/fix-nfc-manager.sh || echo_error "nfc_manager patch failed" ./fastlane/scripts/commun/fix-nfc-manager.sh
echo_info "Cleaning generated files..." echo "[IN1] Cleaning generated files..."
dart run build_runner clean || echo_error "Build runner clean failed" dart run build_runner clean
echo_info "Generating code files..." echo "[IN1] Generating code files..."
dart run build_runner build --delete-conflicting-outputs || echo_error "Code generation failed" dart run build_runner build --delete-conflicting-outputs
echo_info "Building Flutter web application..." # Mode de compilation en RELEASE
# Mesure du temps de compilation Flutter echo "[IN1] 🏁 Building Flutter web (RELEASE mode)..."
BUILD_START=$(($(date +%s%N)/1000000)) flutter build web --release
echo_info "[$(date '+%H:%M:%S.%3N')] Début de la compilation Flutter (Mode: RELEASE)"
flutter build web $BUILD_FLAGS || echo_error "Flutter build failed" 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_END=$(($(date +%s%N)/1000000))
BUILD_TIME=$((BUILD_END - BUILD_START)) BUILD_TIME=$((BUILD_END - BUILD_START))
echo_info "[$(date '+%H:%M:%S.%3N')] Fin de la compilation Flutter" echo_info "⏱️ Temps de compilation sur IN1: ${BUILD_TIME} ms ($((BUILD_TIME/1000)) secondes)"
echo_info "⏱️ Temps de compilation Flutter: ${BUILD_TIME} ms ($((BUILD_TIME/1000)) secondes)"
echo_info "Fixing web assets structure..." # Récupérer l'archive depuis IN1
./copy-web-images.sh || echo_error "Failed to fix web assets" 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) # Nettoyer sur IN1
echo_info "Creating archive from build..." ssh ${IN1_HOST} "rm -f /tmp/app-deploy-build.tar.gz"
tar -czf "${TEMP_ARCHIVE}" -C ${FLUTTER_BUILD_DIR} \
--exclude='*.symbols' \
--exclude='*.kra' \
--exclude='.DS_Store' \
. || echo_error "Failed to create archive"
create_local_backup "${TEMP_ARCHIVE}" "dev" create_local_backup "${TEMP_ARCHIVE}" "dev"