55 lines
1.6 KiB
YAML
55 lines
1.6 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 << 'EOF'
|
|
cd /Auto-Homelab/$folder
|
|
git pull
|
|
docker-compose up -d
|
|
EOF
|