: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
chore(tasks): post each agent release and its sandbox bump to slack (#105209)
Alessandro Pogliaghid7345c9f57ac
diff --git a/.github/workflows/cd-sandbox-base-image.yml b/.github/workflows/cd-sandbox-base-image.ymlindex 48f9ce9a649a..32026a5839eb 100644--- a/.github/workflows/cd-sandbox-base-image.yml+++ b/.github/workflows/cd-sandbox-base-image.yml@@ -319,6 +319,8 @@ jobs:id-token: write # allow issuing OIDC tokens for this workflow runcontents: read # allow at least reading the repo contents, add other permissions if necessarypackages: write # allow push to ghcr.io+ outputs:+ promoted: ${{ steps.promote.outcome }}steps:- name: Check out@@ -412,6 +414,7 @@ jobs:done- name: Promote the smoked base image to :master+ id: promoteif: github.ref == 'refs/heads/master' && vars.CD_DEPLOY_ENABLED == 'true'env:IMAGE: ghcr.io/posthog/posthog-sandbox-base@@ -454,6 +457,114 @@ jobs:build-args: |BASE_IMAGE=ghcr.io/posthog/posthog-sandbox-base:${{ github.sha }}+ # Posts in the release thread that update-sandbox-agent-version.yml cached under the pinned version.+ # It runs on a GitHub-hosted runner because Depot runners read a separate cache backend.+ # hogli-lint: not-a-required-gate -- reads the build result only to report it in Slack+ notify_agent_bump:+ needs: sandbox_base_build+ name: Post the agent bump to Slack+ if: |+ !cancelled() &&+ github.event_name == 'push' &&+ github.ref == 'refs/heads/master' &&+ vars.CD_DEPLOY_ENABLED == 'true' &&+ needs.sandbox_base_build.result != 'skipped'+ runs-on: ubuntu-24.04+ timeout-minutes: 5+ permissions:+ contents: read+ env:+ DOCKERFILE: products/tasks/backend/sandbox/images/Dockerfile.sandbox-base+ SLACK_CHANNEL: 'C0C3FBES5ST'+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ sparse-checkout: products/tasks/backend/sandbox/images/Dockerfile.sandbox-base+ sparse-checkout-cone-mode: false++ # The merge queue can land several commits in one push, so the bump is not always HEAD.+ # Compare with the commit master pointed at before the push, not with HEAD^.+ - name: Check whether this push moved the agent pin+ id: pin+ env:+ BEFORE: ${{ github.event.before }}+ run: |+ pinned=$(sed -n 's/^ARG AGENT_VERSION=//p' "$DOCKERFILE")+ echo "version=$pinned" >> "$GITHUB_OUTPUT"+ if ! git fetch --no-tags --depth=1 origin "$BEFORE" 2>/dev/null; then+ echo "::warning::Could not fetch the pre-push commit '$BEFORE', so this run posts no agent bump notice"+ echo "changed=false" >> "$GITHUB_OUTPUT"+ exit 0+ fi+ previous=$(git show "$BEFORE:$DOCKERFILE" 2>/dev/null | sed -n 's/^ARG AGENT_VERSION=//p' || true)+ if [ -n "$pinned" ] && [ "$pinned" != "$previous" ]; then+ echo "changed=true" >> "$GITHUB_OUTPUT"+ echo "Agent pin moved from '$previous' to '$pinned'"+ else+ echo "changed=false" >> "$GITHUB_OUTPUT"+ fi++ - name: Restore the release thread+ if: steps.pin.outputs.changed == 'true'+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: .sandbox-agent-slack-thread+ key: sandbox-agent-slack-${{ steps.pin.outputs.version }}++ - name: Describe the merge for Slack+ id: message+ if: steps.pin.outputs.changed == 'true'+ env:+ VERSION: ${{ steps.pin.outputs.version }}+ PROMOTED: ${{ needs.sandbox_base_build.outputs.promoted }}+ SHA: ${{ github.sha }}+ COMMIT_URL: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}+ RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}+ run: |+ ts=""+ if [ -f .sandbox-agent-slack-thread ]; then ts=$(cat .sandbox-agent-slack-thread); fi+ commit="<${COMMIT_URL}|${SHA:0:7}>"+ if [ "$PROMOTED" = "success" ]; then+ text=":rocket: Merged in ${commit}. \`posthog-sandbox-base:master\` now runs @posthog/agent ${VERSION}."+ else+ text=":red_circle: The master image build for ${commit} failed, so \`posthog-sandbox-base:master\` still runs the previous agent. <${RUN_URL}|View run>"+ fi+ if [ -z "$ts" ]; then+ text="*@posthog/agent ${VERSION}*: ${text}"+ fi+ {+ echo "ts=$ts"+ echo "text=$text"+ } >> "$GITHUB_OUTPUT"++ - name: Post the merge in the release thread+ if: steps.message.outputs.text != '' && steps.message.outputs.ts != ''+ continue-on-error: true+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1+ with:+ method: chat.postMessage+ token: ${{ secrets.SLACK_BOT_TOKEN }}+ errors: true+ payload: |+ channel: "${{ env.SLACK_CHANNEL }}"+ thread_ts: "${{ steps.message.outputs.ts }}"+ unfurl_links: false+ text: "${{ steps.message.outputs.text }}"++ # A hand-edited pin has no cached thread, so the merge post starts one.+ - name: Post the merge as a new thread+ if: steps.message.outputs.text != '' && steps.message.outputs.ts == ''+ continue-on-error: true+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1+ with:+ method: chat.postMessage+ token: ${{ secrets.SLACK_BOT_TOKEN }}+ errors: true+ payload: |+ channel: "${{ env.SLACK_CHANNEL }}"+ unfurl_links: false+ text: "${{ steps.message.outputs.text }}"+# Single required status check for branch protection. Add future sandbox# image jobs to `needs` here rather than reconfiguring GitHub.# NOT registered as required yet: the trigger-level pull_request pathsdiff --git a/.github/workflows/desktop-agent-release.yml b/.github/workflows/desktop-agent-release.ymlindex c93d039e97c7..2fdc8814ae1a 100644--- a/.github/workflows/desktop-agent-release.yml+++ b/.github/workflows/desktop-agent-release.yml@@ -10,6 +10,7 @@ concurrency:cancel-in-progress: falseenv:+ SLACK_CHANNEL: 'C0C3FBES5ST'# npm's audit blocks the pnpm bootstrap. See .github/actions/pnpm-install for why.NPM_CONFIG_AUDIT: 'false'NPM_CONFIG_FUND: 'false'@@ -72,9 +73,84 @@ jobs:env:NPM_CONFIG_PROVENANCE: true+ # hogli-lint: not-a-required-gate -- reads the release result only to report it in Slack+ notify-release:+ name: Post the release to Slack+ needs: release+ if: ${{ !cancelled() }}+ runs-on: ubuntu-24.04+ timeout-minutes: 5+ permissions:+ actions: read+ outputs:+ thread_ts: ${{ steps.slack.outputs.ts }}+ steps:+ - name: Describe the release+ id: meta+ env:+ GH_TOKEN: ${{ github.token }}+ REPO: ${{ github.repository }}+ RUN_ID: ${{ github.run_id }}+ RESULT: ${{ needs.release.result }}+ TAG: ${{ github.ref_name }}+ SHA: ${{ github.sha }}+ run: |+ started=$(gh api "repos/${REPO}/actions/runs/${RUN_ID}" --jq .run_started_at 2>/dev/null || true)+ if [ -n "$started" ]; then+ elapsed=$(( $(date +%s) - $(date -d "$started" +%s) ))+ duration="$((elapsed / 60))m $((elapsed % 60))s"+ else+ duration="Unknown"+ fi+ if [ "$RESULT" = "success" ]; then+ emoji=":white_check_mark:"+ status="Published to npm"+ else+ emoji=":red_circle:"+ status="Release ${RESULT}"+ fi+ {+ echo "version=${TAG#agent-v}"+ echo "emoji=$emoji"+ echo "status=$status"+ echo "duration=$duration"+ echo "commit=${SHA:0:7} (${TAG})"+ } >> "$GITHUB_OUTPUT"++ - name: Post to Slack+ id: slack+ # Slack is a courtesy: a failed post must not stop the pin bump below.+ continue-on-error: true+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1+ with:+ method: chat.postMessage+ token: ${{ secrets.SLACK_BOT_TOKEN }}+ errors: true+ payload: |+ channel: "${{ env.SLACK_CHANNEL }}"+ text: "${{ steps.meta.outputs.emoji }} @posthog/agent ${{ steps.meta.outputs.version }}: ${{ steps.meta.outputs.status }}"+ unfurl_links: false+ blocks:+ - type: "section"+ text:+ type: "mrkdwn"+ text: "${{ steps.meta.outputs.emoji }} *<https://www.npmjs.com/package/@posthog/agent/v/${{ steps.meta.outputs.version }}|@posthog/agent ${{ steps.meta.outputs.version }}>*"+ - type: "section"+ fields:+ - type: "mrkdwn"+ text: "*Status*\n${{ steps.meta.outputs.status }}"+ - type: "mrkdwn"+ text: "*Commit*\n`${{ steps.meta.outputs.commit }}`"+ - type: "mrkdwn"+ text: "*Duration*\n${{ steps.meta.outputs.duration }}"+ - type: "mrkdwn"+ text: "*Run*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Desktop Agent Release #${{ github.run_number }}>"+bump-sandbox-agent-pin:name: Open a PR bumping the sandbox agent pin- needs: release+ needs: [release, notify-release]+ # notify-release runs on !cancelled(), so this job restates the release gate it used to inherit.+ if: ${{ !cancelled() && needs.release.result == 'success' }}runs-on: ubuntu-24.04timeout-minutes: 5permissions:@@ -85,9 +161,11 @@ jobs:env:GH_TOKEN: ${{ github.token }}AGENT_VERSION: ${{ needs.release.outputs.version }}+ SLACK_THREAD_TS: ${{ needs.notify-release.outputs.thread_ts }}run: |echo "Dispatching sandbox agent pin bump to $AGENT_VERSION"gh workflow run update-sandbox-agent-version.yml \--repo PostHog/posthog \--ref master \- -f version="$AGENT_VERSION"+ -f version="$AGENT_VERSION" \+ -f slack_thread_ts="$SLACK_THREAD_TS"diff --git a/.github/workflows/update-sandbox-agent-version.yml b/.github/workflows/update-sandbox-agent-version.ymlindex 9853de880f70..25e278554bd7 100644--- a/.github/workflows/update-sandbox-agent-version.yml+++ b/.github/workflows/update-sandbox-agent-version.yml@@ -9,6 +9,10 @@ on:description: 'Agent version to pin. Defaults to the npm "latest" dist-tag.'required: falsetype: string+ slack_thread_ts:+ description: 'Slack thread of the release post to reply in. The release workflow sets it.'+ required: false+ type: stringpermissions:contents: read@@ -25,6 +29,7 @@ jobs:env:DOCKERFILE: products/tasks/backend/sandbox/images/Dockerfile.sandbox-baseBRANCH_PREFIX: chore/bump-sandbox-agent-version-+ SLACK_CHANNEL: 'C0C3FBES5ST'AGENT_PATHS: products/desktop/packages/agent products/desktop/packages/enricher products/desktop/packages/git products/desktop/packages/harness products/desktop/packages/sharedsteps:@@ -128,6 +133,8 @@ jobs:{echo "action=$action"echo "stale_prs=${stale_prs# }"+ echo "current_pr=$current_pr"+ echo "declined_by=${declined_by:-}"} >> "$GITHUB_OUTPUT"- name: Wait for npm to serve the version@@ -282,6 +289,57 @@ jobs:--label "automated" --label "dependencies" --label "skip-agent-review")echo "Created $pr_url"echo "number=${pr_url##*/}" >> "$GITHUB_OUTPUT"+ echo "url=$pr_url" >> "$GITHUB_OUTPUT"++ - name: Post the bump PR in the release thread+ id: slack-opened-reply+ if: steps.state.outputs.action == 'bump' && inputs.slack_thread_ts != ''+ continue-on-error: true+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1+ with:+ method: chat.postMessage+ token: ${{ secrets.SLACK_BOT_TOKEN }}+ errors: true+ payload: |+ channel: "${{ env.SLACK_CHANNEL }}"+ thread_ts: "${{ inputs.slack_thread_ts }}"+ unfurl_links: false+ text: ":twisted_rightwards_arrows: Sandbox bump PR <${{ steps.pr.outputs.url }}|#${{ steps.pr.outputs.number }}> opened: `${{ steps.resolve.outputs.pinned }}` to `${{ steps.resolve.outputs.latest }}`. It merges on its own once the image smoke passes."++ # A nightly or manual run has no release thread, so the PR post starts one.+ - name: Post the bump PR as a new thread+ id: slack-opened-parent+ if: steps.state.outputs.action == 'bump' && inputs.slack_thread_ts == ''+ continue-on-error: true+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1+ with:+ method: chat.postMessage+ token: ${{ secrets.SLACK_BOT_TOKEN }}+ errors: true+ payload: |+ channel: "${{ env.SLACK_CHANNEL }}"+ unfurl_links: false+ text: ":twisted_rightwards_arrows: *@posthog/agent ${{ steps.resolve.outputs.latest }}*: sandbox bump PR <${{ steps.pr.outputs.url }}|#${{ steps.pr.outputs.number }}> opened, from `${{ steps.resolve.outputs.pinned }}`. It merges on its own once the image smoke passes."++ - name: Resolve the Slack thread+ id: thread+ if: ${{ !cancelled() }}+ env:+ INPUT_TS: ${{ inputs.slack_thread_ts }}+ PARENT_TS: ${{ steps.slack-opened-parent.outputs.ts }}+ run: |+ ts="${INPUT_TS:-$PARENT_TS}"+ echo "ts=$ts" >> "$GITHUB_OUTPUT"+ printf '%s' "$ts" > .sandbox-agent-slack-thread++ # cd-sandbox-base-image.yml restores this on the merge commit to post that the version is live.+ - name: Cache the Slack thread for the merge notice+ if: github.ref == 'refs/heads/master' && steps.state.outputs.action == 'bump' && steps.thread.outputs.ts != ''+ continue-on-error: true+ uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: .sandbox-agent-slack-thread+ key: sandbox-agent-slack-${{ steps.resolve.outputs.latest }}- name: Wait for the image smoke on the bump commitid: smoke@@ -314,6 +372,7 @@ jobs:permission-pull-requests: write- name: Approve and enqueue the bump+ id: enqueueif: steps.state.outputs.action == 'bump'env:GH_TOKEN: ${{ steps.releaser-token.outputs.token }}@@ -331,3 +390,61 @@ jobs:-f commit_id="$SHA" \-f body="Automated approval: the sandbox image built from this commit passed the agent smoke on both architectures." >/dev/nullgh pr comment "$PR" --body '/trunk merge'++ - name: Describe the outcome for Slack+ id: outcome+ if: ${{ !cancelled() && steps.thread.outputs.ts != '' }}+ env:+ ACTION: ${{ steps.state.outputs.action }}+ ENQUEUE: ${{ steps.enqueue.outcome }}+ SMOKE: ${{ steps.smoke.outputs.conclusion }}+ PR_URL: ${{ steps.pr.outputs.url }}+ PR_NUMBER: ${{ steps.pr.outputs.number }}+ LATEST: ${{ steps.resolve.outputs.latest }}+ PINNED: ${{ steps.resolve.outputs.pinned }}+ CURRENT_PR: ${{ steps.state.outputs.current_pr }}+ DECLINED_BY: ${{ steps.state.outputs.declined_by }}+ RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}+ REPO_URL: ${{ github.server_url }}/${{ github.repository }}+ run: |+ pr="<${PR_URL}|#${PR_NUMBER}>"+ case "$ACTION" in+ bump)+ if [ "$ENQUEUE" = "success" ]; then+ text=":white_check_mark: The image built from ${pr} passed the smoke on amd64 and arm64. Approved and added to the merge queue."+ elif [ -n "$SMOKE" ] && [ "$SMOKE" != "success" ]; then+ text=":red_circle: Sandbox Base Image Pass concluded \`${SMOKE}\` on ${pr}, so it waits for a person. <${RUN_URL}|View run>"+ elif [ -n "$PR_NUMBER" ]; then+ text=":red_circle: The bump run failed before ${pr} reached the merge queue. <${RUN_URL}|View run>"+ else+ text=":red_circle: The bump run failed before it opened a PR. <${RUN_URL}|View run>"+ fi+ ;;+ noop)+ text=":information_source: The sandbox pin is already at \`${LATEST}\`, so no bump PR was opened."+ ;;+ declined)+ text=":no_entry_sign: ${DECLINED_BY} closed the bump PR for \`${LATEST}\` without merging, so the sandbox pin stays at \`${PINNED}\`."+ ;;+ current)+ text=":information_source: <${REPO_URL}/pull/${CURRENT_PR}|#${CURRENT_PR}> already proposes \`${LATEST}\`."+ ;;+ *)+ text=":red_circle: The bump run failed before it opened a PR. <${RUN_URL}|View run>"+ ;;+ esac+ echo "text=$text" >> "$GITHUB_OUTPUT"++ - name: Post the outcome in the Slack thread+ if: ${{ !cancelled() && steps.outcome.outputs.text != '' }}+ continue-on-error: true+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1+ with:+ method: chat.postMessage+ token: ${{ secrets.SLACK_BOT_TOKEN }}+ errors: true+ payload: |+ channel: "${{ env.SLACK_CHANNEL }}"+ thread_ts: "${{ steps.thread.outputs.ts }}"+ unfurl_links: false+ text: "${{ steps.outcome.outputs.text }}"