diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..a2c9f77 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -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 \ No newline at end of file diff --git a/update.sh b/update.sh index d6e29ef..7274ee2 100755 --- a/update.sh +++ b/update.sh @@ -1,10 +1,8 @@ -#!/bin/bash - -git fetch -git pull +#!/usr/bin/env bash +set -euo pipefail 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 "" # Prüfen ob wir im richtigen Verzeichnis sind @@ -13,18 +11,32 @@ if [ ! -f "package.json" ]; then exit 1 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 -if ! command -v sudo &> /dev/null; then +if ! command -v sudo >/dev/null 2>&1; then echo "Error: sudo is required but not installed" exit 1 fi -# Backend updaten echo "" echo "=== Updating Backend ===" ./update-backend.sh -# Frontend bauen und updaten echo "" echo "=== Building and Updating Frontend ===" ./update-frontend.sh @@ -35,5 +47,4 @@ echo "Your application has been updated." echo "" echo "To check logs:" 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" \ No newline at end of file