Skip to content

Commit d10e8e2

Browse files
committed
Add analytics page
1 parent cda370c commit d10e8e2

File tree

14 files changed

+2638
-5
lines changed

14 files changed

+2638
-5
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: Collect GitHub Metrics
2+
3+
on:
4+
# Run weekly on Mondays at 00:00 UTC
5+
schedule:
6+
- cron: '0 0 * * 1'
7+
# Allow manual trigger
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
collect-metrics:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v6
19+
with:
20+
# Use default fetch for faster checkout
21+
fetch-depth: 1
22+
# Ensure we're on the latest main branch
23+
ref: main
24+
25+
- name: Setup GitHub CLI
26+
run: |
27+
# gh is pre-installed on GitHub Actions runners
28+
# Use METRICS_GITHUB_TOKEN if available (for traffic data), fallback to GITHUB_TOKEN
29+
TOKEN="${{ secrets.METRICS_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}"
30+
echo "$TOKEN" | gh auth login --with-token
31+
32+
- name: Install uv
33+
uses: astral-sh/setup-uv@v7
34+
with:
35+
version: "0.9.11"
36+
enable-cache: true
37+
38+
- name: Set up Python
39+
uses: actions/setup-python@v6
40+
with:
41+
python-version: '3.12'
42+
43+
- name: Install Python dependencies
44+
run: uv pip install --system pyyaml
45+
46+
- name: Configure git
47+
run: |
48+
git config user.name "github-actions[bot]"
49+
git config user.email "github-actions[bot]@users.noreply.github.com"
50+
51+
- name: Ensure data directory exists
52+
run: mkdir -p catalog/public/data
53+
54+
- name: Collect GitHub metrics
55+
id: collect
56+
run: |
57+
python scripts/collect_github_metrics.py
58+
if [ $? -ne 0 ]; then
59+
echo "error=true" >> $GITHUB_OUTPUT
60+
exit 1
61+
fi
62+
echo "error=false" >> $GITHUB_OUTPUT
63+
env:
64+
GH_TOKEN: ${{ secrets.METRICS_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
65+
66+
- name: Validate JSON files
67+
run: |
68+
echo "Validating JSON files..."
69+
python -c "import json; json.load(open('catalog/public/data/github_metrics.json'))"
70+
python -c "import json; json.load(open('catalog/public/data/github_metrics_history.json'))"
71+
echo "✓ JSON files are valid"
72+
73+
- name: Check for changes
74+
id: check_changes
75+
run: |
76+
git add catalog/public/data/github_metrics.json
77+
git add catalog/public/data/github_metrics_history.json
78+
if git diff --cached --quiet; then
79+
echo "changed=false" >> $GITHUB_OUTPUT
80+
echo "No changes to commit"
81+
else
82+
echo "changed=true" >> $GITHUB_OUTPUT
83+
echo "Changes detected, will commit"
84+
fi
85+
86+
- name: Commit and push metrics data
87+
if: steps.check_changes.outputs.changed == 'true'
88+
run: |
89+
git commit -m "chore: update GitHub metrics data
90+
91+
🤖 Automated weekly metrics collection
92+
93+
- Updated current metrics snapshot
94+
- Added to historical metrics database
95+
96+
Generated by: ${{ github.workflow }}
97+
Run ID: ${{ github.run_id }}"
98+
99+
# Push with retry logic
100+
for i in {1..3}; do
101+
if git push origin main; then
102+
echo "✓ Successfully pushed changes"
103+
break
104+
else
105+
if [ $i -lt 3 ]; then
106+
echo "Push failed, retrying in 5 seconds... (attempt $i/3)"
107+
sleep 5
108+
git pull --rebase origin main
109+
else
110+
echo "Failed to push after 3 attempts"
111+
exit 1
112+
fi
113+
fi
114+
done
115+
116+
- name: Create summary
117+
if: always()
118+
run: |
119+
echo "## GitHub Metrics Collection Results" >> $GITHUB_STEP_SUMMARY
120+
echo "" >> $GITHUB_STEP_SUMMARY
121+
echo "**Workflow Run:** \`${{ github.workflow }}\`" >> $GITHUB_STEP_SUMMARY
122+
echo "**Trigger:** \`${{ github.event_name }}\`" >> $GITHUB_STEP_SUMMARY
123+
echo "**Date:** \`$(date -u)\`" >> $GITHUB_STEP_SUMMARY
124+
echo "" >> $GITHUB_STEP_SUMMARY
125+
126+
if [ "${{ steps.collect.outputs.error }}" == "true" ]; then
127+
echo "**Status:** ❌ Collection failed" >> $GITHUB_STEP_SUMMARY
128+
exit 0
129+
fi
130+
131+
if [ -f catalog/public/data/github_metrics.json ]; then
132+
REPO_COUNT=$(python -c "import json; data=json.load(open('catalog/public/data/github_metrics.json')); print(len(data.get('repos', {})))")
133+
echo "**Repositories Tracked:** $REPO_COUNT" >> $GITHUB_STEP_SUMMARY
134+
135+
LAST_UPDATED=$(python -c "import json; data=json.load(open('catalog/public/data/github_metrics.json')); print(data.get('last_updated', 'Unknown'))")
136+
echo "**Last Updated:** \`$LAST_UPDATED\`" >> $GITHUB_STEP_SUMMARY
137+
fi
138+
139+
if [ "${{ steps.check_changes.outputs.changed }}" == "true" ]; then
140+
echo "**Status:** ✅ Metrics updated and committed" >> $GITHUB_STEP_SUMMARY
141+
echo "" >> $GITHUB_STEP_SUMMARY
142+
echo "The deployment workflow will automatically trigger to publish the updated analytics." >> $GITHUB_STEP_SUMMARY
143+
else
144+
echo "**Status:** ℹ️ No changes detected" >> $GITHUB_STEP_SUMMARY
145+
fi

.github/workflows/deploy-catalog.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ on:
1010
- 'scripts/sync_repositories_to_json.py'
1111
- '.github/workflows/deploy-catalog.yml'
1212
workflow_dispatch:
13+
# Auto-trigger when metrics are updated
14+
workflow_run:
15+
workflows: ["Collect GitHub Metrics"]
16+
types:
17+
- completed
18+
branches:
19+
- main
1320

1421
permissions:
1522
contents: write
@@ -21,6 +28,8 @@ concurrency:
2128
jobs:
2229
build-and-deploy:
2330
runs-on: ubuntu-latest
31+
# Only deploy if metrics collection succeeded (or if triggered by push/manual)
32+
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
2433
steps:
2534
- name: Checkout
2635
uses: actions/checkout@v6

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ repos:
3838
hooks:
3939
- id: typos
4040
args: []
41-
exclude: ^(catalog/public/data/repositories.json|catalog/public/data/papers\.bib|repositories/crisp-nam\.yaml)$
41+
exclude: ^(catalog/public/data/repositories.json|catalog/public/data/papers\.bib|catalog/public/data/github_metrics.json|catalog/public/data/github_metrics_history.json|repositories/crisp-nam\.yaml)$
4242

4343
- repo: local
4444
hooks:

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ npm install
2525
npm run dev
2626
```
2727

28+
## 📊 Analytics Dashboard
29+
30+
Executive dashboard for catalog performance metrics:
31+
- **Key Metrics**: Aggregate stats across all repositories
32+
- **Top Performers**: Highest starred, most visited, and most cloned repos
33+
- **Complete Overview**: Sortable table of all repositories
34+
- **Auto-Update**: Weekly collection via GitHub Actions (Mondays at 00:00 UTC)
35+
36+
**Manual Collection**: `python scripts/collect_github_metrics.py` (requires `gh` CLI)
37+
38+
> **Note**: Traffic data (views/clones) requires a Personal Access Token with `repo` permissions. Add as `METRICS_GITHUB_TOKEN` secret in repository settings. Without it, traffic metrics will show "—" but basic metrics (stars, forks) still work.
39+
2840
## 📋 Repository Information
2941

3042
The catalog contains the following information for each implementation:

0 commit comments

Comments
 (0)