From 0be9f81b5e8163992f2d6a613d53477c59ab2a44 Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Mon, 25 Aug 2025 16:56:16 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Automatisation=20SSH=20compl=C3=A8te=20?= =?UTF-8?q?pour=20push?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yml | 38 +++++----- scripts/auto-ssh-push.sh | 155 +++++++++++++++++++++++++++++++++++++++ scripts/setup-ssh-ci.sh | 24 +++--- 3 files changed, 186 insertions(+), 31 deletions(-) create mode 100755 scripts/auto-ssh-push.sh diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 72dfbb7..ecca100 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -9,7 +9,7 @@ on: jobs: test: runs-on: ubuntu-latest - + steps: - name: Setup SSH for Gitea run: | @@ -18,34 +18,34 @@ jobs: chmod 600 ~/.ssh/id_rsa ssh-keyscan -H git.4nkweb.com >> ~/.ssh/known_hosts git config --global url."git@git.4nkweb.com:".insteadOf "https://git.4nkweb.com/" - + - name: Checkout code uses: actions/checkout@v3 with: ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} submodules: recursive - + - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '20' cache: 'npm' - + - name: Install dependencies run: npm ci - + - name: Run linting run: npm run lint - + - name: Run type checking run: npm run type-check - + - name: Run tests run: npm run test - + - name: Build application run: npm run build - + - name: Test Docker build run: | docker build -f Dockerfile.4nk-node -t ihm-client:test . @@ -54,7 +54,7 @@ jobs: security: runs-on: ubuntu-latest needs: test - + steps: - name: Setup SSH for Gitea run: | @@ -63,30 +63,30 @@ jobs: chmod 600 ~/.ssh/id_rsa ssh-keyscan -H git.4nkweb.com >> ~/.ssh/known_hosts git config --global url."git@git.4nkweb.com:".insteadOf "https://git.4nkweb.com/" - + - name: Checkout code uses: actions/checkout@v3 with: ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} - + - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '20' - + - name: Install dependencies run: npm ci - + - name: Run security audit run: npm audit --audit-level=moderate - + - name: Check for known vulnerabilities run: npm audit --audit-level=high integration-test: runs-on: ubuntu-latest needs: test - + steps: - name: Setup SSH for Gitea run: | @@ -95,15 +95,15 @@ jobs: chmod 600 ~/.ssh/id_rsa ssh-keyscan -H git.4nkweb.com >> ~/.ssh/known_hosts git config --global url."git@git.4nkweb.com:".insteadOf "https://git.4nkweb.com/" - + - name: Checkout code uses: actions/checkout@v3 with: ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} - + - name: Setup Docker Buildx uses: docker/setup-buildx-action@v2 - + - name: Build and test Docker integration run: | docker build -f Dockerfile.4nk-node -t ihm-client:integration . diff --git a/scripts/auto-ssh-push.sh b/scripts/auto-ssh-push.sh new file mode 100755 index 0000000..f8d804b --- /dev/null +++ b/scripts/auto-ssh-push.sh @@ -0,0 +1,155 @@ +#!/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é !" diff --git a/scripts/setup-ssh-ci.sh b/scripts/setup-ssh-ci.sh index f1e9ac8..63b3a6d 100755 --- a/scripts/setup-ssh-ci.sh +++ b/scripts/setup-ssh-ci.sh @@ -10,25 +10,25 @@ echo "🔑 Configuration automatique de la clé SSH pour ihm_client CI/CD..." # Vérifier si on est dans un environnement CI if [ -n "$CI" ]; then echo "✅ Environnement CI détecté" - + # Configuration SSH pour Gitea Actions if [ -n "$SSH_PRIVATE_KEY" ]; then echo "🔐 Configuration de la clé SSH privée..." - + # Créer le répertoire SSH mkdir -p ~/.ssh chmod 700 ~/.ssh - + # Écrire la clé privée echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa - + # Ajouter la clé publique correspondante (si disponible) if [ -n "$SSH_PUBLIC_KEY" ]; then echo "$SSH_PUBLIC_KEY" > ~/.ssh/id_rsa.pub chmod 644 ~/.ssh/id_rsa.pub fi - + # Configuration SSH pour git.4nkweb.com cat > ~/.ssh/config << EOF Host git.4nkweb.com @@ -38,9 +38,9 @@ Host git.4nkweb.com StrictHostKeyChecking no UserKnownHostsFile=/dev/null EOF - + chmod 600 ~/.ssh/config - + # Tester la connexion SSH echo "🧪 Test de connexion SSH vers git.4nkweb.com..." if ssh -T git@git.4nkweb.com 2>&1 | grep -q "Welcome"; then @@ -48,24 +48,24 @@ EOF else echo "⚠️ Connexion SSH établie (message de bienvenue non détecté)" fi - + # Configurer Git pour utiliser SSH git config --global url."git@git.4nkweb.com:".insteadOf "https://git.4nkweb.com/" - + echo "✅ Configuration SSH terminée" else echo "⚠️ Variable SSH_PRIVATE_KEY non définie, utilisation de HTTPS" fi else echo "ℹ️ Environnement local détecté" - + # Vérifier si une clé SSH existe if [ -f ~/.ssh/id_rsa ]; then echo "🔑 Clé SSH locale trouvée" - + # Configurer Git pour utiliser SSH localement git config --global url."git@git.4nkweb.com:".insteadOf "https://git.4nkweb.com/" - + echo "✅ Configuration SSH locale terminée" else echo "⚠️ Aucune clé SSH trouvée, configuration manuelle requise"