ihm_client/scripts/auto-ssh-push.sh

156 lines
4.5 KiB
Bash
Executable File

#!/bin/bash
# Script d'automatisation des push SSH pour ihm_client
# Utilise automatiquement la clé SSH pour tous les push
set -e
echo "🔑 Configuration automatique SSH pour push ihm_client..."
# Configuration SSH automatique
echo "⚙️ Configuration Git pour utiliser SSH..."
git config --global url."git@git.4nkweb.com:".insteadOf "https://git.4nkweb.com/"
# Vérifier la configuration SSH
echo "🔍 Vérification de la configuration SSH..."
if ! ssh -T git@git.4nkweb.com 2>&1 | grep -q "successfully authenticated"; then
echo "❌ Échec de l'authentification SSH"
echo "💡 Vérifiez que votre clé SSH est configurée :"
echo " 1. ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_4nk"
echo " 2. Ajouter la clé publique à votre compte Gitea"
echo " 3. ssh-add ~/.ssh/id_ed25519_4nk"
exit 1
fi
echo "✅ Authentification SSH réussie"
# Fonction pour push automatique
auto_push() {
local branch=${1:-$(git branch --show-current)}
local commit_message=${2:-"Auto-commit $(date '+%Y-%m-%d %H:%M:%S')"}
echo "🚀 Push automatique sur la branche: $branch"
# Ajouter tous les changements
git add .
# Commiter avec le message fourni
git commit -m "$commit_message"
# Push avec SSH automatique
echo "📤 Push vers origin/$branch..."
git push origin "$branch"
echo "✅ Push réussi !"
}
# Fonction pour push avec message personnalisé
push_with_message() {
local message="$1"
local branch=${2:-$(git branch --show-current)}
echo "💬 Push avec message: $message"
auto_push "$branch" "$message"
}
# Fonction pour push rapide (sans message)
quick_push() {
local branch=${1:-$(git branch --show-current)}
auto_push "$branch"
}
# Fonction pour push sur une branche spécifique
push_branch() {
local branch="$1"
local message=${2:-"Update $branch $(date '+%Y-%m-%d %H:%M:%S')"}
echo "🌿 Push sur la branche: $branch"
auto_push "$branch" "$message"
}
# Fonction pour push et merge vers main
push_and_merge() {
local source_branch=${1:-$(git branch --show-current)}
local target_branch=${2:-main}
echo "🔄 Push et merge $source_branch -> $target_branch"
# Push de la branche source
auto_push "$source_branch"
# Demander confirmation pour le merge
read -p "Voulez-vous créer une Pull Request pour merger vers $target_branch ? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "🔗 Création de la Pull Request..."
echo "💡 Allez sur: https://git.4nkweb.com/4nk/ihm_client/compare/$target_branch...$source_branch"
fi
}
# Fonction pour status et push conditionnel
status_and_push() {
echo "📊 Statut du repository:"
git status --short
if [[ -n $(git status --porcelain) ]]; then
echo "📝 Changements détectés, push automatique..."
auto_push
else
echo "✅ Aucun changement à pousser"
fi
}
# Menu interactif si aucun argument fourni
if [[ $# -eq 0 ]]; then
echo "🤖 Script de push SSH automatique pour ihm_client"
echo ""
echo "Options disponibles:"
echo " auto-push.sh quick - Push rapide"
echo " auto-push.sh message \"Mon message\" - Push avec message"
echo " auto-push.sh branch nom-branche - Push sur branche spécifique"
echo " auto-push.sh merge [source] [target] - Push et préparation merge"
echo " auto-push.sh status - Status et push conditionnel"
echo ""
echo "Exemples:"
echo " ./scripts/auto-ssh-push.sh quick"
echo " ./scripts/auto-ssh-push.sh message \"feat: nouvelle fonctionnalité\""
echo " ./scripts/auto-ssh-push.sh branch feature/nouvelle-fonctionnalite"
echo " ./scripts/auto-ssh-push.sh merge feature/nouvelle-fonctionnalite main"
echo ""
exit 0
fi
# Traitement des arguments
case "$1" in
"quick")
quick_push
;;
"message")
if [[ -z "$2" ]]; then
echo "❌ Message requis pour l'option 'message'"
exit 1
fi
push_with_message "$2"
;;
"branch")
if [[ -z "$2" ]]; then
echo "❌ Nom de branche requis pour l'option 'branch'"
exit 1
fi
push_branch "$2" "$3"
;;
"merge")
push_and_merge "$2" "$3"
;;
"status")
status_and_push
;;
*)
echo "❌ Option inconnue: $1"
echo "💡 Utilisez './scripts/auto-ssh-push.sh' pour voir les options"
exit 1
;;
esac
echo "🎯 Push SSH automatique terminé !"