Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 2 additions & 61 deletions shared-overwrite/.github/workflows/mt-check-data-outdated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,66 +94,7 @@ jobs:
DIFF_SEC=$((NOW_TIMESTAMP_SEC - DEPLOYED_LAST_DEPARTURE_SEC))
DIFF_DAYS=$((DIFF_SEC / 86400))
echo ">> Deployed data has expired! Last departure was ${DIFF_DAYS} days ago."
echo ">> Data is OUTDATED. Sync recommended. Looking for available archives..."

# Check archive directory for available data
ARCHIVE_DIR="agency-parser/archive"
echo "> Archive dir: '${ARCHIVE_DIR}'"

if [[ ! -d "${ARCHIVE_DIR}" ]]; then
echo ">> No archive directory found. Cannot check for newer data."
echo ">> Data is up-to-date (based on deployed data only)."
exit 0 # No archive, so we can't determine if newer data available
fi

# Find archives (requires bash 4+ for mapfile, available on ubuntu-latest)
mapfile -t ARCHIVES < <(find "${ARCHIVE_DIR}" -name "*.zip" -type f 2>/dev/null | sort)
echo "> Archives found: ${#ARCHIVES[@]}"

if [[ "${#ARCHIVES[@]}" -eq 0 ]]; then
echo ">> No archives available. Data cannot be updated."
echo ">> Data is up-to-date (based on deployed data only)."
exit 0
fi

# Check if any archive has data that extends beyond the deployed last departure
ARCHIVE_HAS_NEWER_DATA=false

for ARCHIVE in "${ARCHIVES[@]}"; do
ARCHIVE_BASENAME=$(basename "${ARCHIVE}")
ARCHIVE_BASENAME_NO_EXT="${ARCHIVE_BASENAME%.*}"

# Validate archive date format
if ! [[ "${ARCHIVE_BASENAME_NO_EXT}" =~ ^[0-9]{8}-[0-9]{8}$ ]]; then
echo "> Archive: ${ARCHIVE_BASENAME}"
echo " - WARNING: Archive filename doesn't match expected format (YYYYMMDD-YYYYMMDD.zip)"
continue
fi

ARCHIVE_START_DATE=${ARCHIVE_BASENAME_NO_EXT:0:8}
ARCHIVE_END_DATE=${ARCHIVE_BASENAME_NO_EXT:9:8}
echo "> Archive: ${ARCHIVE_BASENAME} (${ARCHIVE_START_DATE} to ${ARCHIVE_END_DATE})"

# Convert archive end date (YYYYMMDD) to timestamp at end of day (GNU date, available on ubuntu-latest)
ARCHIVE_END_TIMESTAMP=$(date -d "${ARCHIVE_END_DATE} 23:59:59" +%s 2>/dev/null)

if [[ -n "${ARCHIVE_END_TIMESTAMP}" ]]; then
echo " - Archive end timestamp: ${ARCHIVE_END_TIMESTAMP}"
# If archive has data beyond what's currently deployed, we need to sync
if [[ "${ARCHIVE_END_TIMESTAMP}" -gt "${DEPLOYED_LAST_DEPARTURE_SEC}" ]]; then
echo " - Archive has newer data than deployed!"
ARCHIVE_HAS_NEWER_DATA=true
break # Found newer data, no need to check other archives
fi
fi
done

# Determine if data is outdated based on archive availability
if [[ "${ARCHIVE_HAS_NEWER_DATA}" == true ]]; then
echo ">> Archive contains newer data. Data is OUTDATED. Triggering mt-download-data.yml workflow..."
gh workflow run mt-download-data.yml
else
echo ">> Data is up-to-date."
fi
echo ">> Data is OUTDATED. Triggering mt-download-data.yml workflow..."
gh workflow run mt-download-data.yml
Comment thread
mmathieum marked this conversation as resolved.
env:
GH_TOKEN: ${{ secrets.MT_PAT }}