From 1632e415720a3865c4ea49d48472ca400d9b3821 Mon Sep 17 00:00:00 2001 From: mafyuh Date: Sun, 9 Jun 2024 04:24:27 +0000 Subject: [PATCH] Add .forgejo/workflows/CD.yml --- .forgejo/workflows/CD.yml | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .forgejo/workflows/CD.yml diff --git a/.forgejo/workflows/CD.yml b/.forgejo/workflows/CD.yml new file mode 100644 index 0000000..959a00a --- /dev/null +++ b/.forgejo/workflows/CD.yml @@ -0,0 +1,56 @@ +name: Continuous Deployment + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up SSH agent + uses: webfactory/ssh-agent@v0.5.3 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Detect modified folders + id: detect-changes + run: | + # List all modified files and filter unique folder names + folders=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | cut -d/ -f1 | sort | uniq) + echo "Modified folders: $folders" + echo "::set-output name=folders::$folders" + + - name: Deploy to Hosts + if: steps.detect-changes.outputs.folders != '' + run: | + for folder in ${{ steps.detect-changes.outputs.folders }} + do + case $folder in + arrs) + host="${{ secrets.ARRS_IP }}" + ;; + ag_main) + host="${{ secrets.AGMAIN_IP }}" + ;; + downloaders) + host="${{ secrets.DOWNLOADERS_IP }}" + ;; + # Add cases for other folders/hosts + *) + echo "Unknown folder: $folder" + continue + ;; + esac + + echo "Deploying to $host for folder $folder" + ssh -o StrictHostKeyChecking=no mafyuh@$host << EOF + cd /Auto-Homelab/$folder + git pull + docker-compose up -d +EOF + done