iac/.forgejo/workflows/CD.yml

104 lines
3.3 KiB
YAML
Raw Normal View History

2024-07-12 23:57:29 -04:00
name: Deploy to Hosts
on:
pull_request:
types: [closed]
jobs:
deploy:
if: github.event.pull_request.merged == true
2024-07-30 20:37:13 -04:00
runs-on: docker
2024-07-12 23:57:29 -04:00
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Fetch all history for git diff
run: git fetch --depth=2
2024-07-30 22:13:47 -04:00
- name: Install jq
run: |
apt-get update && apt-get install -y jq
2024-07-12 23:57:29 -04:00
- name: Detect modified folders
id: detect-changes
run: |
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
git fetch --unshallow
fi
2024-07-23 21:47:12 -04:00
folders=$(git diff --name-only HEAD~1 HEAD | grep '^docker/' | cut -d/ -f2 | sort | uniq)
2024-07-12 23:57:29 -04:00
echo "Modified folders: $folders"
2024-07-30 20:17:39 -04:00
echo "::set-output name=folders::$folders"
2024-07-12 23:57:29 -04:00
- name: Deploy to hosts
run: |
2024-07-30 20:17:39 -04:00
IFS=' ' read -r -a folder_array <<< "${{ steps.detect-changes.outputs.folders }}"
2024-07-12 23:57:29 -04:00
for folder in "${folder_array[@]}"; do
case $folder in
2024-09-16 23:30:26 -04:00
actual)
target_host="ubu.lan"
;;
2024-07-12 23:57:29 -04:00
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"
;;
2024-09-16 23:30:26 -04:00
nexterm)
target_host="ubu.lan"
2024-07-12 23:57:29 -04:00
;;
2024-09-16 23:30:26 -04:00
npm)
target_host="npm.lan"
;;
paperless)
target_host="ubu.lan"
2024-07-12 23:57:29 -04:00
;;
portainer)
target_host="port.lan"
;;
2024-10-12 13:55:37 -04:00
runner)
target_host="runner.lan"
;;
2024-07-12 23:57:29 -04:00
twingate)
target_host="twingate.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/"
2024-07-30 20:17:39 -04:00
sleep 45 # Delay for 45 seconds before fetching logs
2024-07-30 22:13:47 -04:00
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)
2024-07-12 23:57:29 -04:00
echo "AWX Job Logs for folder: $folder"
echo "Content:"
2024-07-30 22:13:47 -04:00
echo "$(echo "$logs" | jq -r '.content')"
2024-07-30 20:37:04 -04:00
done