Skip to content

Add daily code metrics workflow with persistent trend tracking#3639

Merged
pelikhan merged 4 commits into
mainfrom
copilot/add-daily-code-metrics-workflow
Nov 11, 2025
Merged

Add daily code metrics workflow with persistent trend tracking#3639
pelikhan merged 4 commits into
mainfrom
copilot/add-daily-code-metrics-workflow

Conversation

Copilot AI commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

Implementation Complete: Daily Code Metrics Workflow ✅

Successfully implemented the daily code metrics workflow as requested in issue #3605.

Implementation Checklist

  • Explore repository structure and understand existing workflows
  • Analyze similar workflows (lockfile-stats, duplicate-code-detector, repo-tree-map)
  • Verify gh-aw binary is available for compilation
  • Create .github/workflows/daily-code-metrics.md workflow file (543 lines)
  • Configure workflow with all required settings
  • Implement all 6 metric categories with bash commands
  • Implement trend tracking with JSON Lines storage
  • Compile workflow successfully (215.1 KB lock file)
  • Validate with strict mode (0 errors, 0 warnings)
  • Verify all requirements from issue are met
  • Final verification and documentation
  • Merge main branch to include latest changes

Merge Summary

Merged main branch (commits 35ba212 and 2c547f8) into the feature branch to include:

All workflows continue to compile successfully with the new validation:

✓ .github/workflows/daily-code-metrics.md (215.1 KB)
✓ All pinned actions are up to date
✓ Successfully compiled 1 workflow file(s)
✓ Compiled 1 workflow(s): 0 error(s), 0 warning(s)

Files Created

  1. .github/workflows/daily-code-metrics.md (543 lines)

    • Complete workflow definition with comprehensive instructions
    • 6 metric categories with detailed collection strategies
    • Historical data management with JSON Lines format
    • Report generation template with ASCII visualizations
    • Quality score calculation methodology
    • Trend tracking over 7-day and 30-day windows
  2. .github/workflows/daily-code-metrics.lock.yml (215.1 KB)

    • Auto-generated compiled GitHub Actions workflow
    • Pinned action versions for security
    • All dependencies and configurations resolved

Key Features Implemented

Configuration:

  • ✅ Daily schedule at 8 AM UTC (cron: "0 8 * * *")
  • ✅ Manual trigger via workflow_dispatch
  • ✅ Claude engine for comprehensive analysis
  • ✅ 15-minute timeout
  • ✅ Strict mode enabled for enhanced validation
  • ✅ Read-only permissions

Metrics (6 Categories):

  1. Codebase Size: LOC by language (Go, JS/CJS, YAML, MD), directory, file distribution
  2. Code Quality: Average file size, large files, function counts, comments
  3. Test Coverage: Test files, test LOC, test-to-source ratio
  4. Code Churn: 7-day activity (files, commits, lines added/deleted)
  5. Workflows: Agentic workflow counts and statistics
  6. Documentation: Doc files, LOC, code-to-docs ratio

Trend Tracking:

  • ✅ Persistent storage: /tmp/gh-aw/cache-memory/metrics/
  • ✅ JSON Lines format for efficient time-series data
  • ✅ 7-day and 30-day trend calculations
  • ✅ Trend indicators: ⬆️ (up) ➡️ (stable) ⬇️ (down)
  • ✅ 90-day data retention
  • ✅ Anomaly detection (>10% changes)

Report Generation:

  • ✅ Executive summary with key metrics
  • ✅ Detailed comparison tables (current vs 7-day vs 30-day)
  • ✅ ASCII trend visualizations
  • ✅ Quality score (0-100 composite metric)
  • ✅ Actionable insights and recommendations
  • ✅ Published to "audits" discussion category

Validation Results

Compilation:

✓ .github/workflows/daily-code-metrics.md (215.1 KB)
✓ All pinned actions are up to date
✓ Successfully compiled 1 workflow file(s)
✓ Compiled 1 workflow(s): 0 error(s), 0 warning(s)

Strict Mode:

✓ All security checks passed
✓ All validation rules passed
✓ 0 errors, 0 warnings

Deployment Status

Status: ✅ READY FOR REVIEW AND MERGE

Branch: copilot/add-daily-code-metrics-workflow

Next Steps:

  1. Review and merge the pull request
  2. Workflow will run automatically tomorrow at 8 AM UTC
  3. Or trigger manually via workflow_dispatch for immediate test
  4. First run establishes baseline data
  5. Trends improve as historical data accumulates over 30+ days
  6. Reports published to "audits" discussion category
Original prompt

This section details on the original issue you should resolve

