name: Build-und-Deploy

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: 📥 Repository auschecken
        uses: actions/checkout@v3

      - name: 🧼 IP-Adresse von Gitea zu /etc/hosts hinzufügen
        run: echo "172.26.0.2 gitea" >> /etc/hosts

      - name: 🛠 Baue das Projekt (ohne Tests)
        run: ./gradlew clean build -x test

      - name: 📦 JAR ins Shared Volume kopieren und archivieren
        run: |
          mkdir -p /shared_jar_data /shared_jar_data/archive
          
          # Zeitstempel im Format YYYYMMDD-HHMMSS
          timestamp=$(date +"%Y%m%d-%H%M%S")
          
          # JAR-Datei kopieren (aktuelle Version)
          cp build/libs/MyTimeTracker-0.0.1-SNAPSHOT.jar /shared_jar_data/MyTimeTracker-0.0.1-SNAPSHOT.jar
          
          # JAR-Datei archivieren
          cp build/libs/MyTimeTracker-0.0.1-SNAPSHOT.jar /shared_jar_data/archive/MyTimeTracker-$timestamp.jar

      - name: 🚦 Neustart der Anwendung triggern
        run: |
          mkdir -p /shared_trigger_dir
          touch /shared_trigger_dir/restart-requested