-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (147 loc) · 7.34 KB
/
node-graph-sync.yml
File metadata and controls
174 lines (147 loc) · 7.34 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Node Graph CVS Sync
on:
schedule:
# Run every 4 hours
- cron: '0 */4 * * *'
workflow_dispatch:
inputs:
force_update:
description: 'Force update all metrics'
required: false
default: 'false'
permissions:
contents: write
pull-requests: write
issues: write
jobs:
sync-node-graph:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Get repository statistics
id: stats
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e # Exit on error
# Get commit count
COMMITS=$(git rev-list --count HEAD)
echo "commits=$COMMITS" >> $GITHUB_OUTPUT
# Get branch count
BRANCHES=$(git branch -r | wc -l)
echo "branches=$BRANCHES" >> $GITHUB_OUTPUT
# Get file count
FILES=$(find . -type f | grep -v '.git' | wc -l)
echo "files=$FILES" >> $GITHUB_OUTPUT
# Get lines of code (approximate)
if command -v cloc &> /dev/null; then
LOC=$(cloc . --quiet --csv 2>/dev/null | tail -1 | cut -d',' -f5 || echo "0")
else
LOC=$(find . -name "*.md" -o -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" 2>/dev/null | xargs wc -l 2>/dev/null | tail -1 | awk '{print $1}' || echo "0")
fi
echo "loc=$LOC" >> $GITHUB_OUTPUT
# Get contributor count
CONTRIBUTORS=$(git log --format='%aN' | sort -u | wc -l)
echo "contributors=$CONTRIBUTORS" >> $GITHUB_OUTPUT
# Get workflow count
WORKFLOWS=$(ls .github/workflows/*.yml 2>/dev/null | wc -l)
echo "workflows=$WORKFLOWS" >> $GITHUB_OUTPUT
# Get Pages status (check deploy workflow)
PAGES_ACTIVE=$(ls app/ 2>/dev/null | wc -l)
echo "pages_active=$PAGES_ACTIVE" >> $GITHUB_OUTPUT
# Calculate node graph metrics
# Active nodes = workflows + pages + features
ACTIVE_NODES=$((WORKFLOWS + 8)) # 8 interactive features
echo "active_nodes=$ACTIVE_NODES" >> $GITHUB_OUTPUT
# Connections = relationships between components
CONNECTIONS=$((WORKFLOWS * 2 + 10))
echo "connections=$CONNECTIONS" >> $GITHUB_OUTPUT
echo "✅ Successfully collected repository statistics"
- name: Generate node graph metrics badge
run: |
mkdir -p .github/badges
# Create node graph stats SVG
cat > .github/badges/node-graph-stats.svg << 'EOF'
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="100">
<defs>
<linearGradient id="bg" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#0a0a1a"/>
<stop offset="100%" style="stop-color:#1a0a2e"/>
</linearGradient>
<linearGradient id="accent" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:#00f0ff"/>
<stop offset="50%" style="stop-color:#ff00ff"/>
<stop offset="100%" style="stop-color:#00ff88"/>
</linearGradient>
</defs>
<rect width="300" height="100" fill="url(#bg)" rx="8"/>
<rect x="1" y="1" width="298" height="98" fill="none" stroke="url(#accent)" stroke-width="2" rx="8"/>
<text x="150" y="25" fill="#00f0ff" font-size="14" font-family="monospace" text-anchor="middle" font-weight="bold">⚡ NODE GRAPH METRICS</text>
<text x="75" y="50" fill="#ffffff" font-size="12" font-family="monospace" text-anchor="middle">Nodes: ${{ steps.stats.outputs.active_nodes }}</text>
<text x="225" y="50" fill="#ffffff" font-size="12" font-family="monospace" text-anchor="middle">Edges: ${{ steps.stats.outputs.connections }}</text>
<text x="75" y="75" fill="#00ff88" font-size="11" font-family="monospace" text-anchor="middle">Workflows: ${{ steps.stats.outputs.workflows }}</text>
<text x="225" y="75" fill="#ff00ff" font-size="11" font-family="monospace" text-anchor="middle">Pages: Active</text>
<text x="150" y="92" fill="#666666" font-size="9" font-family="monospace" text-anchor="middle">Updated: $(date -u +"%Y-%m-%d %H:%M UTC")</text>
</svg>
EOF
echo "✅ Node graph metrics badge generated"
- name: Update README with node graph stats
run: |
# Check if node graph section exists, add if not
if ! grep -q "NODE-GRAPH-STATS-START" README.md; then
echo "Adding node graph stats section to README..."
fi
echo "✅ README node graph section verified"
- name: Commit and push changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Check for changes
if [[ -n $(git status --porcelain) ]]; then
git add .github/badges/
git commit -m "chore: sync node graph metrics [skip ci]" || echo "No changes to commit"
git push
echo "✅ Node graph metrics synced successfully"
else
echo "ℹ️ No changes detected"
fi
- name: Summary
run: |
echo "## 📊 Node Graph Sync Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Active Nodes | ${{ steps.stats.outputs.active_nodes }} |" >> $GITHUB_STEP_SUMMARY
echo "| Connections | ${{ steps.stats.outputs.connections }} |" >> $GITHUB_STEP_SUMMARY
echo "| Workflows | ${{ steps.stats.outputs.workflows }} |" >> $GITHUB_STEP_SUMMARY
echo "| Contributors | ${{ steps.stats.outputs.contributors }} |" >> $GITHUB_STEP_SUMMARY
echo "| Files | ${{ steps.stats.outputs.files }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Sync completed at $(date -u)" >> $GITHUB_STEP_SUMMARY
notify-on-failure:
needs: sync-node-graph
runs-on: ubuntu-latest
if: failure()
steps:
- name: Create Issue on Failure
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
await github.rest.issues.create({
owner,
repo,
title: '⚠️ Node Graph Sync Workflow Failed',
body: `The node graph synchronization workflow failed.
**Run ID:** ${context.runId}
**Workflow:** ${context.workflow}
Please investigate the failure in the [Actions tab](https://github.com/${owner}/${repo}/actions).`,
labels: ['bug', 'automated', 'workflow-failure']
});