#!/bin/bash # πŸš€ NETGESCON - WORKFLOW GIT DISTRIBUITO # Creato: 19/07/2025 - Workflow Michele + AI set -e echo "πŸš€ === NETGESCON - WORKFLOW GIT DISTRIBUITO ===" echo "πŸ“… $(date '+%Y-%m-%d %H:%M:%S')" echo "" # === CONFIGURAZIONI === CURRENT_BRANCH=$(git branch --show-current) VERSION_FILE="docs/versione/VERSION.txt" CHANGELOG_FILE="docs/versione/CHANGELOG.md" # === FUNZIONI === # Funzione per incrementare versione increment_version() { local version_type=$1 if [ ! -f "$VERSION_FILE" ]; then echo "1.0.0" > "$VERSION_FILE" echo " βœ… File versione creato: 1.0.0" return fi local current_version=$(cat "$VERSION_FILE") local major=$(echo $current_version | cut -d. -f1) local minor=$(echo $current_version | cut -d. -f2) local patch=$(echo $current_version | cut -d. -f3) case $version_type in "major") major=$((major + 1)) minor=0 patch=0 ;; "minor") minor=$((minor + 1)) patch=0 ;; "patch") patch=$((patch + 1)) ;; esac local new_version="$major.$minor.$patch" echo "$new_version" > "$VERSION_FILE" echo " βœ… Versione aggiornata: $current_version β†’ $new_version" } # Funzione per aggiornare changelog update_changelog() { local version=$1 local description="$2" # Crea changelog se non existe if [ ! -f "$CHANGELOG_FILE" ]; then cat > "$CHANGELOG_FILE" << 'EOF' # πŸ“‹ NETGESCON - CHANGELOG Tutte le modifiche importanti al progetto NetGescon sono documentate in questo file. Il formato Γ¨ basato su [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), e questo progetto aderisce al [Semantic Versioning](https://semver.org/spec/v2.0.0.html). --- EOF fi # Aggiunge nuova entry in cima local temp_file=$(mktemp) local current_date=$(date '+%Y-%m-%d') # Header del file head -n 8 "$CHANGELOG_FILE" > "$temp_file" # Nuova entry cat >> "$temp_file" << EOF ## [${version}] - ${current_date} ### Added - ${description} EOF # Resto del file tail -n +9 "$CHANGELOG_FILE" >> "$temp_file" mv "$temp_file" "$CHANGELOG_FILE" echo " βœ… Changelog aggiornato" } # === COMANDI PRINCIPALI === case "${1:-help}" in # === SVILUPPO === "dev-start") echo "🌿 Inizio sviluppo feature..." if [ -z "$2" ]; then echo "❌ Specificare nome feature: $0 dev-start nome-feature" exit 1 fi feature_name="$2" branch_name="feature/$feature_name" git checkout development git pull origin development git checkout -b "$branch_name" echo " βœ… Branch creato: $branch_name" echo " πŸ“ Ora puoi sviluppare la feature '$feature_name'" ;; "dev-commit") echo "πŸ“¦ Commit sviluppo..." if [ -z "$2" ]; then echo "❌ Specificare messaggio: $0 dev-commit 'messaggio'" exit 1 fi git add . git commit -m "🚧 $2 πŸ“ Branch: $CURRENT_BRANCH πŸ”„ Sviluppo in corso πŸ“… $(date '+%Y-%m-%d %H:%M:%S')" echo " βœ… Commit creato sul branch $CURRENT_BRANCH" ;; "dev-finish") echo "🎯 Finalizzazione feature..." if [[ ! "$CURRENT_BRANCH" =~ ^feature/ ]]; then echo "❌ Devi essere su un branch feature/" exit 1 fi feature_name=$(echo "$CURRENT_BRANCH" | sed 's/feature\///') # Push del branch git push origin "$CURRENT_BRANCH" # Merge in development git checkout development git pull origin development git merge --no-ff "$CURRENT_BRANCH" -m "βœ… Feature completata: $feature_name πŸ“‹ Merge feature/$feature_name in development 🎯 Feature pronta per testing πŸ“… $(date '+%Y-%m-%d %H:%M:%S')" # Pulizia git branch -d "$CURRENT_BRANCH" git push origin --delete "$CURRENT_BRANCH" git push origin development echo " βœ… Feature '$feature_name' integrata in development" ;; # === RELEASE === "release-start") echo "πŸš€ Inizio preparazione release..." version_type="${2:-patch}" git checkout development git pull origin development git checkout release git pull origin release git merge --no-ff development -m "πŸ”„ Merge development in release per nuova versione" # Incrementa versione increment_version "$version_type" new_version=$(cat "$VERSION_FILE") # Aggiorna changelog update_changelog "$new_version" "Nuova release con feature sviluppate" # Commit versione git add "$VERSION_FILE" "$CHANGELOG_FILE" git commit -m "🏷️ Bump versione a $new_version πŸ“‹ Preparazione release $new_version πŸ”„ Changelog aggiornato πŸ“… $(date '+%Y-%m-%d %H:%M:%S')" git push origin release echo " βœ… Release $new_version preparata" ;; "release-deploy") echo "πŸš€ Deploy release in produzione..." if [ "$CURRENT_BRANCH" != "release" ]; then echo "❌ Devi essere sul branch release" exit 1 fi current_version=$(cat "$VERSION_FILE") # Merge in master git checkout master git pull origin master git merge --no-ff release -m "🎯 Release $current_version in produzione πŸ“‹ Deploy versione $current_version βœ… Testing completato πŸ“… $(date '+%Y-%m-%d %H:%M:%S')" # Tag versione git tag -a "v$current_version" -m "🏷️ Release $current_version πŸ“‹ Versione stabile per produzione 🎯 Tag: v$current_version πŸ“… $(date '+%Y-%m-%d %H:%M:%S')" # Push tutto git push origin master git push origin "v$current_version" # Merge master in development git checkout development git merge master git push origin development echo " βœ… Release $current_version deployata in produzione" echo " 🏷️ Tag creato: v$current_version" ;; # === HOTFIX === "hotfix-start") echo "🚨 Inizio hotfix urgente..." if [ -z "$2" ]; then echo "❌ Specificare nome hotfix: $0 hotfix-start nome-hotfix" exit 1 fi hotfix_name="$2" branch_name="hotfix/$hotfix_name" git checkout master git pull origin master git checkout -b "$branch_name" echo " βœ… Branch hotfix creato: $branch_name" ;; "hotfix-deploy") echo "🚨 Deploy hotfix urgente..." if [[ ! "$CURRENT_BRANCH" =~ ^hotfix/ ]]; then echo "❌ Devi essere su un branch hotfix/" exit 1 fi hotfix_name=$(echo "$CURRENT_BRANCH" | sed 's/hotfix\///') # Incrementa patch version increment_version "patch" new_version=$(cat "$VERSION_FILE") # Aggiorna changelog update_changelog "$new_version" "Hotfix: $hotfix_name" # Commit versione git add "$VERSION_FILE" "$CHANGELOG_FILE" git commit -m "🚨 Hotfix $new_version: $hotfix_name πŸ“‹ Fix urgente in produzione πŸ”„ Versione: $new_version πŸ“… $(date '+%Y-%m-%d %H:%M:%S')" # Merge in master git checkout master git merge --no-ff "$CURRENT_BRANCH" git tag -a "v$new_version" -m "🚨 Hotfix $new_version: $hotfix_name" git push origin master git push origin "v$new_version" # Merge in development e release git checkout development git merge master git push origin development git checkout release git merge master git push origin release # Pulizia git branch -d "$CURRENT_BRANCH" git push origin --delete "$CURRENT_BRANCH" echo " βœ… Hotfix $hotfix_name deployato: v$new_version" ;; # === UTILITΓ€ === "status") echo "πŸ“Š Status repository NetGescon:" echo "" echo "🌿 Branch corrente: $CURRENT_BRANCH" echo "πŸ“‹ Versione: $(cat $VERSION_FILE 2>/dev/null || echo 'Non definita')" echo "" echo "πŸ”„ Status Git:" git status --short echo "" echo "🌐 Remotes:" git remote -v echo "" echo "🏷️ Ultimi 5 tag:" git tag --sort=-version:refname | head -5 ;; "sync") echo "πŸ”„ Sincronizzazione con server..." git fetch origin git status echo "" echo "πŸ“‹ Branch disponibili:" git branch -a ;; "help"|*) echo "πŸ› οΈ === NETGESCON - WORKFLOW GIT COMANDI ===" echo "" echo "🌿 SVILUPPO:" echo " $0 dev-start [nome-feature] # Inizio nuova feature" echo " $0 dev-commit [messaggio] # Commit durante sviluppo" echo " $0 dev-finish # Finalizza feature" echo "" echo "πŸš€ RELEASE:" echo " $0 release-start [major|minor|patch] # Prepara release" echo " $0 release-deploy # Deploy in produzione" echo "" echo "🚨 HOTFIX:" echo " $0 hotfix-start [nome] # Inizio hotfix urgente" echo " $0 hotfix-deploy # Deploy hotfix" echo "" echo "πŸ› οΈ UTILITΓ€:" echo " $0 status # Status repository" echo " $0 sync # Sincronizza con server" echo " $0 help # Questa guida" echo "" echo "πŸ“‹ Struttura Branches:" echo " master β†’ Produzione stabile" echo " release β†’ Preparazione release" echo " development β†’ Integrazione feature" echo " feature/* β†’ Sviluppo singole feature" echo " hotfix/* β†’ Fix urgenti produzione" ;; esac echo "" echo "πŸ“… $(date '+%Y-%m-%d %H:%M:%S') - Operazione completata"