diff --git a/.github/workflows/ghcr-publish.yml b/.github/workflows/ghcr-publish.yml index ce8c9fab..162f796f 100644 --- a/.github/workflows/ghcr-publish.yml +++ b/.github/workflows/ghcr-publish.yml @@ -73,6 +73,8 @@ jobs: cache-to: type=gha,mode=max platforms: ${{ matrix.platform }} outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + build-args: | + SOURCEBOT_VERSION=${{ github.ref_name }} - name: Export digest run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index f5223492..b491ccd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added a `SOURCEBOT_VERSION` build argument to the Docker image. ([#41](https://github.com/sourcebot-dev/sourcebot/pull/41)) +- Added the `sourcebot_version` property to all PostHog events for versioned telemetry. ([#41](https://github.com/sourcebot-dev/sourcebot/pull/41) + ## [1.0.3] - 2024-10-15 ### Fixed diff --git a/Dockerfile b/Dockerfile index 795300ea..7d06d144 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ COPY . . ENV NEXT_TELEMETRY_DISABLED=1 # @see: https://phase.dev/blog/nextjs-public-runtime-variables/ ARG NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED=BAKED_NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED +ARG NEXT_PUBLIC_SOURCEBOT_VERSION=BAKED_NEXT_PUBLIC_SOURCEBOT_VERSION RUN yarn run build # ------ Runner ------ @@ -35,6 +36,10 @@ ENV DATA_DIR=/data ENV CONFIG_PATH=$DATA_DIR/config.json ENV DATA_CACHE_DIR=$DATA_DIR/.sourcebot +ARG SOURCEBOT_VERSION=unknown +ENV SOURCEBOT_VERSION=$SOURCEBOT_VERSION +RUN echo "Sourcebot Version: $SOURCEBOT_VERSION" + ENV GITHUB_HOSTNAME=github.com ENV GITLAB_HOSTNAME=gitlab.com diff --git a/entrypoint.sh b/entrypoint.sh index fce3fb6d..9acd18d1 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,8 @@ #!/bin/sh set -e +echo -e "\e[34m[Info] Sourcebot version: $SOURCEBOT_VERSION\e[0m" + # Issue a info message about telemetry if [ ! -z "$SOURCEBOT_TELEMETRY_DISABLED" ]; then 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 curl -L -s --header "Content-Type: application/json" -d '{ "api_key": "'"$NEXT_PUBLIC_POSTHOG_KEY"'", "event": "install", - "distinct_id": "'"$(uuidgen)"'" + "distinct_id": "'"$(uuidgen)"'", + "properties": { + "sourcebot_version": "'"$SOURCEBOT_VERSION"'" + } }' https://us.i.posthog.com/capture/ > /dev/null fi fi @@ -79,9 +84,15 @@ if [ -z "$NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED" ] && [ ! -z "$SOURCEBOT_TELE export NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED="$SOURCEBOT_TELEMETRY_DISABLED" fi +# Infer NEXT_PUBLIC_SOURCEBOT_VERSION if it is not set +if [ -z "$NEXT_PUBLIC_SOURCEBOT_VERSION" ] && [ ! -z "$SOURCEBOT_VERSION" ]; then + export NEXT_PUBLIC_SOURCEBOT_VERSION="$SOURCEBOT_VERSION" +fi + find /app/public /app/.next -type f -name "*.js" | while read file; do sed -i "s|BAKED_NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED|${NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED}|g" "$file" + sed -i "s|BAKED_NEXT_PUBLIC_SOURCEBOT_VERSION|${NEXT_PUBLIC_SOURCEBOT_VERSION}|g" "$file" done exec supervisord -c /etc/supervisor/conf.d/supervisord.conf \ No newline at end of file diff --git a/src/hooks/useCaptureEvent.ts b/src/hooks/useCaptureEvent.ts index 70652afb..ad7d66db 100644 --- a/src/hooks/useCaptureEvent.ts +++ b/src/hooks/useCaptureEvent.ts @@ -3,13 +3,17 @@ import { CaptureOptions } from "posthog-js"; import posthog from "posthog-js"; import { PosthogEvent, PosthogEventMap } from "../lib/posthogEvents"; +import { NEXT_PUBLIC_SOURCEBOT_VERSION } from "@/lib/environment.client"; export function captureEvent(event: E, properties: PosthogEventMap[E], options?: CaptureOptions) { if(!options) { options = {}; } options.send_instantly = true; - posthog.capture(event, properties, options); + posthog.capture(event, { + ...properties, + sourcebot_version: NEXT_PUBLIC_SOURCEBOT_VERSION, + }, options); } /** diff --git a/src/lib/environment.client.ts b/src/lib/environment.client.ts index ba0d2904..fcb22b4b 100644 --- a/src/lib/environment.client.ts +++ b/src/lib/environment.client.ts @@ -7,3 +7,4 @@ export const NEXT_PUBLIC_POSTHOG_HOST = getEnv(process.env.NEXT_PUBLIC_POSTHOG_H export const NEXT_PUBLIC_POSTHOG_UI_HOST = getEnv(process.env.NEXT_PUBLIC_POSTHOG_UI_HOST); export const NEXT_PUBLIC_POSTHOG_ASSET_HOST = getEnv(process.env.NEXT_PUBLIC_POSTHOG_ASSET_HOST); export const NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED = getEnvBoolean(process.env.NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED, false); +export const NEXT_PUBLIC_SOURCEBOT_VERSION = getEnv(process.env.NEXT_PUBLIC_SOURCEBOT_VERSION, "unknown");