Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
ericboehs committed Sep 13, 2024
1 parent 5f6c641 commit 3415b56
Showing 1 changed file with 53 additions and 30 deletions.
83 changes: 53 additions & 30 deletions .github/workflows/deploy_missing_notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 3415b56

Please sign in to comment.