name: Technical Debt Analysis
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: '0 9 * * 1'
workflow_dispatch:
jobs:
analyze-debt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Technical Debt Analysis
run: |
chmod +x ./scripts/analyze_technical_debt.sh
./scripts/analyze_technical_debt.sh
- name: Upload Report
uses: actions/upload-artifact@v3
with:
name: technical-debt-report
path: technical_debt_reports/
retention-days: 90
- name: Check Critical Issues
id: check-critical
run: |
if grep -q "Critical Issues: [1-9]" technical_debt_reports/debt_analysis_*.md; then
echo "critical_found=true" >> $GITHUB_OUTPUT
echo "::warning::Critical technical debt issues detected!"
else
echo "critical_found=false" >> $GITHUB_OUTPUT
fi
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const reports = fs.readdirSync('technical_debt_reports');
const latestReport = reports.sort().reverse()[0];
const content = fs.readFileSync(`technical_debt_reports/${latestReport}`, 'utf8');
// Extract key metrics
const riskScore = content.match(/Risk Score: (\d+)/)?.[1] || '0';
const criticalIssues = content.match(/Critical Issues: (\d+)/)?.[1] || '0';
const unwraps = content.match(/unwrap\(\) calls.*: (\d+)/)?.[1] || '0';
const comment = `## 📊 Technical Debt Analysis
**Risk Score:** ${riskScore}/100
**Critical Issues:** ${criticalIssues}
**Unwrap Calls:** ${unwraps}
<details>
<summary>View Full Report</summary>
\`\`\`markdown
${content}
\`\`\`
</details>
${criticalIssues > 0 ? '⚠️ **Warning:** Critical technical debt detected!' : '✅ No critical issues found.'}
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Create Issue for Critical Debt
if: steps.check-critical.outputs.critical_found == 'true' && github.event_name == 'schedule'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const reports = fs.readdirSync('technical_debt_reports');
const latestReport = reports.sort().reverse()[0];
const content = fs.readFileSync(`technical_debt_reports/${latestReport}`, 'utf8');
const riskScore = content.match(/Risk Score: (\d+)/)?.[1] || '0';
const unwraps = content.match(/unwrap\(\) calls.*: (\d+)/)?.[1] || '0';
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `🔴 Critical Technical Debt Alert - Risk Score: ${riskScore}/100`,
body: `The weekly technical debt analysis has detected critical issues that need immediate attention.
## Key Metrics
- **Risk Score:** ${riskScore}/100
- **Unwrap Calls:** ${unwraps} (potential panic points)
## Required Actions
1. Review the full report in the Actions artifacts
2. Prioritize fixing unwrap() calls
3. Update documentation for public APIs
This issue was automatically created by the Technical Debt Analysis workflow.`,
labels: ['technical-debt', 'critical', 'automated']
});