fix: improve weekly metrics workflow with 14-day window and debug output

- Extend search window from 7 to 14 days for more reliable metrics
- Add debug output to troubleshoot empty metrics
- Add fallback values when no metrics files found
- Show date range in Discord message for clarity
This commit is contained in:
Ralph Khreish
2025-09-22 11:41:37 +02:00
parent c395e93696
commit 83d5b22ca9

View File

@@ -19,13 +19,14 @@ jobs:
steps:
- name: Get dates for last week
run: |
# Last 7 days
first_day=$(date -d "7 days ago" +%Y-%m-%d)
# Last 14 days for more reliable metrics
first_day=$(date -d "14 days ago" +%Y-%m-%d)
last_day=$(date +%Y-%m-%d)
echo "first_day=$first_day" >> $GITHUB_ENV
echo "last_day=$last_day" >> $GITHUB_ENV
echo "week_of=$(date -d '7 days ago' +'Week of %B %d, %Y')" >> $GITHUB_ENV
echo "date_range=Past 14 days ($first_day to $last_day)" >> $GITHUB_ENV
- name: Generate issue metrics
uses: github/issue-metrics@v3
@@ -45,19 +46,37 @@ jobs:
- name: Parse metrics
id: metrics
run: |
echo "Debug: Checking for generated files..."
ls -la *.md || echo "No markdown files found"
# Parse the metrics from the generated markdown files
if [ -f "issue_metrics.md" ]; then
echo "Debug: Found issue_metrics.md, contents:"
cat issue_metrics.md
# Extract key metrics using grep/awk
AVG_TIME_TO_FIRST_RESPONSE=$(grep -A 1 "Average time to first response" issue_metrics.md | tail -1 | xargs || echo "N/A")
AVG_TIME_TO_CLOSE=$(grep -A 1 "Average time to close" issue_metrics.md | tail -1 | xargs || echo "N/A")
NUM_ISSUES_CREATED=$(grep -oP '\d+(?= issues created)' issue_metrics.md || echo "0")
NUM_ISSUES_CLOSED=$(grep -oP '\d+(?= issues closed)' issue_metrics.md || echo "0")
else
echo "Debug: No issue_metrics.md file found"
NUM_ISSUES_CREATED=0
NUM_ISSUES_CLOSED=0
AVG_TIME_TO_FIRST_RESPONSE="N/A"
AVG_TIME_TO_CLOSE="N/A"
fi
if [ -f "pr_metrics.md" ]; then
echo "Debug: Found pr_metrics.md, contents:"
cat pr_metrics.md
PR_AVG_TIME_TO_MERGE=$(grep -A 1 "Average time to close" pr_metrics.md | tail -1 | xargs || echo "N/A")
NUM_PRS_CREATED=$(grep -oP '\d+(?= pull requests created)' pr_metrics.md || echo "0")
NUM_PRS_MERGED=$(grep -oP '\d+(?= pull requests closed)' pr_metrics.md || echo "0")
else
echo "Debug: No pr_metrics.md file found"
NUM_PRS_CREATED=0
NUM_PRS_MERGED=0
PR_AVG_TIME_TO_MERGE="N/A"
fi
# Set outputs for Discord action
@@ -69,6 +88,12 @@ jobs:
echo "avg_time_to_close=${AVG_TIME_TO_CLOSE:-N/A}" >> $GITHUB_OUTPUT
echo "pr_avg_merge_time=${PR_AVG_TIME_TO_MERGE:-N/A}" >> $GITHUB_OUTPUT
echo "Debug: Final outputs:"
echo "Issues created: ${NUM_ISSUES_CREATED:-0}"
echo "Issues closed: ${NUM_ISSUES_CLOSED:-0}"
echo "PRs created: ${NUM_PRS_CREATED:-0}"
echo "PRs merged: ${NUM_PRS_MERGED:-0}"
- name: Send to Discord
uses: sarisia/actions-status-discord@v1
if: env.DISCORD_WEBHOOK != ''
@@ -78,15 +103,16 @@ jobs:
title: "📊 Weekly Metrics Report"
description: |
**${{ env.week_of }}**
*${{ env.date_range }}*
**🎯 Issues**
• Created: ${{ steps.metrics.outputs.issues_created }}
• Closed: ${{ steps.metrics.outputs.issues_closed }}
**🔀 Pull Requests**
• Created: ${{ steps.metrics.outputs.prs_created }}
• Merged: ${{ steps.metrics.outputs.prs_merged }}
**⏱️ Response Times**
• First Response: ${{ steps.metrics.outputs.avg_first_response }}
• Time to Close: ${{ steps.metrics.outputs.avg_time_to_close }}