:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): generate release notes from monorepo tags (#77149)
Shy Alter971cde88393f
diff --git a/.github/scripts/desktop/generate-release-notes.mjs b/.github/scripts/desktop/generate-release-notes.mjsnew file mode 100644index 000000000000..ad6608b33782--- /dev/null+++ b/.github/scripts/desktop/generate-release-notes.mjs@@ -0,0 +1,118 @@+import { execFileSync } from "node:child_process";++const REPOSITORY = "PostHog/posthog";+const DESKTOP_LABEL = "feature/desktop";+const DESKTOP_PATH = "products/desktop/";++export function selectReleaseChanges(commits, pullRequests) {+ return commits.filter((commit) => {+ if (commit.files.some((file) => file.startsWith(DESKTOP_PATH))) {+ return true;+ }+ const pullRequest = pullRequests.get(commit.pullRequestNumber);+ return pullRequest?.labels.includes(DESKTOP_LABEL) ?? false;+ });+}++export function renderReleaseNotes(previousTag, currentTag, commits, pullRequests) {+ const lines = ["## What's Changed"];+ for (const commit of selectReleaseChanges(commits, pullRequests)) {+ const pullRequest = pullRequests.get(commit.pullRequestNumber);+ if (pullRequest) {+ lines.push(`* ${pullRequest.title} by @${pullRequest.author} in ${pullRequest.url}`);+ } else {+ lines.push(`* ${commit.subject} ([commit](https://github.com/${REPOSITORY}/commit/${commit.sha}))`);+ }+ }+ lines.push(+ "",+ `**Full Changelog**: https://github.com/${REPOSITORY}/compare/${previousTag}...${currentTag}`,+ );+ return `${lines.join("\n")}\n`;+}++function git(...args) {+ return execFileSync("git", args, { encoding: "utf8" }).trim();+}++function readCommits(previousTag, currentTag) {+ const log = git("log", "--format=%H%x09%s", `${previousTag}..${currentTag}`);+ if (!log) return [];+ return log.split("\n").map((line) => {+ const tab = line.indexOf("\t");+ const sha = line.slice(0, tab);+ const subject = line.slice(tab + 1);+ const match = subject.match(/\(#(\d+)\)$/);+ const files = git("diff-tree", "--no-commit-id", "--name-only", "-r", sha)+ .split("\n")+ .filter(Boolean);+ return {+ sha,+ subject,+ files,+ pullRequestNumber: match ? Number(match[1]) : null,+ };+ });+}++async function readPullRequests(numbers) {+ const pullRequests = new Map();+ for (let index = 0; index < numbers.length; index += 50) {+ const chunk = numbers.slice(index, index + 50);+ const fields = chunk+ .map(+ (number) => `pr${number}: pullRequest(number: ${number}) {+ title url author { login } labels(first: 100) { nodes { name } }+ }`,+ )+ .join("\n");+ const response = await fetch("https://api.github.com/graphql", {+ method: "POST",+ headers: {+ Authorization: `Bearer ${process.env.GH_TOKEN}`,+ "Content-Type": "application/json",+ },+ body: JSON.stringify({ query: `query { repository(owner: "PostHog", name: "posthog") { ${fields} } }` }),+ });+ if (!response.ok) throw new Error(`GitHub GraphQL request failed: ${response.status}`);+ const payload = await response.json();+ if (payload.errors) throw new Error(`GitHub GraphQL request failed: ${JSON.stringify(payload.errors)}`);+ for (const number of chunk) {+ const pullRequest = payload.data.repository[`pr${number}`];+ if (!pullRequest) continue;+ pullRequests.set(number, {+ title: pullRequest.title,+ url: pullRequest.url,+ author: pullRequest.author?.login ?? "ghost",+ labels: pullRequest.labels.nodes.map((label) => label.name),+ });+ }+ }+ return pullRequests;+}++async function main() {+ const currentTag = process.argv[2];+ if (!currentTag) throw new Error("Usage: generate-release-notes.mjs <desktop-tag>");+ if (!process.env.GH_TOKEN) throw new Error("GH_TOKEN is required");++ const previousTag = git(+ "describe",+ "--tags",+ "--match",+ "desktop-v*",+ "--abbrev=0",+ `${currentTag}^`,+ );+ const commits = readCommits(previousTag, currentTag);+ const numbers = [...new Set(commits.map((commit) => commit.pullRequestNumber).filter(Boolean))];+ const pullRequests = await readPullRequests(numbers);+ process.stdout.write(renderReleaseNotes(previousTag, currentTag, commits, pullRequests));+}++if (import.meta.url === `file://${process.argv[1]}`) {+ main().catch((error) => {+ console.error(error.message);+ process.exit(1);+ });+}diff --git a/.github/scripts/desktop/generate-release-notes.test.mjs b/.github/scripts/desktop/generate-release-notes.test.mjsnew file mode 100644index 000000000000..855e286174db--- /dev/null+++ b/.github/scripts/desktop/generate-release-notes.test.mjs@@ -0,0 +1,30 @@+import assert from "node:assert/strict";+import { describe, it } from "node:test";+import { renderReleaseNotes, selectReleaseChanges } from "./generate-release-notes.mjs";++const commits = [+ { sha: "desktop", subject: "fix: desktop", files: ["products/desktop/app.ts"], pullRequestNumber: 1 },+ { sha: "backend", subject: "feat: backend", files: ["posthog/api.py"], pullRequestNumber: 2 },+ { sha: "other", subject: "feat: other", files: ["frontend/index.ts"], pullRequestNumber: 3 },+];+const pullRequests = new Map([+ [1, { title: "fix: desktop", author: "one", url: "https://example.test/1", labels: [] }],+ [2, { title: "feat: backend", author: "two", url: "https://example.test/2", labels: ["feature/desktop"] }],+ [3, { title: "feat: other", author: "three", url: "https://example.test/3", labels: [] }],+]);++describe("selectReleaseChanges", () => {+ it("includes desktop paths and feature/desktop labels", () => {+ assert.deepEqual(selectReleaseChanges(commits, pullRequests).map(({ sha }) => sha), ["desktop", "backend"]);+ });+});++describe("renderReleaseNotes", () => {+ it("renders only selected pull requests and the monorepo comparison", () => {+ const notes = renderReleaseNotes("desktop-v1", "desktop-v2", commits, pullRequests);+ assert.match(notes, /fix: desktop by @one/);+ assert.match(notes, /feat: backend by @two/);+ assert.doesNotMatch(notes, /feat: other/);+ assert.match(notes, /PostHog\/posthog\/compare\/desktop-v1\.\.\.desktop-v2/);+ });+});diff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.ymlindex db41cf488ef9..3d1011759609 100644--- a/.github/workflows/desktop-release.yml+++ b/.github/workflows/desktop-release.yml@@ -666,11 +666,14 @@ jobs:- name: Checkout release scriptsuses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2with:+ fetch-depth: 0+ filter: blob:nonesparse-checkout: |products/desktop/apps/code/scripts/merge-mac-manifests.mjsproducts/desktop/apps/code/scripts/generate-release-download-tables.mjsproducts/desktop/apps/code/scripts/build-releases-feed.mjsproducts/desktop/apps/code/scripts/inject-release-notes.mjs+ .github/scripts/desktop/generate-release-notes.mjssparse-checkout-cone-mode: false- name: Setup Node.js@@ -720,8 +723,8 @@ jobs:GH_TOKEN: ${{ steps.app-token.outputs.token }}APP_VERSION: ${{ steps.version.outputs.version }}run: |- gh api repos/PostHog/code/releases/generate-notes -f tag_name="v$APP_VERSION" --jq '.body' > /tmp/release-notes.md- printf '\n' >> /tmp/release-notes.md+ CURRENT_TAG="desktop-v$APP_VERSION"+ node .github/scripts/desktop/generate-release-notes.mjs "$CURRENT_TAG" > /tmp/release-notes.mdnode products/desktop/apps/code/scripts/generate-release-download-tables.mjs "$APP_VERSION" /tmp/checksums >> /tmp/release-notes.mdgh release edit "v$APP_VERSION" --repo PostHog/code --draft=false --notes-file /tmp/release-notes.md