: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(ci): post weekly renovate digest to slack (#112681)
Raúl Negrón-Otero575f3abd3109
diff --git a/.github/scripts/renovate-dashboard-digest.mjs b/.github/scripts/renovate-dashboard-digest.mjsnew file mode 100644index 000000000000..aeed6db9be18--- /dev/null+++ b/.github/scripts/renovate-dashboard-digest.mjs@@ -0,0 +1,99 @@+import { readFileSync } from 'node:fs'+import { pathToFileURL } from 'node:url'++import {+ DRY_RUN,+ GITHUB_REPOSITORY,+ GITHUB_SERVER_URL,+ cell,+ editWorkflowBlock,+ postToSlack,+} from './weekly-report-common.mjs'++const ALERTS_DEVEX_CHANNEL = 'C0AS64N6DJL'+const CONFIG_PATH = '.github/renovate.json5'+const ECOSYSTEMS = { npm: 'npm', pep621: 'python', cargo: 'rust', gomod: 'go', 'github-actions': 'actions' }+const UPDATE_TYPES = ['major', 'minor', 'patch']+const COLUMNS = [...UPDATE_TYPES, 'other', 'total']++export function summarize(report) {+ const repository = Object.values(report.repositories ?? {})[0]+ const branches = new Map()+ const deprecated = new Set()+ const lookupWarnings = new Set()+ for (const [manager, packageFiles] of Object.entries(repository?.packageFiles ?? {})) {+ for (const dep of packageFiles.flatMap((packageFile) => packageFile.deps)) {+ const depKey = `${manager}:${dep.depName}`+ if (dep.deprecationMessage) {+ deprecated.add(depKey)+ }+ if (dep.warnings?.length) {+ lookupWarnings.add(depKey)+ }+ for (const update of dep.updates ?? []) {+ const branch = branches.get(update.branchName) ?? { manager, types: new Set() }+ branch.types.add(update.updateType)+ branches.set(update.branchName, branch)+ }+ }+ }+ const pending = {}+ for (const { manager, types } of branches.values()) {+ const type = UPDATE_TYPES.find((candidate) => types.has(candidate)) ?? 'other'+ pending[manager] ??= Object.fromEntries(COLUMNS.map((column) => [column, 0]))+ pending[manager][type] += 1+ pending[manager].total += 1+ }+ // Renovate exits 0 when a lookup aborts.+ if (branches.size === 0) {+ throw new Error('The Renovate report lists no pending updates, so the lookup did not complete')+ }+ return { pending, deprecated: deprecated.size, lookupWarnings: lookupWarnings.size }+}++export function buildBlocks({ pending, deprecated, lookupWarnings }, day) {+ const managers = Object.keys(pending).sort((a, b) => pending[b].total - pending[a].total)+ const totals = Object.fromEntries(+ COLUMNS.map((column) => [column, managers.reduce((sum, manager) => sum + pending[manager][column], 0)])+ )+ const row = (label, counts) => [cell(label), ...COLUMNS.map((column) => cell(counts[column].toLocaleString('en-US')))]+ const repoUrl = `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}`+ const footer = [+ `${deprecated} deprecated`,+ `${lookupWarnings} lookup warnings`,+ `<${repoUrl}/issues?q=${encodeURIComponent('is:issue is:open author:app/renovate')}|dashboard>`,+ `<https://developer.mend.io/github/${GITHUB_REPOSITORY}|job logs>`,+ `<${repoUrl}/blob/master/${CONFIG_PATH}|config>`,+ ].join(' · ')+ return [+ {+ type: 'section',+ text: { type: 'mrkdwn', text: `*Weekly Renovate, ${day}* _(pending dependency updates)_` },+ },+ {+ type: 'table',+ column_settings: [{ align: 'left' }, ...COLUMNS.map(() => ({ align: 'right' }))],+ rows: [+ [cell('ecosystem'), ...COLUMNS.map(cell)],+ ...managers.map((manager) => row(ECOSYSTEMS[manager] ?? manager, pending[manager])),+ row('all', totals),+ ],+ },+ { type: 'context', elements: [{ type: 'mrkdwn', text: footer }] },+ editWorkflowBlock(),+ ].filter(Boolean)+}++async function main() {+ const summary = summarize(JSON.parse(readFileSync(process.env.RENOVATE_REPORT_PATH, 'utf8')))+ const blocks = buildBlocks(summary, new Date().toISOString().slice(0, 10))+ if (DRY_RUN) {+ console.info(JSON.stringify(blocks, null, 2))+ return+ }+ await postToSlack(blocks, 'Weekly Renovate digest', { channel: process.env.SLACK_CHANNEL || ALERTS_DEVEX_CHANNEL })+}++if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {+ await main()+}diff --git a/.github/scripts/renovate-dashboard-digest.test.mjs b/.github/scripts/renovate-dashboard-digest.test.mjsnew file mode 100644index 000000000000..20661a33eec7--- /dev/null+++ b/.github/scripts/renovate-dashboard-digest.test.mjs@@ -0,0 +1,64 @@+import assert from 'node:assert/strict'+import { describe, it } from 'node:test'++import { summarize } from './renovate-dashboard-digest.mjs'++const update = (branchName, updateType) => ({ branchName, updateType })++const REPORT = {+ repositories: {+ local: {+ packageFiles: {+ npm: [+ {+ packageFile: 'package.json',+ deps: [+ { depName: 'widget', updates: [update('renovate/widget-5.x', 'major')] },+ {+ depName: 'gadget',+ deprecationMessage: 'use gizmo',+ updates: [update('renovate/gadget-2.x', 'minor'), update('renovate/gadget-3.x', 'major')],+ },+ { depName: 'pinned', updates: [] },+ ],+ },+ {+ packageFile: 'apps/web/package.json',+ deps: [+ { depName: 'react', updates: [update('renovate/react-monorepo', 'patch')] },+ { depName: 'react-dom', updates: [update('renovate/react-monorepo', 'minor')] },+ { depName: 'widget', updates: [update('renovate/widget-5.x', 'major')] },+ { depName: 'gadget', deprecationMessage: 'use gizmo', updates: [] },+ ],+ },+ ],+ 'github-actions': [+ {+ packageFile: '.github/workflows/build.yml',+ deps: [+ { depName: 'acme/setup', warnings: [{ message: 'Could not determine new digest' }] },+ { depName: 'acme/deploy', updates: [update('renovate/github-actions', 'digest')] },+ ],+ },+ ],+ },+ },+ },+}++describe('renovate dashboard digest', () => {+ it('counts each branch once, under its riskiest update type', () => {+ assert.deepEqual(summarize(REPORT), {+ pending: {+ npm: { major: 2, minor: 2, patch: 0, other: 0, total: 4 },+ 'github-actions': { major: 0, minor: 0, patch: 0, other: 1, total: 1 },+ },+ deprecated: 1,+ lookupWarnings: 1,+ })+ })++ it('refuses a report with no updates instead of posting an empty table', () => {+ assert.throws(() => summarize({ repositories: { local: { packageFiles: {} } } }), /did not complete/)+ })+})diff --git a/.github/workflows/renovate-dashboard-digest.yml b/.github/workflows/renovate-dashboard-digest.ymlnew file mode 100644index 000000000000..8cd1bbe574c8--- /dev/null+++ b/.github/workflows/renovate-dashboard-digest.yml@@ -0,0 +1,84 @@+name: Renovate dashboard digest++# Posts the pending Renovate updates to #alerts-devex. The lookup is read-only.++on:+ schedule:+ - cron: '50 13 * * 3' # Wednesdays 13:50 UTC+ workflow_dispatch:+ inputs:+ dry_run:+ description: 'Print the message blocks instead of posting to Slack'+ type: boolean+ default: true+ channel:+ description: 'Slack channel or user ID to post to instead of #alerts-devex'+ type: string+ default: ''++permissions:+ contents: read++jobs:+ # Renovate is third-party npm code, so the Slack token stays out of this job.+ lookup:+ runs-on: ubuntu-24.04+ timeout-minutes: 20+ # Manual dispatch is master-only so branch-controlled code can't run with the Slack token.+ if: >-+ github.repository == 'PostHog/posthog' &&+ (github.event_name != 'workflow_dispatch' || github.ref == 'refs/heads/master')+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ persist-credentials: false++ - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0+ with:+ node-version-file: .nvmrc++ - name: Look up pending updates+ env:+ GITHUB_COM_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ RENOVATE_REPORT_TYPE: file+ RENOVATE_REPORT_PATH: ${{ runner.temp }}/renovate-report.json+ LOG_LEVEL: warn+ npm_config_ignore_scripts: 'true'+ run: npx --yes [email protected] --platform=local --dry-run=lookup++ - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1+ with:+ name: renovate-report+ path: ${{ runner.temp }}/renovate-report.json+ retention-days: 7++ post:+ needs: lookup+ runs-on: ubuntu-24.04+ timeout-minutes: 5+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ persist-credentials: false+ sparse-checkout: |+ .github/scripts/renovate-dashboard-digest.mjs+ .github/scripts/weekly-report-common.mjs+ .nvmrc+ sparse-checkout-cone-mode: false++ - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0+ with:+ node-version-file: .nvmrc++ - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0+ with:+ name: renovate-report+ path: ${{ runner.temp }}++ - name: Post the digest+ env:+ RENOVATE_REPORT_PATH: ${{ runner.temp }}/renovate-report.json+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_DEVEX_BOT_TOKEN }}+ SLACK_CHANNEL: ${{ inputs.channel }}+ DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}+ run: node .github/scripts/renovate-dashboard-digest.mjs