-
Notifications
You must be signed in to change notification settings - Fork 19
106 lines (90 loc) · 3.41 KB
/
Copy pathbreach-monitor.yml
File metadata and controls
106 lines (90 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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