Skip to content

Commit 4b51a8d

Browse files
Added SOURCEBOT_VERSION build arg + versioned telemetry (#41)
1 parent 36a1464 commit 4b51a8d

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

.github/workflows/ghcr-publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ jobs:
7373
cache-to: type=gha,mode=max
7474
platforms: ${{ matrix.platform }}
7575
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
76+
build-args: |
77+
SOURCEBOT_VERSION=${{ github.ref_name }}
7678
7779
- name: Export digest
7880
run: |

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added a `SOURCEBOT_VERSION` build argument to the Docker image. ([#41](https://github.com/sourcebot-dev/sourcebot/pull/41))
13+
- Added the `sourcebot_version` property to all PostHog events for versioned telemetry. ([#41](https://github.com/sourcebot-dev/sourcebot/pull/41)
14+
1015
## [1.0.3] - 2024-10-15
1116

1217
### Fixed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ COPY . .
2424
ENV NEXT_TELEMETRY_DISABLED=1
2525
# @see: https://phase.dev/blog/nextjs-public-runtime-variables/
2626
ARG NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED=BAKED_NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED
27+
ARG NEXT_PUBLIC_SOURCEBOT_VERSION=BAKED_NEXT_PUBLIC_SOURCEBOT_VERSION
2728
RUN yarn run build
2829

2930
# ------ Runner ------
@@ -35,6 +36,10 @@ ENV DATA_DIR=/data
3536
ENV CONFIG_PATH=$DATA_DIR/config.json
3637
ENV DATA_CACHE_DIR=$DATA_DIR/.sourcebot
3738

39+
ARG SOURCEBOT_VERSION=unknown
40+
ENV SOURCEBOT_VERSION=$SOURCEBOT_VERSION
41+
RUN echo "Sourcebot Version: $SOURCEBOT_VERSION"
42+
3843
ENV GITHUB_HOSTNAME=github.com
3944
ENV GITLAB_HOSTNAME=gitlab.com
4045

entrypoint.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22
set -e
33

4+
echo -e "\e[34m[Info] Sourcebot version: $SOURCEBOT_VERSION\e[0m"
5+
46
# Issue a info message about telemetry
57
if [ ! -z "$SOURCEBOT_TELEMETRY_DISABLED" ]; then
68
echo -e "\e[34m[Info] Disabling telemetry since SOURCEBOT_TELEMETRY_DISABLED was set.\e[0m"
@@ -23,7 +25,10 @@ if [ ! -f "$FIRST_RUN_FILE" ]; then
2325
curl -L -s --header "Content-Type: application/json" -d '{
2426
"api_key": "'"$NEXT_PUBLIC_POSTHOG_KEY"'",
2527
"event": "install",
26-
"distinct_id": "'"$(uuidgen)"'"
28+
"distinct_id": "'"$(uuidgen)"'",
29+
"properties": {
30+
"sourcebot_version": "'"$SOURCEBOT_VERSION"'"
31+
}
2732
}' https://us.i.posthog.com/capture/ > /dev/null
2833
fi
2934
fi
@@ -79,9 +84,15 @@ if [ -z "$NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED" ] && [ ! -z "$SOURCEBOT_TELE
7984
export NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED="$SOURCEBOT_TELEMETRY_DISABLED"
8085
fi
8186

87+
# Infer NEXT_PUBLIC_SOURCEBOT_VERSION if it is not set
88+
if [ -z "$NEXT_PUBLIC_SOURCEBOT_VERSION" ] && [ ! -z "$SOURCEBOT_VERSION" ]; then
89+
export NEXT_PUBLIC_SOURCEBOT_VERSION="$SOURCEBOT_VERSION"
90+
fi
91+
8292
find /app/public /app/.next -type f -name "*.js" |
8393
while read file; do
8494
sed -i "s|BAKED_NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED|${NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED}|g" "$file"
95+
sed -i "s|BAKED_NEXT_PUBLIC_SOURCEBOT_VERSION|${NEXT_PUBLIC_SOURCEBOT_VERSION}|g" "$file"
8596
done
8697

8798
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf

src/hooks/useCaptureEvent.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import { CaptureOptions } from "posthog-js";
44
import posthog from "posthog-js";
55
import { PosthogEvent, PosthogEventMap } from "../lib/posthogEvents";
6+
import { NEXT_PUBLIC_SOURCEBOT_VERSION } from "@/lib/environment.client";
67

78
export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E], options?: CaptureOptions) {
89
if(!options) {
910
options = {};
1011
}
1112
options.send_instantly = true;
12-
posthog.capture(event, properties, options);
13+
posthog.capture(event, {
14+
...properties,
15+
sourcebot_version: NEXT_PUBLIC_SOURCEBOT_VERSION,
16+
}, options);
1317
}
1418

1519
/**

src/lib/environment.client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export const NEXT_PUBLIC_POSTHOG_HOST = getEnv(process.env.NEXT_PUBLIC_POSTHOG_H
77
export const NEXT_PUBLIC_POSTHOG_UI_HOST = getEnv(process.env.NEXT_PUBLIC_POSTHOG_UI_HOST);
88
export const NEXT_PUBLIC_POSTHOG_ASSET_HOST = getEnv(process.env.NEXT_PUBLIC_POSTHOG_ASSET_HOST);
99
export const NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED = getEnvBoolean(process.env.NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED, false);
10+
export const NEXT_PUBLIC_SOURCEBOT_VERSION = getEnv(process.env.NEXT_PUBLIC_SOURCEBOT_VERSION, "unknown");

0 commit comments

Comments
 (0)