116 lines
3.9 KiB
YAML
116 lines
3.9 KiB
YAML
name: Deploy to Hosts
|
|
on:
|
|
pull_request:
|
|
types: [closed]
|
|
|
|
jobs:
|
|
deploy:
|
|
if: github.event.pull_request.merged == true
|
|
runs-on: ubuntu-22.04
|
|
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 | grep '^docker/' | cut -d/ -f2 | sort | uniq)
|
|
echo "Modified folders: $folders"
|
|
echo "::set-output name=folders::$folders"
|
|
|
|
- name: Set condition for deployment
|
|
id: set-condition
|
|
run: |
|
|
if [ -z "${{ steps.detect-changes.outputs.folders }}" ]; then
|
|
echo "No relevant changes detected."
|
|
echo "::set-output name=continue::false"
|
|
else
|
|
echo "Relevant changes detected."
|
|
echo "::set-output name=continue::true"
|
|
fi
|
|
|
|
conditional-deploy:
|
|
if: needs.deploy.outputs.continue == 'true'
|
|
runs-on: ubuntu-22.04
|
|
needs: deploy
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Deploy to hosts
|
|
run: |
|
|
IFS=' ' read -r -a folder_array <<< "${{ needs.deploy.outputs.folders }}"
|
|
for folder in "${folder_array[@]}"; do
|
|
case $folder in
|
|
arrs)
|
|
target_host="arrs.lan"
|
|
;;
|
|
arm)
|
|
target_host="arm.lan"
|
|
;;
|
|
downloaders)
|
|
target_host="downloaders.lan"
|
|
;;
|
|
AI)
|
|
target_host="ai.lan"
|
|
;;
|
|
authentik)
|
|
target_host="auth.lan"
|
|
;;
|
|
cf)
|
|
target_host="cf.lan"
|
|
;;
|
|
jellyfin)
|
|
target_host="jf.lan"
|
|
;;
|
|
kasm)
|
|
target_host="kasm.lan"
|
|
;;
|
|
netboot)
|
|
target_host="netboot.lan"
|
|
;;
|
|
nexus)
|
|
target_host="nexus.lan"
|
|
;;
|
|
pages)
|
|
target_host="pages.lan"
|
|
;;
|
|
portainer)
|
|
target_host="port.lan"
|
|
;;
|
|
twingate)
|
|
target_host="twingate.lan"
|
|
;;
|
|
whisper)
|
|
target_host="whisper.lan"
|
|
;;
|
|
# Add cases for other folders/hosts
|
|
*)
|
|
echo "Unknown folder: $folder"
|
|
continue
|
|
;;
|
|
esac
|
|
echo "Triggering AWX Job with target host: $target_host and folder: $folder"
|
|
curl -X POST -k -H "Content-Type: application/json" \
|
|
-H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" \
|
|
-d "{\"extra_vars\": {\"target_host\": \"$target_host\", \"folder\": \"$folder\"}}" \
|
|
"https://awx.mafyuh.xyz/api/v2/job_templates/13/launch/"
|
|
|
|
sleep 45
|
|
|
|
job_id=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/job_templates/13/jobs/?order_by=-id | jq -r '.results[0].id')
|
|
logs=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/jobs/$job_id/stdout/?format=json)
|
|
echo "AWX Job Logs for folder: $folder"
|
|
echo "Range:"
|
|
echo "Start: $(echo "$logs" | jq -r '.range.start')"
|
|
echo "End: $(echo "$logs" | jq -r '.range.end')"
|
|
echo "Absolute End: $(echo "$logs" | jq -r '.range.absolute_end')"
|
|
echo "Content:"
|
|
echo "$(echo "$logs" | jq -r '.content')"
|
|
done
|