-
Notifications
You must be signed in to change notification settings - Fork 1
452 lines (389 loc) · 14 KB
/
monitoring.yml
File metadata and controls
452 lines (389 loc) · 14 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
name: Monitoring & Performance
on:
schedule:
# Executa diariamente às 6h
- cron: '0 6 * * *'
push:
branches: [ main ]
workflow_dispatch:
jobs:
lighthouse-audit:
runs-on: ubuntu-latest
steps:
- name: Checkout código
uses: actions/checkout@v4
- name: Verificar se é projeto Node.js
id: check-node
run: |
if [ -f "package.json" ]; then
echo "has_package_json=true" >> $GITHUB_OUTPUT
else
echo "has_package_json=false" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.check-node.outputs.has_package_json == 'true'
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install dependencies
if: steps.check-node.outputs.has_package_json == 'true'
run: |
if [ -f "package-lock.json" ]; then
npm ci
else
npm install
fi
- name: Build aplicação
if: steps.check-node.outputs.has_package_json == 'true'
continue-on-error: true
run: |
if grep -q "\"build\"" package.json; then
npm run build
fi
- name: Lighthouse CI
if: steps.check-node.outputs.has_package_json == 'true'
uses: treosh/lighthouse-ci-action@v10
continue-on-error: true
with:
urls: |
http://localhost:3000
uploadArtifacts: true
temporaryPublicStorage: true
- name: Upload Lighthouse report
if: steps.check-node.outputs.has_package_json == 'true'
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: lighthouse-report
path: '.lighthouseci'
retention-days: 30
performance-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout código
uses: actions/checkout@v4
- name: Verificar se é projeto Node.js
id: check-node
run: |
if [ -f "package.json" ]; then
echo "has_package_json=true" >> $GITHUB_OUTPUT
else
echo "has_package_json=false" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.check-node.outputs.has_package_json == 'true'
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install k6
run: |
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6
- name: Run performance tests
continue-on-error: true
run: |
if [ -f "k6-test.js" ]; then
k6 run k6-test.js
else
echo "Nenhum teste k6 encontrado"
fi
health-check:
runs-on: ubuntu-latest
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
steps:
- name: Check website status
continue-on-error: true
run: |
# Adicione suas URLs aqui
URLS=(
"https://example.com"
"https://api.example.com/health"
)
for url in "${URLS[@]}"; do
echo "Checking $url..."
response=$(curl -s -o /dev/null -w "%{http_code}" "$url" || echo "000")
if [ "$response" -eq 200 ]; then
echo "✅ $url is up (HTTP $response)"
else
echo "❌ $url is down or unhealthy (HTTP $response)"
fi
done
uptime-monitor:
runs-on: ubuntu-latest
if: github.event_name == 'schedule'
steps:
- name: Uptime Robot Monitor
continue-on-error: true
env:
UPTIME_ROBOT_API_KEY: ${{ secrets.UPTIME_ROBOT_API_KEY }}
run: |
if [ -z "$UPTIME_ROBOT_API_KEY" ]; then
echo "UPTIME_ROBOT_API_KEY não configurado, pulando verificação."
exit 0
fi
echo "Verificando status do Uptime Robot..."
curl -X POST https://api.uptimerobot.com/v2/getMonitors \
-d "api_key=$UPTIME_ROBOT_API_KEY" \
-d "format=json"
ssl-check:
runs-on: ubuntu-latest
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
steps:
- name: Check SSL certificates
continue-on-error: true
run: |
# Adicione seus domínios aqui
DOMAINS=(
"example.com"
"api.example.com"
)
for domain in "${DOMAINS[@]}"; do
echo "Checking SSL for $domain..."
expiry_date=$(echo | openssl s_client -servername "$domain" -connect "$domain:443" 2>/dev/null | openssl x509 -noout -enddate 2>/dev/null | cut -d= -f2)
if [ -n "$expiry_date" ]; then
expiry_epoch=$(date -d "$expiry_date" +%s)
current_epoch=$(date +%s)
days_left=$(( ($expiry_epoch - $current_epoch) / 86400 ))
echo "SSL certificate for $domain expires in $days_left days"
if [ $days_left -lt 30 ]; then
echo "⚠️ SSL certificate for $domain expires soon!"
else
echo "✅ SSL certificate for $domain is valid"
fi
else
echo "❌ Could not check SSL for $domain"
fi
done
docker-image-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout código
uses: actions/checkout@v4
- name: Verificar Dockerfile
id: check-dockerfile
run: |
if [ -f "Dockerfile" ]; then
echo "has_dockerfile=true" >> $GITHUB_OUTPUT
else
echo "has_dockerfile=false" >> $GITHUB_OUTPUT
fi
- name: Set up Docker Buildx
if: steps.check-dockerfile.outputs.has_dockerfile == 'true'
uses: docker/setup-buildx-action@v3
- name: Build Docker image
if: steps.check-dockerfile.outputs.has_dockerfile == 'true'
run: docker build -t local-test:latest .
- name: Scan image with Trivy
if: steps.check-dockerfile.outputs.has_dockerfile == 'true'
uses: aquasecurity/trivy-action@master
with:
image-ref: 'local-test:latest'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy results
if: steps.check-dockerfile.outputs.has_dockerfile == 'true'
uses: github/codeql-action/upload-sarif@v3
continue-on-error: true
with:
sarif_file: 'trivy-results.sarif'
- name: Scan image with Snyk
if: steps.check-dockerfile.outputs.has_dockerfile == 'true'
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run: |
if [ -z "$SNYK_TOKEN" ]; then
echo "SNYK_TOKEN não configurado, pulando scan com Snyk"
exit 0
fi
echo "Scan com Snyk requer configuração adicional - consulte a documentação do Snyk"
code-coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout código
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Verificar se é projeto Node.js
id: check-node
run: |
if [ -f "package.json" ]; then
echo "has_package_json=true" >> $GITHUB_OUTPUT
else
echo "has_package_json=false" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.check-node.outputs.has_package_json == 'true'
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install dependencies
if: steps.check-node.outputs.has_package_json == 'true'
run: |
if [ -f "package-lock.json" ]; then
npm ci
else
npm install
fi
- name: Run tests with coverage
if: steps.check-node.outputs.has_package_json == 'true'
continue-on-error: true
run: |
if grep -q "\"test:coverage\"" package.json; then
npm run test:coverage
elif grep -q "\"test\"" package.json; then
npm test -- --coverage || npm test
fi
- name: Upload coverage to Codecov
if: steps.check-node.outputs.has_package_json == 'true'
uses: codecov/codecov-action@v3
continue-on-error: true
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
flags: unittests
name: codecov-umbrella
- name: Upload coverage reports
if: steps.check-node.outputs.has_package_json == 'true'
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: coverage-report
path: coverage/
retention-days: 30
performance-budget:
runs-on: ubuntu-latest
steps:
- name: Checkout código
uses: actions/checkout@v4
- name: Verificar se é projeto Node.js
id: check-node
run: |
if [ -f "package.json" ]; then
echo "has_package_json=true" >> $GITHUB_OUTPUT
else
echo "has_package_json=false" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.check-node.outputs.has_package_json == 'true'
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install dependencies
if: steps.check-node.outputs.has_package_json == 'true'
run: |
if [ -f "package-lock.json" ]; then
npm ci
else
npm install
fi
- name: Build
if: steps.check-node.outputs.has_package_json == 'true'
run: |
if grep -q "\"build\"" package.json; then
npm run build
fi
- name: Check bundle size
if: steps.check-node.outputs.has_package_json == 'true'
uses: andresz1/size-limit-action@v1
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
skip_step: install
accessibility-check:
runs-on: ubuntu-latest
steps:
- name: Checkout código
uses: actions/checkout@v4
- name: Verificar se é projeto Node.js
id: check-node
run: |
if [ -f "package.json" ]; then
echo "has_package_json=true" >> $GITHUB_OUTPUT
else
echo "has_package_json=false" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.check-node.outputs.has_package_json == 'true'
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install dependencies
if: steps.check-node.outputs.has_package_json == 'true'
run: |
if [ -f "package-lock.json" ]; then
npm ci
else
npm install
fi
- name: Build
if: steps.check-node.outputs.has_package_json == 'true'
continue-on-error: true
run: |
if grep -q "\"build\"" package.json; then
npm run build
fi
- name: Run Pa11y accessibility tests
if: steps.check-node.outputs.has_package_json == 'true'
continue-on-error: true
run: |
npm install -g pa11y-ci
if [ -f ".pa11yci.json" ]; then
pa11y-ci
else
echo "Nenhum arquivo .pa11yci.json encontrado"
fi
seo-check:
runs-on: ubuntu-latest
steps:
- name: Checkout código
uses: actions/checkout@v4
- name: Verificar se é projeto Node.js
id: check-node
run: |
if [ -f "package.json" ]; then
echo "has_package_json=true" >> $GITHUB_OUTPUT
else
echo "has_package_json=false" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.check-node.outputs.has_package_json == 'true'
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Check meta tags and SEO
continue-on-error: true
run: |
if [ -d "public" ] || [ -d "dist" ]; then
echo "Verificando meta tags..."
find public dist -name "*.html" 2>/dev/null | while read file; do
echo "Checking $file"
grep -i "meta.*description" "$file" || echo "⚠️ Meta description missing in $file"
grep -i "meta.*keywords" "$file" || echo "⚠️ Meta keywords missing in $file"
grep -i "<title>" "$file" || echo "⚠️ Title tag missing in $file"
done
fi
report-summary:
runs-on: ubuntu-latest
needs: [lighthouse-audit, performance-tests, health-check, ssl-check, docker-image-scan, code-coverage, accessibility-check]
if: always()
steps:
- name: Generate summary
run: |
echo "# 📊 Relatório de Monitoramento" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Status dos Jobs" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- Lighthouse Audit: ${{ needs.lighthouse-audit.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Performance Tests: ${{ needs.performance-tests.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Health Check: ${{ needs.health-check.result }}" >> $GITHUB_STEP_SUMMARY
echo "- SSL Check: ${{ needs.ssl-check.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Docker Scan: ${{ needs.docker-image-scan.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Code Coverage: ${{ needs.code-coverage.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Accessibility: ${{ needs.accessibility-check.result }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Executado em:** $(date -u +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY