From 3415b56cd2070bed9680a24f9c14557bed690b8b Mon Sep 17 00:00:00 2001 From: Eric Boehs Date: Fri, 13 Sep 2024 11:02:37 -0500 Subject: [PATCH] debug --- .../deploy_missing_notifications.yml | 83 ++++++++++++------- 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/.github/workflows/deploy_missing_notifications.yml b/.github/workflows/deploy_missing_notifications.yml index 4b816504271..6dae59b9848 100644 --- a/.github/workflows/deploy_missing_notifications.yml +++ b/.github/workflows/deploy_missing_notifications.yml @@ -44,54 +44,77 @@ jobs: - name: Check if today is a valid day id: check-day run: | + set -x # Enable debug mode today=$(date +'%Y-%m-%d') current_time=$(date +'%H:%M') day_of_week=$(date +'%u') # Parse the values.yaml file - sync_windows=$(yq e '.projects[] | select(.name == "vets-api") | .sync_windows' ./vsp-infra-argocd/chart/values.yaml) + sync_windows=$(yq e '.projects[] | select(.name == "vets-api") | .sync_windows[]' ./vsp-infra-argocd/chart/values.yaml) + + # Debug: Print the extracted sync_windows + echo "Extracted sync_windows:" + echo "$sync_windows" + + # Check if sync_windows is empty + if [ -z "$sync_windows" ]; then + echo "Error: No sync windows found for vets-api project" + echo "run_check=false" >> $GITHUB_OUTPUT + exit 0 + fi # Check for deny windows first deny_active=false - while IFS= read -r deny_window; do - schedule=$(echo "$deny_window" | yq e '.schedule' -) - month=$(echo "$schedule" | awk '{print $4}') - day=$(echo "$schedule" | awk '{print $3}') - - if [[ "$(date +'%b' | tr '[:lower:]' '[:upper:]')" == "$month" && "$(date +'%d')" == "$day" ]]; then - echo "Deny window active today" - deny_active=true - break + while IFS= read -r window; do + kind=$(echo "$window" | yq e '.kind' -) + schedule=$(echo "$window" | yq e '.schedule' -) + if [ "$kind" = "deny" ]; then + month=$(echo "$schedule" | awk '{print $4}') + day=$(echo "$schedule" | awk '{print $3}') + + if [[ "$(date +'%b' | tr '[:lower:]' '[:upper:]')" == "$month" && "$(date +'%d')" == "$day" ]]; then + echo "Deny window active today" + deny_active=true + break + fi fi - done < <(echo "$sync_windows" | yq e '.[] | select(.kind == "deny")' -) + done <<< "$sync_windows" # If no deny window is active, check for allow window if [ "$deny_active" = false ]; then if [[ $day_of_week -le 5 ]]; then - allow_window=$(echo "$sync_windows" | yq e '.[] | select(.kind == "allow")' -) - allow_schedule=$(echo "$allow_window" | yq e '.schedule' -) - allow_time=$(echo "$allow_schedule" | awk '{print $2}') - allow_duration=$(echo "$allow_window" | yq e '.duration' -) - - # Convert allow_time to minutes since midnight - IFS=: read allow_hour allow_minute <<< "$allow_time" - allow_minutes=$((10#$allow_hour * 60 + 10#$allow_minute)) - - # Convert current_time to minutes since midnight - IFS=: read current_hour current_minute <<< "$current_time" - current_minutes=$((10#$current_hour * 60 + 10#$current_minute)) - - # Check if current time is within the allow window - if ((current_minutes >= allow_minutes && current_minutes < allow_minutes + allow_duration)); then - echo "Weekday within allowed time window" - echo "run_check=true" >> $GITHUB_OUTPUT - exit 0 - fi + while IFS= read -r window; do + kind=$(echo "$window" | yq e '.kind' -) + if [ "$kind" = "allow" ]; then + schedule=$(echo "$window" | yq e '.schedule' -) + duration=$(echo "$window" | yq e '.duration' -) + allow_time=$(echo "$schedule" | awk '{print $2}') + + # Convert allow_time to minutes since midnight + IFS=: read allow_hour allow_minute <<< "$allow_time" + allow_minutes=$((10#$allow_hour * 60 + 10#$allow_minute)) + + # Convert current_time to minutes since midnight + IFS=: read current_hour current_minute <<< "$current_time" + current_minutes=$((10#$current_hour * 60 + 10#$current_minute)) + + # Convert duration to minutes + duration_minutes=$(echo "$duration" | sed 's/m//') + + # Check if current time is within the allow window + if ((current_minutes >= allow_minutes && current_minutes < allow_minutes + duration_minutes)); then + echo "Weekday within allowed time window" + echo "run_check=true" >> $GITHUB_OUTPUT + exit 0 + fi + fi + done <<< "$sync_windows" fi fi echo "Not within allowed window or deny window active" echo "run_check=false" >> $GITHUB_OUTPUT + shell: /usr/bin/bash -e {0} - name: Check API status if: steps.check-day.outputs.run_check == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch'