|
| 1 | +name: Deploy to Hosts |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [closed] |
| 5 | + |
| 6 | +jobs: |
| 7 | + deploy: |
| 8 | + if: github.event.pull_request.merged == true |
| 9 | + runs-on: ubuntu-22.04 |
| 10 | + steps: |
| 11 | + - name: Checkout repository |
| 12 | + uses: actions/checkout@v4 |
| 13 | + |
| 14 | + - name: Fetch all history for git diff |
| 15 | + run: git fetch --depth=2 |
| 16 | + |
| 17 | + - name: Detect modified folders |
| 18 | + id: detect-changes |
| 19 | + run: | |
| 20 | + if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then |
| 21 | + git fetch --unshallow |
| 22 | + fi |
| 23 | + folders=$(git diff --name-only HEAD~1 HEAD | cut -d/ -f1 | sort | uniq) |
| 24 | + echo "Modified folders: $folders" |
| 25 | + echo "::set-output name=folders::$folders" |
| 26 | +
|
| 27 | + - name: Deploy to hosts |
| 28 | + run: | |
| 29 | + IFS=' ' read -r -a folder_array <<< "${{ steps.detect-changes.outputs.folders }}" |
| 30 | + for folder in "${folder_array[@]}"; do |
| 31 | + case $folder in |
| 32 | + arrs) |
| 33 | + target_host="arrs.lan" |
| 34 | + ;; |
| 35 | + arm) |
| 36 | + target_host="arm.lan" |
| 37 | + ;; |
| 38 | + downloaders) |
| 39 | + target_host="downloaders.lan" |
| 40 | + ;; |
| 41 | + AI) |
| 42 | + target_host="ai.lan" |
| 43 | + ;; |
| 44 | + authentik) |
| 45 | + target_host="auth.lan" |
| 46 | + ;; |
| 47 | + cf) |
| 48 | + target_host="cf.lan" |
| 49 | + ;; |
| 50 | + jellyfin) |
| 51 | + target_host="jf.lan" |
| 52 | + ;; |
| 53 | + kasm) |
| 54 | + target_host="kasm.lan" |
| 55 | + ;; |
| 56 | + netboot) |
| 57 | + target_host="netboot.lan" |
| 58 | + ;; |
| 59 | + nexus) |
| 60 | + target_host="nexus.lan" |
| 61 | + ;; |
| 62 | + pages) |
| 63 | + target_host="pages.lan" |
| 64 | + ;; |
| 65 | + portainer) |
| 66 | + target_host="port.lan" |
| 67 | + ;; |
| 68 | + twingate) |
| 69 | + target_host="twingate.lan" |
| 70 | + ;; |
| 71 | + whisper) |
| 72 | + target_host="whisper.lan" |
| 73 | + ;; |
| 74 | + # Add cases for other folders/hosts |
| 75 | + *) |
| 76 | + echo "Unknown folder: $folder" |
| 77 | + continue |
| 78 | + ;; |
| 79 | + esac |
| 80 | + echo "Triggering AWX Job with target host: $target_host and folder: $folder" |
| 81 | + curl -X POST -k -H "Content-Type: application/json" \ |
| 82 | + -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" \ |
| 83 | + -d "{\"extra_vars\": {\"target_host\": \"$target_host\", \"folder\": \"$folder\"}}" \ |
| 84 | + "https://awx.mafyuh.xyz/api/v2/job_templates/13/launch/" |
| 85 | +
|
| 86 | + sleep 45 # Delay for 45 seconds before fetching logs |
| 87 | +
|
| 88 | + 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') |
| 89 | + logs=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/jobs/$job_id/stdout/?format=json) |
| 90 | + echo "AWX Job Logs for folder: $folder" |
| 91 | + echo "Range:" |
| 92 | + echo "Start: $(echo "$logs" | jq -r '.range.start')" |
| 93 | + echo "End: $(echo "$logs" | jq -r '.range.end')" |
| 94 | + echo "Absolute End: $(echo "$logs" | jq -r '.range.absolute_end')" |
| 95 | + echo "Content:" |
| 96 | + echo "$(echo "$logs" | jq -r '.content')" |
| 97 | + done |
0 commit comments