-
Notifications
You must be signed in to change notification settings - Fork 1
95 lines (83 loc) · 2.83 KB
/
mimir-chain-compare.yml
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
name: Compare test
on:
push:
branches:
- main
schedule:
- cron: "*/10 * * * *"
workflow_dispatch:
permissions:
contents: write
concurrency:
group: "failure-count"
cancel-in-progress: false
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Fetch Failure Count from Repository
run: |
if [ ! -f failure_count.json ]; then
echo '{"failure_count": 0}' > failure_count.json
fi
echo "Current failure count:"
cat failure_count.json
- name: Run Tests
run: |
dotnet restore mimir-uptime.sln
dotnet test mimir-uptime.sln
- name: Update Failure Count on Failure
if: failure()
run: |
COUNT=$(jq '.failure_count' failure_count.json)
NEW_COUNT=$((COUNT + 1))
jq ".failure_count = $NEW_COUNT" failure_count.json > tmp.json && mv tmp.json failure_count.json
echo "Updated failure count to $NEW_COUNT"
- name: Trigger PagerDuty Alert on 3 Consecutive Failures
if: failure()
env:
PAGERDUTY_INTEGRATION_KEY: ${{ secrets.PAGERDUTY_INTEGRATION_KEY }}
run: |
COUNT=$(jq '.failure_count' failure_count.json)
if [ "$COUNT" -ge 3 ]; then
curl --request POST \
--url 'https://events.pagerduty.com/v2/enqueue' \
--header 'Content-Type: application/json' \
--data '{
"payload": {
"summary": "GitHub Actions Workflow Failed 3 Times Consecutively",
"severity": "critical",
"source": "GitHub Actions Workflow"
},
"routing_key": "'"$PAGERDUTY_INTEGRATION_KEY"'",
"event_action": "trigger"
}'
echo "PagerDuty alert triggered due to 3 consecutive failures."
else
echo "Failure count is $COUNT, no PagerDuty alert triggered."
fi
- name: Reset Failure Count on Success
if: success()
run: |
jq ".failure_count = 0" failure_count.json > tmp.json && mv tmp.json failure_count.json
echo "Failure count reset to 0"
- name: Commit Failure Count Changes If Needed
if: always()
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
if ! git diff --quiet failure_count.json; then
git add failure_count.json
git commit -m "Update failure count [skip ci]"
git push
echo "Changes committed."
else
echo "No changes to commit."
fi