From 80fcbe3fca03e8449f145178367cf2ab9d9874fd Mon Sep 17 00:00:00 2001 From: Lars Hampe Date: Mon, 27 Oct 2025 23:44:13 +0100 Subject: [PATCH] ci: clone/pull repo --- .gitea/workflows/deploy.yml | 42 +++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 378821f..afad3d1 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -51,6 +51,10 @@ jobs: echo "Action: ${{ inputs.action }}" echo "Detached: ${{ inputs.detach }}" + # Git Repo URL (aus Gitea) + REPO_URL="https://git.hashdot.co/${{ github.repository }}.git" + echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV + # Server-Konfiguration setzen case "${{ inputs.server }}" in devops) @@ -103,8 +107,23 @@ jobs: run: | echo "=== Deploying to ${{ inputs.server }} ===" - # Git pull auf dem Server - ssh $USER@$HOST "git pull" + # Check ob Repo existiert, sonst clonen + ssh $USER@$HOST " + export COMPOSE_PATH='$COMPOSE_PATH' + export REPO_URL='$REPO_URL' + + if [ -d \"\$COMPOSE_PATH/.git\" ]; then + echo 'Repository already exists, pulling latest changes...' + cd \$COMPOSE_PATH && git pull + else + echo 'Repository not found, cloning...' + PARENT_DIR=\$(dirname \$COMPOSE_PATH) + mkdir -p \$PARENT_DIR + cd \$PARENT_DIR + git clone \$REPO_URL \$(basename \$COMPOSE_PATH) + echo 'Repository cloned successfully' + fi + " # Docker Compose Aktion ausführen case "${{ inputs.action }}" in @@ -143,8 +162,23 @@ jobs: echo "" echo ">>> Deploying to $server..." - # Git pull - ssh $user_host "cd $compose_path && git pull" || { echo "Failed to deploy to $server"; continue; } + # Check ob Repo existiert, sonst clonen + ssh $user_host " + export COMPOSE_PATH='$compose_path' + export REPO_URL='$REPO_URL' + + if [ -d \"\$COMPOSE_PATH/.git\" ]; then + echo 'Repository already exists, pulling latest changes...' + cd \$COMPOSE_PATH && git pull + else + echo 'Repository not found, cloning...' + PARENT_DIR=\$(dirname \$COMPOSE_PATH) + mkdir -p \$PARENT_DIR + cd \$PARENT_DIR + git clone \$REPO_URL \$(basename \$COMPOSE_PATH) + echo 'Repository cloned successfully' + fi + " || { echo "Failed to setup git for $server"; continue; } # Docker Compose Aktion case "${{ inputs.action }}" in