<issue_title>[q] Add Daily Code Metrics Workflow with Trend Tracking</issue_title>
<issue_description># Q Workflow Optimization Report

Context

This pull request addresses the request from discussion #3605 to create a daily workflow that computes code/codebase size and quality metrics and provides trends over time.

Issues Found (from Analysis)

Current State Assessment

Log Analysis Summary:

  • No existing code metrics workflow was found in the repository
  • Existing workflows like lockfile-stats and duplicate-code-detector provide partial coverage but don't track comprehensive metrics over time
  • No persistent trend tracking mechanism exists for codebase health

Workflow Patterns Identified:

  • Repository has 79 agentic workflows tracking various aspects
  • Several workflows use cache-memory for persistence (lockfile-stats.md)
  • Strong pattern of using bash tools for analysis
  • Safe-outputs (create-discussion) pattern well-established for reporting

Changes Made

New Workflow: daily-code-metrics.md

Created a comprehensive daily code metrics tracking workflow that:

1. Tracks Multiple Metric Categories

Codebase Size Metrics:

  • Lines of Code (LOC) by language (Go, JavaScript/CJS, YAML, Markdown)
  • LOC by directory (cmd/, pkg/, workflows/)
  • File counts and distribution
  • Directory structure analysis

Code Quality Metrics:

  • Complexity indicators (function sizes, nesting depth)
  • Code organization metrics
  • Comment-to-code ratio
  • Large file detection

Test Coverage Metrics:

  • Test file counts and distribution
  • Test-to-source LOC ratio
  • Test organization patterns

Code Churn Metrics (7-day window):

  • Files modified
  • Lines added/deleted
  • Commit frequency
  • Most active areas

Workflow Metrics:

  • Agentic workflow statistics
  • Engine distribution
  • Trigger patterns

Documentation Metrics:

  • Doc file coverage
  • Code-to-docs ratio

2. Implements Persistent Trend Tracking

  • Cache Storage: Uses /tmp/gh-aw/cache-memory/metrics/ for persistent data
  • Data Format: JSON Lines (.jsonl) for efficient time-series storage
  • Historical Analysis: Tracks 30+ days of historical data
  • Trend Calculations:
    • 7-day trends (percentage change)
    • 30-day trends (percentage change)
    • Growth rates and volatility indicators

3. Generates Comprehensive Reports

  • Executive Summary: High-level metrics with trends
  • Detailed Tables: Current vs 7-day vs 30-day comparisons
  • Visual Charts: ASCII-based trend visualizations
  • Quality Score: Composite score (0-100) based on multiple factors
  • Insights & Recommendations: Actionable findings

4. Configuration Details

engine: claude                    # Using Claude for comprehensive analysis
tools:
  cache-memory:
    - id: metrics                 # Persistent storage for trends
      key: code-metrics-${{ github.workflow }}
  bash:                           # Bash tools for data collection
safe-outputs:
  create-discussion:              # Publishes to audits category
    category: "audits"
schedule:
  - cron: "0 8 * * *"            # Daily at 8 AM UTC
timeout-minutes: 15               # Adequate time for analysis
strict: true                      # Enhanced validation

Expected Improvements

Visibility & Tracking

  1. Daily Metrics Snapshot: Automated daily collection eliminates manual tracking
  2. Trend Detection: Identifies growth patterns, code churn spikes, quality degradation
  3. Historical Context: Builds 30+ day history for informed decision-making

Code Quality Insights

  1. Quality Score Tracking: Composite metric (0-100) tracks overall codebase health
  2. Complexity Monitoring: Detects increasing complexity early
  3. Test Coverage Trends: Monitors test-to-code ratio changes

Actionable Intelligence

  1. Automated Reports: Published to audits discussion category for team visibility
  2. Anomaly Detection: Highlights unusual changes (>10% spikes)
  3. Recommendation Engine: Provides context-based suggestions

Team Alignment

  1. Shared Metrics: Common baseline for discussions about code health
  2. Progress Tracking: Shows impact of refactoring efforts over time
  3. Data-Driven Decisions: Objective metrics inform technical debt prioritization

Validation

Compilation Status: ✅ Workflow compiled successfully

✓ .github/workflows/daily-code-metrics.md (211.9 KB)
✓ Compiled 1 workflow(s): 0 error(s), 0 warning(s)

Note: The .lock.yml file will be generated automatically after merge as per Q workflow guidelines.

Implementation Notes

Cache Memory Strategy

  • Persistence: GitHub Actions cache preserves data across runs
  • Format: JSON Lines for efficient append operations
  • Retention: Last 90 days retained in history
  • Recovery: Graceful handling of missi...

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 11, 2025 17:23
…tion

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot merge main

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot continue

