Skip to content

Commit 3db8e7c

Browse files
committed
ci: send stats to posthog
1 parent b459055 commit 3db8e7c

4 files changed

Lines changed: 51 additions & 42 deletions

File tree

.github/workflows/stats.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ jobs:
3030
git add STATS.md
3131
git diff --staged --quiet || git commit -m "ignore: update download stats $(date -I)"
3232
git push
33+
env:
34+
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}

AGENTS.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
## Style
1+
## IMPORTANT
22

3-
- prefer single word variable/function names
4-
- avoid try catch where possible - prefer to let exceptions bubble up
5-
- avoid else statements where possible
6-
- do not make useless helper functions - inline functionality unless the
7-
function is reusable or composable
8-
- prefer Bun apis
9-
10-
## Workflow
11-
12-
- you can regenerate the golang sdk by calling ./scripts/stainless.ts
13-
- we use bun for everything
3+
- Try to keep things in one function unless composable or reusable
4+
- DO NOT do unnecessary destructuring of variables
5+
- DO NOT use `else` statements unless necessary
6+
- DO NOT use `try`/`catch` if it can be avoided
7+
- AVOID `try`/`catch` where possible
8+
- AVOID `else` statements
9+
- AVOID using `any` type
10+
- AVOID `let` statements
11+
- PREFER single word variable names where possible
12+
- Use as many bun apis as possible like Bun.file()

packages/opencode/AGENTS.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@
1717
- **Error handling**: Use Result patterns, avoid throwing exceptions in tools
1818
- **File structure**: Namespace-based organization (e.g., `Tool.define()`, `Session.create()`)
1919

20-
## IMPORTANT
21-
22-
- Try to keep things in one function unless composable or reusable
23-
- DO NOT do unnecessary destructuring of variables
24-
- DO NOT use `else` statements unless necessary
25-
- DO NOT use `try`/`catch` if it can be avoided
26-
- AVOID `try`/`catch` where possible
27-
- AVOID `else` statements
28-
- AVOID using `any` type
29-
- AVOID `let` statements
30-
- PREFER single word variable names where possible
31-
- Use as many bun apis as possible like Bun.file()
32-
3320
## Architecture
3421

3522
- **Tools**: Implement `Tool.Info` interface with `execute()` method

script/stats.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
#!/usr/bin/env bun
22

3+
async function sendToPostHog(event: string, properties: Record<string, any>) {
4+
const key = process.env["POSTHOG_KEY"]
5+
6+
if (!key) {
7+
console.warn("POSTHOG_API_KEY not set, skipping PostHog event")
8+
return
9+
}
10+
11+
const response = await fetch("https://us.i.posthog.com/i/v0/e/", {
12+
method: "POST",
13+
headers: {
14+
"Content-Type": "application/json",
15+
},
16+
body: JSON.stringify({
17+
distinct_id: "download",
18+
api_key: key,
19+
event,
20+
properties: {
21+
...properties,
22+
},
23+
}),
24+
}).catch(() => null)
25+
26+
if (response && !response.ok) {
27+
console.warn(`PostHog API error: ${response.status}`)
28+
}
29+
}
30+
331
interface Asset {
432
name: string
533
download_count: number
@@ -173,6 +201,16 @@ console.log(`Fetched npm all-time downloads: ${npmDownloads.toLocaleString()}\n`
173201

174202
await save(githubTotal, npmDownloads)
175203

204+
await sendToPostHog("download", {
205+
count: githubTotal,
206+
source: "github",
207+
})
208+
209+
await sendToPostHog("download", {
210+
count: npmDownloads,
211+
source: "npm",
212+
})
213+
176214
const totalDownloads = githubTotal + npmDownloads
177215

178216
console.log("=".repeat(60))
@@ -181,23 +219,6 @@ console.log(` GitHub: ${githubTotal.toLocaleString()}`)
181219
console.log(` npm: ${npmDownloads.toLocaleString()}`)
182220
console.log("=".repeat(60))
183221

184-
console.log("\nDownloads by release:")
185-
console.log("-".repeat(60))
186-
187-
stats
188-
.sort((a, b) => b.downloads - a.downloads)
189-
.forEach((release) => {
190-
console.log(`${release.tag.padEnd(15)} ${release.downloads.toLocaleString().padStart(10)} downloads`)
191-
192-
if (release.assets.length > 1) {
193-
release.assets
194-
.sort((a, b) => b.downloads - a.downloads)
195-
.forEach((asset) => {
196-
console.log(` └─ ${asset.name.padEnd(25)} ${asset.downloads.toLocaleString().padStart(8)}`)
197-
})
198-
}
199-
})
200-
201222
console.log("-".repeat(60))
202223
console.log(`GitHub Total: ${githubTotal.toLocaleString()} downloads across ${releases.length} releases`)
203224
console.log(`npm Total: ${npmDownloads.toLocaleString()} downloads`)

0 commit comments

Comments
 (0)