Breach Notifications Monitor #337
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Breach Notifications Monitor | |
| on: | |
| schedule: | |
| # Run daily at 7:00 AM UTC (adjust timezone as needed) | |
| - cron: '0 7 * * *' | |
| workflow_dispatch: # Allow manual triggering | |
| jobs: | |
| monitor-breaches: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| # Fetch full history to ensure we have the cyberattacks.json file | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Cache pip dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r breach_monitor_requirements.txt | |
| - name: Run Breach notifications monitor (All States) | |
| env: | |
| GROQ_API: ${{ secrets.GROQ_API }} | |
| TG_TK: ${{ secrets.TG_TK }} | |
| TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }} | |
| run: | | |
| python breach_monitor.py | |
| - name: Upload new notifications artifact | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: new-notifications-${{ github.run_number }} | |
| path: | | |
| new_notification_*.json | |
| *.log | |
| retention-days: 3 | |
| if-no-files-found: ignore | |
| - name: Commit and push new cyberattacks data | |
| if: hashFiles('new_notification_*.json') != '' | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| # Check if any state notification files exist and have content | |
| notification_files=$(ls new_notification_*.json 2>/dev/null || true) | |
| if [ -n "$notification_files" ]; then | |
| echo "New notifications found, updating repository" | |
| echo "Found notification files: $notification_files" | |
| # Add any new notification files that might have been created | |
| git add new_notification_*.json | |
| # Check if there are changes to commit | |
| if ! git diff --staged --quiet; then | |
| # Count total notifications across all states | |
| total_notifications=0 | |
| states_with_notifications="" | |
| for file in $notification_files; do | |
| if [ -s "$file" ]; then | |
| count=$(jq length "$file" 2>/dev/null || echo "0") | |
| total_notifications=$((total_notifications + count)) | |
| state=$(echo "$file" | sed 's/new_notification_\(.*\)\.json/\1/') | |
| if [ -n "$states_with_notifications" ]; then | |
| states_with_notifications="$states_with_notifications, $state" | |
| else | |
| states_with_notifications="$state" | |
| fi | |
| fi | |
| done | |
| git commit -m "🚨 New breach notifications found ($total_notifications from $states_with_notifications) - $(date '+%Y-%m-%d %H:%M:%S')" | |
| git push | |
| else | |
| echo "No changes to commit" | |
| fi | |
| else | |
| echo "No new notifications to commit" | |
| fi | |
| - name: Check workflow status | |
| if: failure() | |
| run: | | |
| echo "❌ Breach monitor workflow failed" | |
| echo "Check the logs for details" | |
| exit 1 |