Copilot AI commented Nov 11, 2025

Copy link
Copy Markdown
Contributor Author

@copilot continue

Merged main branch successfully in commit 041af8a. The daily-code-metrics workflow continues to compile without errors, and all pinned actions are up to date with the new SHA validation.

@pelikhan pelikhan marked this pull request as ready for review November 11, 2025 18:30
Copilot AI review requested due to automatic review settings November 11, 2025 18:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a comprehensive daily code metrics workflow that tracks codebase health metrics over time with persistent trend tracking. The workflow runs daily at 8 AM UTC using the Claude engine to analyze repository metrics across 6 categories (codebase size, code quality, test coverage, code churn, workflows, and documentation), stores historical data using cache-memory, and publishes detailed reports to the "audits" discussion category.

Key Changes

  • New agentic workflow for automated daily code metrics collection and analysis
  • Persistent trend tracking using cache-memory with JSON Lines storage format
  • Comprehensive metric collection across 6 categories with 7-day and 30-day trend analysis
  • Automated report generation with ASCII visualizations and quality scores

Reviewed Changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 4 comments.

File Description
.github/workflows/daily-code-metrics.md 543-line workflow definition with detailed instructions for metric collection, historical data management, trend calculation, and report generation
.github/workflows/daily-code-metrics.lock.yml 4559-line compiled GitHub Actions workflow with all dependencies, configurations, and pinned action versions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


- **Repository**: ${{ github.repository }}
- **Analysis Date**: $(date +%Y-%m-%d)
- **Cache Location**: `/tmp/gh-aw/cache-memory/metrics/`

Copilot AI Nov 11, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache location path references cache-memory/metrics/ but the actual cache configuration uses cache-memory-metrics/ (as seen in the lock file line 170). This inconsistency could cause confusion when debugging cache issues. Update the documentation to match the actual implementation path /tmp/gh-aw/cache-memory-metrics/.

Suggested change
- **Cache Location**: `/tmp/gh-aw/cache-memory/metrics/`
- **Cache Location**: `/tmp/gh-aw/cache-memory-metrics/`

Copilot uses AI. Check for mistakes.
find . -type f \( -name "*.js" -o -name "*.cjs" \) ! -name "*.test.js" ! -name "*.test.cjs" ! -path "./.git/*" ! -path "./node_modules/*" | xargs wc -l | tail -1

# YAML files
find . -type f -name "*.yml" -o -name "*.yaml" ! -path "./.git/*" | xargs wc -l | tail -1

Copilot AI Nov 11, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The find command has incorrect operator precedence that will cause it to match all files. The -o operator binds more tightly than the ! -path exclusion, so files in .git/ directories will not be properly excluded. Wrap the name conditions in parentheses: find . -type f \( -name "*.yml" -o -name "*.yaml" \) ! -path "./.git/*" | xargs wc -l | tail -1.

Suggested change
find . -type f -name "*.yml" -o -name "*.yaml" ! -path "./.git/*" | xargs wc -l | tail -1
find . -type f \( -name "*.yml" -o -name "*.yaml" \) ! -path "./.git/*" | xargs wc -l | tail -1

Copilot uses AI. Check for mistakes.

### Cache Memory Usage

- **Persistent Storage**: Maintain history in `/tmp/gh-aw/cache-memory/metrics/`

Copilot AI Nov 11, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same path inconsistency as Comment 1. The documented path /tmp/gh-aw/cache-memory/metrics/ doesn't match the actual cache mount point /tmp/gh-aw/cache-memory-metrics/ used in the workflow configuration. This will cause the historical data to be stored in the wrong location and not persist across runs.

Suggested change
- **Persistent Storage**: Maintain history in `/tmp/gh-aw/cache-memory/metrics/`
- **Persistent Storage**: Maintain history in `/tmp/gh-aw/cache-memory-metrics/`

Copilot uses AI. Check for mistakes.

### Cache Memory Usage

- **Persistent Storage**: Maintain history in `/tmp/gh-aw/cache-memory/metrics/`

Copilot AI Nov 11, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another instance of the same cache path inconsistency. All references to the cache storage location should use /tmp/gh-aw/cache-memory-metrics/ to match the actual configuration.

Suggested change
- **Persistent Storage**: Maintain history in `/tmp/gh-aw/cache-memory/metrics/`
- **Persistent Storage**: Maintain history in `/tmp/gh-aw/cache-memory-metrics/`

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 84f5cb5 into main Nov 11, 2025
48 of 52 checks passed
@pelikhan pelikhan deleted the copilot/add-daily-code-metrics-workflow branch November 11, 2025 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[q] Add Daily Code Metrics Workflow with Trend Tracking

3 participants