The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Notify Slack when the auto-patch workflow skips a release (DEV-1854) (#73114)
Nemanja Glumac92d574667f28
diff --git a/.github/workflows/release-patch.yml b/.github/workflows/release-patch.ymlindex 39e2a4cc9b8..8f1df106a10 100644--- a/.github/workflows/release-patch.yml+++ b/.github/workflows/release-patch.yml@@ -35,12 +35,16 @@ jobs:run: bun install --cwd release --frozen-lockfile && bun run --cwd release build- name: Trigger auto-patchuses: actions/github-script@v7+ env:+ SLACK_RELEASE_CHANNEL: ${{ vars.SLACK_RELEASE_CHANNEL }}+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}with:script: | # jsconst {getLatestGreenCommit,getNextPatchVersion,hasCommitBeenReleased,+ sendAutoPatchFailureMessage,} = require('${{ github.workspace }}/release/dist/index.cjs');const currentRelease = Number('${{ vars.CURRENT_VERSION }}');@@ -86,9 +90,25 @@ jobs:auto: true,}}).catch(console.error);- } else {- console.error(`No new patch version or no green commit found for v${majorVersion}`);+ return;}++ const reason = !nextPatch+ ? 'no-next-patch'+ : !releaseCommit+ ? 'no-green-commit'+ : 'already-released';++ console.error(`Auto-patch skipped for v${majorVersion}: ${reason}`);++ await sendAutoPatchFailureMessage({+ channelName: '${{ vars.SLACK_RELEASE_CHANNEL }}',+ majorVersion,+ reason,+ runId: '${{ github.run_id }}',+ owner: context.repo.owner,+ repo: context.repo.repo,+ }).catch(console.error);}if (context.eventName === 'workflow_dispatch') {diff --git a/release/src/slack.ts b/release/src/slack.tsindex aeafc37d71e..91b548331b6 100644--- a/release/src/slack.ts+++ b/release/src/slack.ts@@ -279,6 +279,46 @@ export function githubRunLink();}+export type AutoPatchSkipReason =+ | "no-next-patch"+ | "no-green-commit"+ | "already-released";++type AutoPatchSkipArgs = {+ majorVersion: number;+ reason: AutoPatchSkipReason;+ runId: string;+ owner: string;+ repo: string;+};++export function buildAutoPatchSkipMessage({+ majorVersion,+ reason,+ runId,+ owner,+ repo,+}: AutoPatchSkipArgs): string {+ const runLink = githubRunLink("workflow run", runId, owner, repo);++ const messageByReason: Record<AutoPatchSkipReason, string> = {+ "no-green-commit": `:x: Auto-patch for *v${majorVersion}* skipped: no commit found suitable for the release. ${runLink}`,+ "no-next-patch": `:x: Auto-patch for *v${majorVersion}* skipped: could not determine next patch version. ${runLink}`,+ "already-released": `:information_source: Auto-patch for *v${majorVersion}* skipped: latest green commit has already been released — nothing new to patch. ${runLink}`,+ };++ return messageByReason[reason];+}++export async function sendAutoPatchFailureMessage(+ args: AutoPatchSkipArgs & { channelName: string },+) {+ return sendSlackMessage({+ channelName: args.channelName,+ message: buildAutoPatchSkipMessage(args),+ });+}+export async function sendPreReleaseMessage({github,owner,diff --git a/release/src/slack.unit.spec.ts b/release/src/slack.unit.spec.tsnew file mode 100644index 00000000000..895adfbf3ce--- /dev/null+++ b/release/src/slack.unit.spec.ts@@ -0,0 +1,51 @@+import { buildAutoPatchSkipMessage } from "./slack";++describe("buildAutoPatchSkipMessage", () => {+ const baseArgs = {+ majorVersion: 54,+ runId: "12345",+ owner: "metabase",+ repo: "metabase",+ };++ const runLink = "<https://github.com/metabase/metabase/actions/runs/12345|workflow run>";++ it("uses a failure emoji for no-green-commit", () => {+ const message = buildAutoPatchSkipMessage({ ...baseArgs, reason: "no-green-commit" });++ expect(message).toContain(":x:");+ expect(message).toContain("v54");+ expect(message).toContain("no commit found suitable for the release");+ expect(message).toContain(runLink);+ });++ it("uses a failure emoji for no-next-patch", () => {+ const message = buildAutoPatchSkipMessage({ ...baseArgs, reason: "no-next-patch" });++ expect(message).toContain(":x:");+ expect(message).toContain("v54");+ expect(message).toContain("next patch version");+ expect(message).toContain(runLink);+ });++ it("uses an info emoji (not a failure emoji) for already-released", () => {+ const message = buildAutoPatchSkipMessage({ ...baseArgs, reason: "already-released" });++ expect(message).toContain(":information_source:");+ expect(message).not.toContain(":x:");+ expect(message).toContain("v54");+ expect(message).toContain("nothing new to patch");+ expect(message).toContain(runLink);+ });++ it("uses the provided major version in the message", () => {+ const message = buildAutoPatchSkipMessage({+ ...baseArgs,+ majorVersion: 53,+ reason: "no-green-commit",+ });++ expect(message).toContain("v53");+ expect(message).not.toContain("v54");+ });+});