refactor(update.sh): improve update script reliability and clarity
Some checks failed
Deploy to production / deploy (push) Failing after 1s
Some checks failed
Deploy to production / deploy (push) Failing after 1s
- Changed shebang to use env for better portability. - Added error handling to ensure the script exits on failure. - Included a check to confirm the current branch is 'main' before proceeding. - Updated git commands to fetch and reset to origin/main, ensuring a clean state. - Enhanced user feedback messages for clarity.
This commit is contained in:
21
.gitea/workflows/deploy.yml
Normal file
21
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
name: Deploy to production
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Run deployment on production server
|
||||||
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.PROD_HOST }}
|
||||||
|
username: ${{ secrets.PROD_USER }}
|
||||||
|
key: ${{ secrets.PROD_SSH_KEY }}
|
||||||
|
port: ${{ secrets.PROD_PORT }}
|
||||||
|
script: |
|
||||||
|
/home/tsschulz/actualize-yourpart.sh
|
||||||
29
update.sh
29
update.sh
@@ -1,10 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
git fetch
|
|
||||||
git pull
|
|
||||||
|
|
||||||
echo "=== YourPart Update Script ==="
|
echo "=== YourPart Update Script ==="
|
||||||
echo "Dieses Script aktualisiert die Anwendung OHNE .env-Dateien zu überschreiben"
|
echo "Aktualisiert die Anwendung, ohne .env-Dateien zu überschreiben"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Prüfen ob wir im richtigen Verzeichnis sind
|
# Prüfen ob wir im richtigen Verzeichnis sind
|
||||||
@@ -13,18 +11,32 @@ if [ ! -f "package.json" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Sicherstellen, dass wir wirklich auf main sind
|
||||||
|
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
|
||||||
|
if [ "$CURRENT_BRANCH" != "main" ]; then
|
||||||
|
echo "Error: current branch is '$CURRENT_BRANCH', expected 'main'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remote-Stand holen
|
||||||
|
git fetch origin main
|
||||||
|
|
||||||
|
# Arbeitsbaum hart auf origin/main setzen
|
||||||
|
git reset --hard origin/main
|
||||||
|
|
||||||
|
# Optional: unversionierte Build-Artefakte entfernen
|
||||||
|
git clean -fd
|
||||||
|
|
||||||
# Prüfen ob sudo verfügbar ist
|
# Prüfen ob sudo verfügbar ist
|
||||||
if ! command -v sudo &> /dev/null; then
|
if ! command -v sudo >/dev/null 2>&1; then
|
||||||
echo "Error: sudo is required but not installed"
|
echo "Error: sudo is required but not installed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Backend updaten
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Updating Backend ==="
|
echo "=== Updating Backend ==="
|
||||||
./update-backend.sh
|
./update-backend.sh
|
||||||
|
|
||||||
# Frontend bauen und updaten
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Building and Updating Frontend ==="
|
echo "=== Building and Updating Frontend ==="
|
||||||
./update-frontend.sh
|
./update-frontend.sh
|
||||||
@@ -36,4 +48,3 @@ echo ""
|
|||||||
echo "To check logs:"
|
echo "To check logs:"
|
||||||
echo " Backend: sudo journalctl -u yourpart.service -f"
|
echo " Backend: sudo journalctl -u yourpart.service -f"
|
||||||
echo " Apache: sudo tail -f /var/log/apache2/yourpart.*.log"
|
echo " Apache: sudo tail -f /var/log/apache2/yourpart.*.log"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user