Update .forgejo/workflows/CD.yml

This commit is contained in:
Matt Reeves 2024-06-15 01:33:06 -04:00
parent a64aa0e258
commit c8f934fd45

View file

@ -24,91 +24,74 @@ jobs:
echo "Modified folders: $folders" echo "Modified folders: $folders"
echo "::set-output name=folders::$folders" echo "::set-output name=folders::$folders"
- name: Determine target host - name: Deploy to hosts
id: determine-host
run: | run: |
folder=$(echo "${{ steps.detect-changes.outputs.folders }}" | head -n 1) IFS=' ' read -r -a folder_array <<< "${{ steps.detect-changes.outputs.folders }}"
if [ -z "$folder" ]; then for folder in "${folder_array[@]}"; do
echo "No modified folders detected" case $folder in
exit 1 arrs)
fi target_host="arrs.lan"
case $folder in ;;
arrs) arm)
target_host="arrs.lan" target_host="arm.lan"
;; ;;
arm) downloaders)
target_host="arm.lan" target_host="downloaders.lan"
;; ;;
downloaders) AI)
target_host="downloaders.lan" target_host="ai.lan"
;; ;;
AI) authentik)
target_host="ai.lan" target_host="auth.lan"
;; ;;
authentik) cf)
target_host="auth.lan" target_host="cf.lan"
;; ;;
cf) jellyfin)
target_host="cf.lan" target_host="jf.lan"
;; ;;
jellyfin) kasm)
target_host="jf.lan" target_host="kasm.lan"
;; ;;
kasm) netboot)
target_host="kasm.lan" target_host="netboot.lan"
;; ;;
netboot) nexus)
target_host="netboot.lan" target_host="nexus.lan"
;; ;;
nexus) pages)
target_host="nexus.lan" target_host="pages.lan"
;; ;;
pages) portainer)
target_host="pages.lan" target_host="port.lan"
;; ;;
portainer) twingate)
target_host="port.lan" target_host="twingate.lan"
;; ;;
twingate) whisper)
target_host="twingate.lan" target_host="whisper.lan"
;; ;;
whisper) # Add cases for other folders/hosts
target_host="whisper.lan" *)
;; echo "Unknown folder: $folder"
# Add cases for other folders/hosts continue
*) ;;
echo "Unknown folder: $folder" esac
exit 1 echo "Triggering AWX Job with target host: $target_host and folder: $folder"
;; curl -X POST -k -H "Content-Type: application/json" \
esac -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" \
echo "::set-output name=target_host::$target_host" -d "{\"extra_vars\": {\"target_host\": \"$target_host\", \"folder\": \"$folder\"}}" \
echo "::set-output name=folder::$folder" "https://awx.mafyuh.xyz/api/v2/job_templates/13/launch/"
- name: Trigger AWX Job sleep 45 # Delay for 45 seconds before fetching logs
run: |
TARGET_HOST="${{ steps.determine-host.outputs.target_host }}"
FOLDER="${{ steps.determine-host.outputs.folder }}"
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/"
- name: Delay for 45 seconds 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')
run: sleep 45 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"
- name: Fetch AWX Job Logs echo "Range:"
run: | echo "Start: $(echo "$logs" | jq -r '.range.start')"
# Fetch the most recent job from AWX echo "End: $(echo "$logs" | jq -r '.range.end')"
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') echo "Absolute End: $(echo "$logs" | jq -r '.range.absolute_end')"
echo "Content:"
# Fetch the logs for the job echo "$(echo "$logs" | jq -r '.content')"
logs=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/jobs/$job_id/stdout/?format=json) done
# Display the logs
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')"