Compare test #4650
This file contains 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: 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 |