-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (129 loc) · 5.51 KB
/
Copy pathupdate-data.yml
File metadata and controls
152 lines (129 loc) · 5.51 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
name: Auto-Update Stats
on:
schedule:
# Run every 6 hours to keep stats fresh
- cron: '0 */6 * * *'
workflow_dispatch: # Allow manual triggering
push:
branches:
- main
paths:
- 'generate_html.py'
- 'update_readme.py'
- '.github/workflows/update-data.yml'
jobs:
update-data:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Cache pip dependencies
uses: actions/cache@v5
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# Install any dependencies if requirements.txt exists
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Configure git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Verify stats.json accessibility
run: |
echo "Checking status.semcl.one/data/stats.json accessibility..."
curl -f -s -o /tmp/stats.json https://status.semcl.one/data/stats.json
echo "Last updated: $(jq -r '.last_updated' /tmp/stats.json)"
echo "Packages found: $(jq '.packages | length' /tmp/stats.json)"
rm /tmp/stats.json
- name: Update README with latest component stats
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Running update_readme.py..."
python3 update_readme.py
if [ $? -eq 0 ]; then
echo "✅ README update completed successfully"
else
echo "❌ README update failed"
exit 1
fi
- name: Update website with latest component data
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Running generate_html.py..."
python3 generate_html.py
if [ $? -eq 0 ]; then
echo "✅ Website update completed successfully"
# Verify downloads stat was updated in HTML
downloads=$(grep -B 1 'stat-label">Downloads' index.html | grep 'stat-number' | grep -oP '>\K[^<]+' || echo "not found")
echo "Downloads stat in HTML: $downloads"
if [ "$downloads" = "N/A" ] || [ "$downloads" = "n/a" ] || [ "$downloads" = "not found" ]; then
echo "⚠️ Warning: Downloads stat is '$downloads' - data may not be loading correctly"
fi
else
echo "❌ Website update failed"
exit 1
fi
- name: Check for changes
id: changes
run: |
if git diff --quiet; then
echo "changes=false" >> $GITHUB_OUTPUT
echo "No changes detected"
else
echo "changes=true" >> $GITHUB_OUTPUT
echo "Changes detected:"
git diff --name-only
fi
- name: Commit and push changes
if: steps.changes.outputs.changes == 'true'
run: |
# Extract current downloads stat for commit message
downloads=$(grep -B 1 'stat-label">Downloads' index.html | grep 'stat-number' | grep -oP '>\K[^<]+' || echo "unknown")
git add README.md index.html
git commit -m "chore: auto-update component stats [skip ci]
- Downloads: $downloads (all-time, organic)
- Updated at: $(date -u '+%Y-%m-%d %H:%M UTC')
- Data source: status.semcl.one/data/stats.json"
git push
- name: Create summary
run: |
echo "## Auto-Update Stats Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Show current stats
downloads=$(grep -B 1 'stat-label">Downloads' index.html | grep 'stat-number' | grep -oP '>\K[^<]+' || echo "unknown")
completion=$(grep -B 1 'stat-label">Complete' index.html | grep 'stat-number' | grep -oP '>\K[^<]+' || echo "unknown")
components=$(grep -B 1 'stat-label">Components' index.html | grep 'stat-number' | grep -oP '>\K[^<]+' || echo "unknown")
echo "### Current Stats" >> $GITHUB_STEP_SUMMARY
echo "- 📥 **Downloads**: $downloads" >> $GITHUB_STEP_SUMMARY
echo "- 📊 **Completion**: $completion" >> $GITHUB_STEP_SUMMARY
echo "- 🎯 **Components**: $components" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.changes.outputs.changes }}" == "true" ]; then
echo "### ✅ Changes Committed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Updated files:" >> $GITHUB_STEP_SUMMARY
git diff --name-only HEAD~1 HEAD | sed 's/^/- /' >> $GITHUB_STEP_SUMMARY
else
echo "### ℹ️ No Changes" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "All component data is already up to date." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "**Run completed at:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
echo "**Data source:** https://status.semcl.one/data/stats.json" >> $GITHUB_STEP_SUMMARY