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 the release Slack channel when an auto release fails (#85823)
Chris Vandoodewaardbe0a0f3c3bd3
diff --git a/.github/actions/notify-release-failure/action.yml b/.github/actions/notify-release-failure/action.ymlnew file mode 100644index 00000000000..2d4c08a28e7--- /dev/null+++ b/.github/actions/notify-release-failure/action.yml@@ -0,0 +1,51 @@+name: Notify release failure+description: Sends a failure or warning message to the release thread++inputs:+ title:+ description: What failed (e.g. "Publishing"). The generic version is added when a version is set.+ required: true+ version:+ description: Release version to find the release thread. Empty posts to the channel.+ required: false+ default: ""+ level:+ description: failure marks the thread as failed. warning does not block the release or change the thread reaction.+ required: false+ default: failure+ slack-channel:+ description: Slack release channel name+ required: true+ slack-bot-token:+ description: Slack bot token+ required: true++runs:+ using: composite+ steps:+ - name: Prepare release scripts+ uses: ./.github/actions/prepare-release-scripts+ - name: Send failure message+ uses: actions/github-script@v9+ env:+ TITLE: ${{ inputs.title }}+ VERSION: ${{ inputs.version }}+ LEVEL: ${{ inputs.level }}+ SLACK_RELEASE_CHANNEL: ${{ inputs.slack-channel }}+ SLACK_BOT_TOKEN: ${{ inputs.slack-bot-token }}+ with:+ script: | # js+ const { sendReleaseSlackMessage, githubRunLink, getGenericVersion } = require('${{ github.workspace }}/release/dist/index.cjs');++ const { owner, repo } = context.repo;+ const { TITLE: title, VERSION: version, LEVEL: level } = process.env;+ const label = version ? `${title} ${getGenericVersion(version)} failed` : `${title} failed`;+ const runLink = githubRunLink(label, context.runId.toString(), owner, repo);++ await sendReleaseSlackMessage({+ channelName: process.env.SLACK_RELEASE_CHANNEL,+ version: version || undefined,+ ...(level === 'warning'+ ? { emoji: 'warning', message: `${runLink}. The release is not blocked.` }+ : { emoji: 'x', message: runLink, status: 'failure' }),+ });diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.ymlindex 0cb444f2c6c..85950938866 100644--- a/.github/workflows/pre-release.yml+++ b/.github/workflows/pre-release.yml@@ -290,7 +290,6 @@ jobs:release: truetests-complete-message:- if: always()runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}needs:[@@ -317,17 +316,36 @@ jobs:script: | # jsconst { sendTestsCompleteMessage } = require('${{ github.workspace }}/release/dist/index.cjs');- const allJobsSuccessful =- '${{ needs.run-sanity-check.result }}' === 'success' &&- '${{ needs.check-uberjar-health.result }}' === 'success' &&- '${{ needs.containerize-ee.result }}' === 'success' &&- '${{ needs.containerize-oss.result }}' === 'success';-await sendTestsCompleteMessage({owner: context.repo.owner,repo: context.repo.repo,version: '${{ inputs.version }}',runId: '${{ github.run_id }}',channelName: '${{ vars.SLACK_RELEASE_CHANNEL }}',- testStatus: allJobsSuccessful ? 'success' : 'failure',}).catch(console.error);++ notify-failure:+ needs:+ - test-mode-config+ - release-artifact+ - check-uberjar-health+ - run-sanity-check+ - containerize-oss+ - containerize-ee+ - tests-complete-message+ if: ${{ always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) }}+ runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}+ timeout-minutes: 5+ steps:+ - uses: actions/checkout@v7+ with:+ sparse-checkout: |+ release+ .github+ - name: Send release failure message+ uses: ./.github/actions/notify-release-failure+ with:+ title: Pre-release tests for+ version: ${{ inputs.version }}+ slack-channel: ${{ vars.SLACK_RELEASE_CHANNEL }}+ slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}diff --git a/.github/workflows/release-auto.yml b/.github/workflows/release-auto.ymlindex bba233096b9..9d9d655823b 100644--- a/.github/workflows/release-auto.yml+++ b/.github/workflows/release-auto.yml@@ -148,6 +148,14 @@ jobs:echo "**Triggered by:** @${{ github.actor }}"} >> "$GITHUB_STEP_SUMMARY"+ - name: Send release failure message+ if: failure() || cancelled()+ uses: ./.github/actions/notify-release-failure+ with:+ title: Auto ${{ inputs.kind }} release for v${{ inputs.version }}+ slack-channel: ${{ vars.SLACK_RELEASE_CHANNEL }}+ slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}+trigger-release:name: Release ${{ needs.prepare.outputs.version }}needs: preparediff --git a/.github/workflows/release-milestone-manage.yml b/.github/workflows/release-milestone-manage.ymlindex 65ad02e9f9f..80c606caf9a 100644--- a/.github/workflows/release-milestone-manage.yml+++ b/.github/workflows/release-milestone-manage.yml@@ -27,6 +27,7 @@ jobs:manage-milestones:# Only run milestone management in https://github.com/metabase/metabase since this is the only place milestones are used.if: github.repository == 'metabase/metabase'+ continue-on-error: trueruns-on: ${{ vars.DEFAULT_RUNNER_KEY }}timeout-minutes: 15steps:@@ -63,3 +64,12 @@ jobs:repo: context.repo.repo,version,}).catch(console.error);+ - name: Send warning message+ if: failure() || cancelled()+ uses: ./.github/actions/notify-release-failure+ with:+ title: Milestone management for+ version: ${{ inputs.version }}+ level: warning+ slack-channel: ${{ vars.SLACK_RELEASE_CHANNEL }}+ slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.ymlindex 2768aa57b06..ee870a73af6 100644--- a/.github/workflows/release-tag.yml+++ b/.github/workflows/release-tag.yml@@ -346,3 +346,27 @@ jobs:aws cloudfront create-invalidation \--distribution-id ${{ vars.AWS_CLOUDFRONT_STATIC_ID }} \--paths "/version-info.json" "/version-info-ee.json"++ notify-failure:+ needs:+ - check-version+ - copy-to-s3+ - tag-docker-image+ - push-git-tags+ - update-version-info-latest+ if: ${{ always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) }}+ runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}+ timeout-minutes: 5+ steps:+ - uses: actions/checkout@v7+ with:+ sparse-checkout: |+ release+ .github+ - name: Send release failure message+ uses: ./.github/actions/notify-release-failure+ with:+ title: Setting the ${{ inputs.tag_name }} tag for+ version: ${{ inputs.version }}+ slack-channel: ${{ vars.SLACK_RELEASE_CHANNEL }}+ slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 0bbe661491b..63d06a76c27 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -94,22 +94,16 @@ jobs:env:VERSION: ${{ inputs.version }}COMMIT: ${{ inputs.commit }}- SLACK_RELEASE_CHANNEL: ${{ vars.SLACK_RELEASE_CHANNEL }}- SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}with:script: | # jsconst {checkReleaseArtifacts,buildReleaseArtifactMismatchMessage,- sendPublishFailureMessage,- slackLink,} = require('${{ github.workspace }}/release/dist/index.cjs');const { VERSION: version, COMMIT: commit } = process.env;const { owner, repo } = context.repo;- let error;- let slackError;try {const result = await checkReleaseArtifacts({ github, owner, repo, version, commit });@@ -118,24 +112,11 @@ jobs:return;}- error = buildReleaseArtifactMismatchMessage(result);- slackError = buildReleaseArtifactMismatchMessage(result, slackLink);+ core.setFailed(buildReleaseArtifactMismatchMessage(result));} catch (err) {- // e.g. a short SHA: still worth telling the release thread- error = slackError = err.message;+ core.setFailed(err.message);}- await sendPublishFailureMessage({- owner,- repo,- version,- runId: context.runId,- channelName: process.env.SLACK_RELEASE_CHANNEL,- details: slackError,- }).catch(console.error);-- core.setFailed(error);-publish-start-message:runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}needs: [check-version]@@ -476,24 +457,15 @@ jobs:--template "$TEMPLATE" \--repository "$REPOSITORY" \--publish- - name: Send Docker Hub README failure message- if: failure()- uses: actions/github-script@v9- env:- SLACK_RELEASE_CHANNEL: ${{ vars.SLACK_RELEASE_CHANNEL }}- SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}+ - name: Send warning message+ if: failure() || cancelled()+ uses: ./.github/actions/notify-release-failurewith:- script: | # js- const { sendDockerReadmeFailureMessage } = require('${{ github.workspace }}/release/dist/index.cjs');-- await sendDockerReadmeFailureMessage({- owner: context.repo.owner,- repo: context.repo.repo,- version: '${{ inputs.version }}',- runId: context.runId,- channelName: '${{ vars.SLACK_RELEASE_CHANNEL }}',- edition: '${{ matrix.edition }}',- }).catch(console.error);+ title: Updating the ${{ matrix.edition }} Docker Hub README for+ version: ${{ inputs.version }}+ level: warning+ slack-channel: ${{ vars.SLACK_RELEASE_CHANNEL }}+ slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}trigger-cloud-issues:# Only create issues in the cloud ops repository if this release happens in https://github.com/metabase/metabase.@@ -697,3 +669,36 @@ jobs:runId: '${{ github.run_id }}',channelName: '${{ vars.SLACK_RELEASE_CHANNEL }}',}).catch(console.error);++ notify-failure:+ needs:+ - check-version+ - publish-start-message+ - download-uberjar+ - upload-to-s3+ - verify-s3-download+ - containerize-oss+ - containerize-ee+ - push-tags+ - get-extra-tags+ - trigger-cloud-issues+ - trigger-ee-extra-pr+ - draft-release-notes+ - publish-version-info+ - publish-complete-message+ if: ${{ always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) }}+ runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}+ timeout-minutes: 5+ steps:+ - uses: actions/checkout@v7+ with:+ sparse-checkout: |+ release+ .github+ - name: Send release failure message+ uses: ./.github/actions/notify-release-failure+ with:+ title: Publishing+ version: ${{ inputs.version }}+ slack-channel: ${{ vars.SLACK_RELEASE_CHANNEL }}+ slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}diff --git a/.github/workflows/tag-for-release.yml b/.github/workflows/tag-for-release.ymlindex 798655a7a81..fb8e4c7717b 100644--- a/.github/workflows/tag-for-release.yml+++ b/.github/workflows/tag-for-release.yml@@ -173,6 +173,7 @@ jobs:contents: readissues: writeuses: ./.github/workflows/release-milestone-manage.yml+ secrets: inheritwith:version: ${{ inputs.version }}@@ -281,3 +282,27 @@ jobs:with:commit: ${{ inputs.commit }}version: ${{ inputs.version }}++ notify-failure:+ needs:+ - start-message+ - check-version+ - check-commit+ - tag-uberjar-for-release+ - upload-to-cloud+ if: ${{ always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) }}+ runs-on: ${{ vars.DEFAULT_RUNNER_KEY }}+ timeout-minutes: 5+ steps:+ - uses: actions/checkout@v7+ with:+ sparse-checkout: |+ release+ .github+ - name: Send release failure message+ uses: ./.github/actions/notify-release-failure+ with:+ title: Tagging+ version: ${{ inputs.version }}+ slack-channel: ${{ vars.SLACK_RELEASE_CHANNEL }}+ slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}diff --git a/release/src/release-artifacts.ts b/release/src/release-artifacts.tsindex b13b5a0e820..17ab7ddf445 100644--- a/release/src/release-artifacts.ts+++ b/release/src/release-artifacts.ts@@ -135,13 +135,10 @@ export async function checkReleaseArtifacts({return { ok: false, version, commit, missing, tagRun };}-type Link = (text: string, url: string) => string;--const plainLink: Link = (text, url) => `${text} (${url})`;+const link = (text: string, url: string) => `${text} (${url})`;export function buildReleaseArtifactMismatchMessage(check: Extract<ReleaseArtifactCheck, { ok: false }>,- link: Link = plainLink,) {const { version, commit, missing, tagRun } = check;diff --git a/release/src/release-artifacts.unit.spec.ts b/release/src/release-artifacts.unit.spec.tsindex 3331414bcf3..ee7f2b7bc5d 100644--- a/release/src/release-artifacts.unit.spec.ts+++ b/release/src/release-artifacts.unit.spec.ts@@ -187,17 +187,6 @@ describe("buildReleaseArtifactMismatchMessage", () => {);});- it("formats links with the link function it is given", () => {- const message = buildReleaseArtifactMismatchMessage(- { ...base, tagRun: { ...tagRun, commit: TAGGED } },- (text, url) => `<${url}|${text}>`,- );-- expect(message).toContain(- `<${TAG_RUN_URL}|Tag v0.65.0-beta> built commit 2540625`,- );- });-it("asks for Release 1 when there is no run for the version", () => {const message = buildReleaseArtifactMismatchMessage({...base,diff --git a/release/src/slack.ts b/release/src/slack.tsindex b9aa2e095b5..7a6248b951e 100644--- a/release/src/slack.ts+++ b/release/src/slack.ts@@ -232,6 +232,18 @@ export async function findSlackMessage({throw new Error(`Could not find channel ${channelName}`);}+ return findMessageInChannel({ channelId, text, limit });+}++async function findMessageInChannel({+ channelId,+ text,+ limit = 100,+}: {+ channelId: string;+ text: string;+ limit?: number;+}) {const response = await slack.conversations.history({channel: channelId,limit,@@ -278,10 +290,6 @@ export async function getRecentSlackMessages({return response.messages?.map((message) => message.text ?? "") ?? [];}-function getExistingSlackMessage(version: string, channelName: string) {- return findSlackMessage({ channelName, text: getReleaseTitle(version) });-}-export async function sendSlackReply({channelName,message,@@ -310,54 +318,6 @@ export async function sendSlackReply({});}-export async function addSlackReaction({- channelName,- messageId,- emoji,-}: {- channelName: string;- messageId: string;- emoji: string;-}) {- const channelId = await getSlackChannelId(channelName);- if (!channelId) {- console.error(`Could not find channel ${channelName}`);- return;- }-- return slack.reactions- .add({- channel: channelId,- name: emoji,- timestamp: messageId,- })- .catch(console.warn);-}--export async function removeSlackReaction({- channelName,- messageId,- emoji,-}: {- channelName: string;- messageId: string;- emoji: string;-}) {- const channelId = await getSlackChannelId(channelName);- if (!channelId) {- console.error(`Could not find channel ${channelName}`);- return;- }-- return slack.reactions- .remove({- channel: channelId,- name: emoji,- timestamp: messageId,- })- .catch(console.warn);-}-const getReleaseTitle = (version: string) =>`:rocket: *${getGenericVersion(version)} Release* :rocket:`;@@ -377,6 +337,61 @@ export function githubRunLink();}+export type ReleaseStatus = "failure" | "success";++export async function sendReleaseSlackMessage({+ channelName,+ version,+ emoji,+ message,+ startThread = false,+ status,+}: {+ channelName: string;+ version?: string;+ emoji?: string;+ message: string;+ startThread?: boolean;+ status?: ReleaseStatus;+}) {+ const channelId = await getSlackChannelId(channelName);+ if (!channelId) {+ throw new Error(`Could not find channel ${channelName}`);+ }++ const title = version ? getReleaseTitle(version) : null;+ const thread =+ title && !startThread+ ? await findMessageInChannel({ channelId, text: title }).catch(() => null)+ : null;+ const text = emoji ? `:${emoji}: ${message}` : message;++ const response = await slack.chat.postMessage({+ channel: channelId,+ text: startThread && title ? `${title}\n${text}` : text,+ thread_ts: thread?.id,+ });++ const ts = thread?.id || response.ts || "";++ if (status && ts) {+ if (status === "success") {+ await slack.reactions+ .remove({ channel: channelId, name: "x", timestamp: ts })+ .catch(() => {});+ }+ await slack.reactions+ .add({+ channel: channelId,+ name: status === "success" ? "very-green-check" : "x",+ timestamp: ts,+ })+ .catch(console.warn);+ }++ return { ts };+}+export type ReleaseKind = "patch" | "minor";export type AutoReleaseSkipReason =@@ -424,7 +439,7 @@ export function buildAutoReleaseSkipMessage({export async function sendAutoReleaseFailureMessage(args: AutoReleaseSkipArgs & { channelName: string },) {- return sendSlackMessage({+ return sendReleaseSlackMessage({channelName: args.channelName,message: buildAutoReleaseSkipMessage(args),});@@ -446,8 +461,6 @@ export async function sendPreReleaseMessage({channelName: string;userName: string;}) {- const title = getReleaseTitle(version);-const milestone = await findMilestone({ version, github, owner, repo });console.log("Milestone", milestone);const milestoneLink = milestone?.number@@ -464,7 +477,7 @@ export async function sendPreReleaseMessage({const githubBuildLink = githubRunLink("_🏗️ CI Build_", runId, owner, repo);- const preReleaseMessage = [+ const message = [releaseCommitLink,milestoneLink,githubBuildLink,@@ -475,42 +488,33 @@ export async function sendPreReleaseMessage({.filter(Boolean).join(" - ");- const message = `${title}\n${preReleaseMessage}`;-- await sendSlackMessage({ message, channelName });+ await sendReleaseSlackMessage({+ channelName,+ version,+ message,+ startThread: true,+ });}export async function sendTestsCompleteMessage({channelName,version,runId,- testStatus,owner,repo,}: {channelName: string;version: string;runId: number;- testStatus: "success" | "failure";owner: string;repo: string;}) {- const message =- testStatus === "success"- ? `:very-green-check: ${getGenericVersion(version)} ${githubRunLink("Pre-release Tests Passed", runId.toString(), owner, repo)}`- : `:x: ${getGenericVersion(version)} ${githubRunLink("Pre-release Tests Failed", runId.toString(), owner, repo)}`;-- const buildThread = await getExistingSlackMessage(version, channelName);-- await sendSlackReply({ channelName, message, messageId: buildThread?.id });-- if (testStatus !== "success" && buildThread?.id) {- await addSlackReaction({- channelName,- messageId: buildThread?.id,- emoji: "warning",- });- }+ await sendReleaseSlackMessage({+ channelName,+ version,+ emoji: "very-green-check",+ message: `${getGenericVersion(version)} ${githubRunLink("Pre-release Tests Passed", runId.toString(), owner, repo)}`,+ });}export async function sendPublishStartMessage({@@ -526,71 +530,19 @@ export async function sendPublishStartMessage({owner: string;repo: string;}) {- const message = `:loading: ${githubRunLink(`Publishing ${getGenericVersion(version)}`, runId.toString(), owner, repo)}`;- const buildThread = await getExistingSlackMessage(version, channelName);- await sendSlackReply({ channelName, message, messageId: buildThread?.id });-}--export async function sendPublishFailureMessage({- channelName,- version,- runId,- owner,- repo,- details,-}: {- channelName: string;- version: string;- runId: number;- owner: string;- repo: string;- details: string;-}) {- const message = `:x: ${githubRunLink(`Publishing ${getGenericVersion(version)} failed`, runId.toString(), owner, repo)}\n${details}`;-- const buildThread = await getExistingSlackMessage(version, channelName);-- if (!buildThread?.id) {- // Without the release thread, say it in the channel rather than not at all.- await sendSlackMessage({ channelName, message });- return;- }-- await sendSlackReply({ channelName, message, messageId: buildThread.id });- await addSlackReaction({+ await sendReleaseSlackMessage({channelName,- messageId: buildThread.id,- emoji: "warning",+ version,+ emoji: "loading",+ message: githubRunLink(+ `Publishing ${getGenericVersion(version)}`,+ runId.toString(),+ owner,+ repo,+ ),});}-export async function sendDockerReadmeFailureMessage({- channelName,- version,- runId,- owner,- repo,- edition,-}: {- channelName: string;- version: string;- runId: number;- owner: string;- repo: string;- edition: string;-}) {- const message = `:warning: ${githubRunLink(`Updating the ${edition} Docker Hub README for ${getGenericVersion(version)} failed`, runId.toString(), owner, repo)}. The release itself is fine.`;-- const buildThread = await getExistingSlackMessage(version, channelName);-- if (!buildThread?.id) {- await sendSlackMessage({ channelName, message });- return;- }-- await sendSlackReply({ channelName, message, messageId: buildThread.id });-}-export async function sendPublishCompleteMessage({channelName,version,@@ -604,7 +556,7 @@ export async function sendPublishCompleteMessage({owner: string;repo: string;}) {- const baseMessage = `:partydeploy: *${githubRunLink(`${getGenericVersion(version)} Release is Complete`, runId.toString(), owner, repo)}* :partydeploy:`;+ const baseMessage = `*${githubRunLink(`${getGenericVersion(version)} Release is Complete`, runId.toString(), owner, repo)}* :partydeploy:`;const fullMessage = `\n• ${slackLink("Ops Issues", `https://github.com/${owner}/metabase-ops/issues`)} - ${mentionSlackTeam("successengineers")}@@ -612,23 +564,13 @@ export async function sendPublishCompleteMessage({const isPatch = version.split(".").length > 3;- const message = `${baseMessage}${isPatch ? "" : fullMessage}`;-- const buildThread = await getExistingSlackMessage(version, channelName);- await sendSlackReply({ channelName, message, messageId: buildThread?.id });-- if (buildThread?.id) {- await removeSlackReaction({- channelName,- messageId: buildThread?.id,- emoji: "warning",- });- await addSlackReaction({- channelName,- messageId: buildThread?.id,- emoji: "very-green-check",- });- }+ await sendReleaseSlackMessage({+ channelName,+ version,+ emoji: "partydeploy",+ message: `${baseMessage}${isPatch ? "" : fullMessage}`,+ status: "success",+ });}export async function sendFlakeStatusReport({