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:27:58 -04:00
|
|
|
runs-on: docker
|
2024-06-09 15:18:49 -04:00
|
|
|
steps:
|
|
|
|
- name: Checkout repository
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
2024-06-09 17:43:43 -04:00
|
|
|
- name: Fetch all history for git diff
|
|
|
|
run: git fetch --depth=2
|
|
|
|
|
2024-06-09 15:18:49 -04:00
|
|
|
- name: Detect modified folders
|
|
|
|
id: detect-changes
|
|
|
|
run: |
|
2024-06-09 17:43:43 -04:00
|
|
|
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
|
|
|
|
git fetch --unshallow
|
2024-06-09 17:30:36 -04:00
|
|
|
fi
|
2024-06-09 17:43:43 -04:00
|
|
|
folders=$(git diff --name-only HEAD~1 HEAD | cut -d/ -f1 | sort | uniq)
|
2024-06-09 15:18:49 -04:00
|
|
|
echo "Modified folders: $folders"
|
|
|
|
echo "::set-output name=folders::$folders"
|
|
|
|
|
|
|
|
- name: Determine target host
|
|
|
|
id: determine-host
|
|
|
|
run: |
|
2024-06-09 17:43:43 -04:00
|
|
|
folder=$(echo "${{ steps.detect-changes.outputs.folders }}" | head -n 1)
|
|
|
|
if [ -z "$folder" ]; then
|
|
|
|
echo "No modified folders detected"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-06-09 15:18:49 -04:00
|
|
|
case $folder in
|
|
|
|
arrs)
|
2024-06-09 17:43:43 -04:00
|
|
|
target_host=${{ secrets.ARRS_IP }}
|
2024-06-09 15:18:49 -04:00
|
|
|
;;
|
|
|
|
ag_main)
|
2024-06-09 17:43:43 -04:00
|
|
|
target_host=${{ secrets.AGMAIN_IP }}
|
2024-06-09 15:18:49 -04:00
|
|
|
;;
|
|
|
|
downloaders)
|
2024-06-09 17:43:43 -04:00
|
|
|
target_host=${{ secrets.DOWNLOADERS_IP }}
|
2024-06-09 15:18:49 -04:00
|
|
|
;;
|
2024-06-09 15:25:48 -04:00
|
|
|
# Add cases for other folders/hosts
|
|
|
|
*)
|
|
|
|
echo "Unknown folder: $folder"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2024-06-09 17:43:43 -04:00
|
|
|
echo "::set-output name=target_host::$target_host"
|
2024-06-09 15:25:48 -04:00
|
|
|
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 }}" \
|
2024-06-09 17:43:43 -04:00
|
|
|
-d "{\"extra_vars\": {\"target_host\": \"${{ steps.determine-host.outputs.target_host }}\", \"folder\": \"${{ steps.determine-host.outputs.folder }}\"}}" \
|
2024-06-09 17:45:47 -04:00
|
|
|
"https://awx.mafyuh.xyz/api/v2/job_templates/13/github/"
|