Add .forgejo/workflows/CD.yml

This commit is contained in:
Matt Reeves 2024-06-09 04:24:27 +00:00
parent 9973d67927
commit 1632e41572

56
.forgejo/workflows/CD.yml Normal file
View file

@ -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