This repository has been archived on 2024-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
Auto-Homelab/.forgejo/workflows/CD.yml
mafyuh 02506b5745
All checks were successful
Lint on PR / Lint YAML files (pull_request) Successful in 10s
Update .forgejo/workflows/CD.yml
2024-06-09 04:29:45 +00:00

52 lines
1.5 KiB
YAML

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 "cd /Auto-Homelab/$folder && git pull && docker-compose up -d"
done