name: Deploy to Test Server on: push: branches: - develop jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Set SSH key permissions shell: bash run: | # Izpis trenutne delovne mape in seznama datotek pwd ls -la ls -la .gitea/runner/ || echo "Mapa runner ne obstaja" # Poskusimo najti SSH ključ find . -name "id_rsa_gitea*" -type f # Uporabimo SSH ključ v bazi repozitorija if [ -f ".gitea/runner/id_rsa_gitea" ]; then chmod 600 .gitea/runner/id_rsa_gitea echo "SSH ključ najden in nastavljen" else echo "SSH ključ ni bil najden na pričakovani lokaciji!" # Ustvarimo SSH ključ iz kodiranega besedila mkdir -p ~/.ssh echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa_gitea chmod 600 ~/.ssh/id_rsa_gitea echo "SSH ključ ustvarjen iz skrivnosti" fi - name: Install rsync shell: bash run: | # Preverimo, ali lahko namestimo rsync echo "Preverjanje možnosti namestitve rsync..." if command -v apt-get &> /dev/null; then echo "Poskušam namestiti rsync z apt-get..." sudo apt-get update && sudo apt-get install -y rsync || echo "Ni mogoče namestiti rsync z apt-get" elif command -v yum &> /dev/null; then echo "Poskušam namestiti rsync z yum..." sudo yum install -y rsync || echo "Ni mogoče namestiti rsync z yum" else echo "Ni mogoče namestiti rsync - manjka paketni upravljalnik" fi # Preverimo, ali je rsync nameščen if command -v rsync &> /dev/null; then echo "rsync je nameščen, verzija:" rsync --version | head -n 1 else echo "rsync ni nameščen, uporabili bomo tar" fi - name: Deploy to test server shell: bash run: | # Najprej preverimo SSH povezavo if [ -f ".gitea/runner/id_rsa_gitea" ]; then SSH_KEY=".gitea/runner/id_rsa_gitea" else SSH_KEY="~/.ssh/id_rsa_gitea" fi echo "Uporabljam SSH ključ: $SSH_KEY" # Testiranje SSH povezave ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "echo 'SSH povezava uspešna'" # Izbrišemo obstoječo vsebino v mapi vtičnika ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "rm -rf test.forexanalysis.com/wp-content/plugins/custom_wheel\ 2/*" # Poskusimo najprej z rsync, če je nameščen if command -v rsync &> /dev/null; then echo "Prenašanje datotek z rsync..." rsync -avz -e "ssh -p 5050 -i $SSH_KEY -o StrictHostKeyChecking=no" --exclude=".git" --exclude=".gitea" --exclude="id_rsa_gitea*" ./ forexana@152.89.234.215:test.forexanalysis.com/wp-content/plugins/custom_wheel\ 2/ else # Alternativna metoda prenosa z uporabo tar preko SSH echo "Prenašanje datotek s tar preko SSH..." tar czf - --exclude=".git" --exclude=".gitea" --exclude="id_rsa_gitea*" ./ | ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "tar xzf - -C test.forexanalysis.com/wp-content/plugins/custom_wheel\ 2/" fi # Nastavimo pravilna dovoljenja ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "chmod -R 755 test.forexanalysis.com/wp-content/plugins/custom_wheel\ 2/" echo "Deployment completed successfully!"