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

55 lines
1.8 KiB
YAML
Raw Normal View History

2024-06-09 15:18:49 -04:00
name: Deploy to Hosts
on:
pull_request:
types: [closed]
jobs:
deploy:
if: github.event.pull_request.merged == true
2024-06-09 15:25:48 -04:00
runs-on: ubuntu-latest
2024-06-09 15:18:49 -04:00
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Detect modified folders
id: detect-changes
run: |
folders=$(git diff-tree --no-commit-id --name-only -r "${{ github.event.pull_request.merge_commit_sha }}" | cut -d/ -f1 | sort | uniq)
echo "Modified folders: $folders"
echo "::set-output name=folders::$folders"
- name: Determine target host
id: determine-host
run: |
2024-06-09 15:25:48 -04:00
folder=${{ steps.detect-changes.outputs.folders }}
2024-06-09 15:18:49 -04:00
case $folder in
arrs)
echo "::set-output name=target_host::${{ secrets.ARRS_IP }}"
;;
ag_main)
echo "::set-output name=target_host::${{ secrets.AGMAIN_IP }}"
;;
downloaders)
echo "::set-output name=target_host::${{ secrets.DOWNLOADERS_IP }}"
;;
2024-06-09 15:25:48 -04:00
# Add cases for other folders/hosts
*)
echo "Unknown folder: $folder"
exit 1
;;
esac
echo "::set-output name=folder::$folder"
- name: Trigger AWX Job
run: |
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" \
-d '{
"extra_vars": {
"target_host": "${{ steps.determine-host.outputs.target_host }}",
"folder": "${{ steps.determine-host.outputs.folder }}"
}
}' \
"https://awx.mafyuh.xyz/api/v2/job_templates/13/github/"