Skip to content

Commit 1ad6e72

Browse files
author
Cell
committed
feat(ci): add automated PyPI download stats reporting workflow
- Add scheduled GitHub Actions workflow using daily cron trigger - Fetch package download statistics from ClickHouse at sql-clickhouse.clickhouse.com - Format numbers with locale-aware thousand separators for readability - Send daily statistics via Discord webhook including last 24h, 7-day, 30-day, and all-time totals - Supports manual workflow_dispatch trigger for ad-hoc statistics checks
1 parent d21b65f commit 1ad6e72

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: PyPI Download Stats
2+
3+
on:
4+
schedule:
5+
- cron: "0 9 * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
notify:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Fetch PyPI stats
13+
id: stats
14+
run: |
15+
STATS=$(curl -s -X POST 'https://sql-clickhouse.clickhouse.com:8443/?user=demo' \
16+
--data-binary "SELECT
17+
sumIf(count, date >= today() - 1) AS last_day,
18+
sumIf(count, date >= today() - 7) AS last_week,
19+
sumIf(count, date >= today() - 30) AS last_month,
20+
sum(count) AS total
21+
FROM pypi.pypi_downloads_per_day
22+
WHERE project = 'code-puppy'
23+
FORMAT JSONEachRow")
24+
25+
fmt() { LC_ALL=en_US.UTF-8 printf "%'d" "$1"; }
26+
27+
echo "last_day=$(fmt "$(echo "$STATS" | jq -r '.last_day')")" >> $GITHUB_OUTPUT
28+
echo "last_week=$(fmt "$(echo "$STATS" | jq -r '.last_week')")" >> $GITHUB_OUTPUT
29+
echo "last_month=$(fmt "$(echo "$STATS" | jq -r '.last_month')")" >> $GITHUB_OUTPUT
30+
echo "total=$(fmt "$(echo "$STATS" | jq -r '.total')")" >> $GITHUB_OUTPUT
31+
32+
- name: Send Discord notification
33+
env:
34+
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
35+
run: |
36+
curl -sS -X POST "$DISCORD_WEBHOOK_URL" \
37+
-H "Content-Type: application/json" \
38+
-d '{
39+
"embeds": [{
40+
"title": "🐶 PyPI Download Stats — code-puppy",
41+
"url": "https://clickpy.clickhouse.com/dashboard/code-puppy",
42+
"color": 5793266,
43+
"fields": [
44+
{
45+
"name": "Last 24h",
46+
"value": "${{ steps.stats.outputs.last_day }}",
47+
"inline": true
48+
},
49+
{
50+
"name": "Last 7 days",
51+
"value": "${{ steps.stats.outputs.last_week }}",
52+
"inline": true
53+
},
54+
{
55+
"name": "Last 30 days",
56+
"value": "${{ steps.stats.outputs.last_month }}",
57+
"inline": true
58+
},
59+
{
60+
"name": "All-time total",
61+
"value": "${{ steps.stats.outputs.total }}",
62+
"inline": false
63+
}
64+
],
65+
"footer": {
66+
"text": "clickpy.clickhouse.com"
67+
}
68+
}]
69+
}'

0 commit comments

Comments
 (0)