Skip to content

Commit 249429b

Browse files
committed
chore: add daily GitHub download stats to PostHog
Scheduled workflow runs daily at 06:00 UTC, queries GitHub Releases API for download counts per version/platform, and sends them to PostHog as release_downloads events. Can also be triggered manually. Signed-off-by: Mohammod Al Amin Ashik <maa.ashik00@gmail.com>
1 parent 1dfcaca commit 249429b

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Download Stats to PostHog
2+
3+
on:
4+
schedule:
5+
# Run daily at 06:00 UTC
6+
- cron: '0 6 * * *'
7+
workflow_dispatch: # Allow manual trigger
8+
9+
jobs:
10+
report-downloads:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Send download counts to PostHog
14+
env:
15+
POSTHOG_KEY: ${{ secrets.VITE_POSTHOG_KEY }}
16+
POSTHOG_HOST: ${{ secrets.VITE_POSTHOG_HOST }}
17+
GH_TOKEN: ${{ github.token }}
18+
run: |
19+
POSTHOG_HOST="${POSTHOG_HOST:-https://us.i.posthog.com}"
20+
21+
# Fetch all releases
22+
releases=$(gh api repos/${{ github.repository }}/releases --paginate)
23+
24+
# Parse and send per-release download counts
25+
echo "$releases" | jq -c '.[]' | while read -r release; do
26+
tag=$(echo "$release" | jq -r '.tag_name')
27+
published=$(echo "$release" | jq -r '.published_at')
28+
29+
# Count real downloads (exclude .sig files and latest.json)
30+
downloads=$(echo "$release" | jq '[.assets[] | select(.name | (endswith(".sig") or . == "latest.json") | not) | .download_count] | add // 0')
31+
32+
# Per-platform counts
33+
windows=$(echo "$release" | jq '[.assets[] | select(.name | test("\\.(msi|exe)$")) | select(.name | endswith(".sig") | not) | .download_count] | add // 0')
34+
macos=$(echo "$release" | jq '[.assets[] | select(.name | endswith(".dmg")) | .download_count] | add // 0')
35+
linux=$(echo "$release" | jq '[.assets[] | select(.name | test("\\.(deb|rpm|AppImage)$")) | .download_count] | add // 0')
36+
37+
# latest.json hits (proxy for active installs checking for updates)
38+
updater_checks=$(echo "$release" | jq '[.assets[] | select(.name == "latest.json") | .download_count] | add // 0')
39+
40+
echo " $tag: $downloads downloads (win=$windows, mac=$macos, linux=$linux, updater=$updater_checks)"
41+
42+
# Send to PostHog
43+
curl -s -o /dev/null "${POSTHOG_HOST}/capture/" \
44+
-H 'Content-Type: application/json' \
45+
-d "{
46+
\"api_key\": \"${POSTHOG_KEY}\",
47+
\"event\": \"release_downloads\",
48+
\"distinct_id\": \"github-release-stats\",
49+
\"properties\": {
50+
\"version\": \"${tag}\",
51+
\"published_at\": \"${published}\",
52+
\"total_downloads\": ${downloads},
53+
\"windows_downloads\": ${windows},
54+
\"macos_downloads\": ${macos},
55+
\"linux_downloads\": ${linux},
56+
\"updater_checks\": ${updater_checks}
57+
}
58+
}"
59+
done
60+
61+
echo "Done reporting download stats to PostHog"

0 commit comments

Comments
 (0)