60 lines
1.9 KiB
YAML
60 lines
1.9 KiB
YAML
name: Deploy to Hosts
|
|
on:
|
|
pull_request:
|
|
types: [closed]
|
|
|
|
jobs:
|
|
deploy:
|
|
if: github.event.pull_request.merged == true
|
|
runs-on: docker
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Fetch all history for git diff
|
|
run: git fetch --depth=2
|
|
|
|
- name: Detect modified folders
|
|
id: detect-changes
|
|
run: |
|
|
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
|
|
git fetch --unshallow
|
|
fi
|
|
folders=$(git diff --name-only HEAD~1 HEAD | cut -d/ -f1 | sort | uniq)
|
|
echo "Modified folders: $folders"
|
|
echo "::set-output name=folders::$folders"
|
|
|
|
- name: Determine target host
|
|
id: determine-host
|
|
run: |
|
|
folder=$(echo "${{ steps.detect-changes.outputs.folders }}" | head -n 1)
|
|
if [ -z "$folder" ]; then
|
|
echo "No modified folders detected"
|
|
exit 1
|
|
fi
|
|
case $folder in
|
|
arrs)
|
|
target_host=${{ secrets.ARRS_IP }}
|
|
;;
|
|
ag_main)
|
|
target_host=${{ secrets.AGMAIN_IP }}
|
|
;;
|
|
downloaders)
|
|
target_host=${{ secrets.DOWNLOADERS_IP }}
|
|
;;
|
|
# Add cases for other folders/hosts
|
|
*)
|
|
echo "Unknown folder: $folder"
|
|
exit 1
|
|
;;
|
|
esac
|
|
echo "::set-output name=target_host::$target_host"
|
|
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 }}\"}}" \
|
|
"http://awx.example.com/api/v2/job_templates/YOUR_JOB_TEMPLATE_ID/launch/"
|