feat: Automatisation SSH complète pour push
This commit is contained in:
parent
ea97ffa733
commit
0be9f81b5e
@ -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 .
|
||||
|
155
scripts/auto-ssh-push.sh
Executable file
155
scripts/auto-ssh-push.sh
Executable file
@ -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é !"
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user