Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

turn off slack messages in engineering-ci and create Linear issues instead (#80533)

Chris Vandoodewaard29afd6c0ade8
diff --git a/.github/scripts/find-linear-issue.js b/.github/scripts/find-linear-issue.js
deleted file mode 100644
index 87b3cd5ab63..00000000000
--- a/.github/scripts/find-linear-issue.js
+++ /dev/null
@@ -1,40 +0,0 @@
-async function findLinearIssue({ githubIssueUrl, linearApiKey }) {
- const response = await fetch("https://api.linear.app/graphql", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: linearApiKey,
- },
- body: JSON.stringify({
- query: `
- query {
- attachmentsForURL(url: "${githubIssueUrl}") {
- nodes {
- issue { identifier }
- }
- }
- }
- `,
- }),
- });
-
- const data = await response.json();
-
- if (!response.ok) {
- return { success: false, message: `Linear API error: ${response.status}` };
- }
-
- if (!data.data?.attachmentsForURL?.nodes?.length) {
- return {
- success: false,
- message: `No Linear issue linked to ${githubIssueUrl}`,
- };
- }
-
- return {
- success: true,
- issue: data.data.attachmentsForURL.nodes[0].issue.identifier,
- };
-}
-
-module.exports = { findLinearIssue };
diff --git a/.github/scripts/linear-issues.js b/.github/scripts/linear-issues.js
new file mode 100644
index 00000000000..8fec8aba996
--- /dev/null
+++ b/.github/scripts/linear-issues.js
@@ -0,0 +1,109 @@
+async function findLinearIssue({ githubIssueUrl, linearApiKey }) {
+ const response = await fetch("https://api.linear.app/graphql", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: linearApiKey,
+ },
+ body: JSON.stringify({
+ query: `
+ query {
+ attachmentsForURL(url: "${githubIssueUrl}") {
+ nodes {
+ issue { identifier }
+ }
+ }
+ }
+ `,
+ }),
+ });
+
+ const data = await response.json();
+
+ if (!response.ok) {
+ return { success: false, message: `Linear API error: ${response.status}` };
+ }
+
+ if (!data.data?.attachmentsForURL?.nodes?.length) {
+ return {
+ success: false,
+ message: `No Linear issue linked to ${githubIssueUrl}`,
+ };
+ }
+
+ return {
+ success: true,
+ issue: data.data.attachmentsForURL.nodes[0].issue.identifier,
+ };
+}
+
+async function createLinearIssue({
+ teamId,
+ title,
+ description,
+ projectId,
+ labelIds,
+ linearApiKey,
+}) {
+ const response = await fetch("https://api.linear.app/graphql", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: linearApiKey,
+ },
+ body: JSON.stringify({
+ query: `
+ mutation CreateIssue($input: IssueCreateInput!) {
+ issueCreate(input: $input) {
+ success
+ issue {
+ id
+ identifier
+ title
+ url
+ }
+ }
+ }
+ `,
+ variables: {
+ input: {
+ teamId,
+ title,
+ ...(description ? { description } : {}),
+ ...(projectId ? { projectId } : {}),
+ ...(labelIds?.length ? { labelIds } : {}),
+ },
+ },
+ }),
+ });
+
+ if (!response.ok) {
+ return { success: false, message: `Linear API error: ${response.status}` };
+ }
+
+ const data = await response.json();
+
+ if (data.errors?.length) {
+ return {
+ success: false,
+ message: `Linear API error: ${data.errors.map((e) => e.message).join(", ")}`,
+ };
+ }
+
+ if (!data.data?.issueCreate?.success) {
+ return {
+ success: false,
+ message: `Failed to create Linear issue "${title}"`,
+ };
+ }
+
+ return {
+ success: true,
+ issue: data.data.issueCreate.issue,
+ };
+}
+
+module.exports = {
+ findLinearIssue,
+ createLinearIssue,
+};
diff --git a/.github/workflows/notify.issue-labeled.yml b/.github/workflows/notify.issue-labeled.yml
index 012b6c293da..9171b50f8b8 100644
--- a/.github/workflows/notify.issue-labeled.yml
+++ b/.github/workflows/notify.issue-labeled.yml
@@ -91,7 +91,7 @@ jobs:
LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
with:
script: |
- const { findLinearIssue } = require('./.github/scripts/find-linear-issue.js');
+ const { findLinearIssue } = require('./.github/scripts/linear-issues.js');
const title = context.payload.issue.title;
const issueUrl = context.payload.issue.html_url;
diff --git a/.github/workflows/rerun-workflows.yml b/.github/workflows/rerun-workflows.yml
index 7def4e0da56..9833b5e242b 100644
--- a/.github/workflows/rerun-workflows.yml
+++ b/.github/workflows/rerun-workflows.yml
@@ -15,7 +15,6 @@ jobs:
env:
BRANCH_NAME: ${{ github.event.workflow_run.head_branch }}
AUTHOR_NAME: ${{ github.event.workflow_run.head_commit.author.name }}
- AUTHOR_LOGIN: ${{ github.event.workflow_run.head_commit.author.username }}
steps:
- name: Generate job summary
run: |
@@ -30,15 +29,11 @@ jobs:
with:
sparse-checkout: |
.github
- release
-
- - name: Prepare release scripts
- uses: ./.github/actions/prepare-release-scripts
- name: Trigger a re-run
uses: actions/github-script@v9
env:
- SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
with:
script: | # js
const MAX_ATTEMPTS = 1;
@@ -46,9 +41,10 @@ jobs:
const FAILED_RUN_URL = "${{ github.event.workflow_run.html_url }}";
const FAILED_RUN_NAME = "${{ github.event.workflow_run.name }}";
const BREAKING_COMMIT = "${{ github.event.workflow_run.head_sha }}";
- let AUTHOR = process.env.AUTHOR_NAME;
- let AUTHOR_LOGIN = process.env.AUTHOR_LOGIN;
+ const AUTHOR = process.env.AUTHOR_NAME;
const BRANCH = process.env.BRANCH_NAME;
+ const LINEAR_TEAM_ID = '2e3af6a2-9b19-4abd-b72c-4b5665054861'; // DevEx team
+ const CI_TRIAGE_LABEL_ID = '1af2175c-8ffa-4765-9bbd-5b6166def8a0'; // 'CI Triage' label
if (ATTEMPT <= MAX_ATTEMPTS) {
try {
@@ -65,91 +61,50 @@ jobs:
}
}
} else if (!BRANCH.includes('backport-')) {
- // notify slack of repeated failure
- const { mentionUserByGithubLogin, sendSlackMessage } = require('${{ github.workspace }}/release/dist/index.cjs');
+ const { createLinearIssue } = require('./.github/scripts/linear-issues.js');
// find out which jobs failed
const { owner, repo } = context.repo;
- const jobInfo = await github.rest.actions.listJobsForWorkflowRun({
+ const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, {
owner,
repo,
run_id: ${{ github.event.workflow_run.id }},
per_page: 100,
});
- const failedJobs = jobInfo.data.jobs
+ // the `*-tests-result` jobs only aggregate the jobs they depend on, so an
+ // issue for one of them would just duplicate the real failures
+ const failedJobs = jobs
.filter(job => job.status === "completed" && job.conclusion === "failure" && !job.name.includes("-tests-result"));
- // don't bother slack if only the flaky job failed
- if (failedJobs.every(job => job.name.toLowerCase().includes("flaky"))) {
- return;
- }
+ const shortSha = BREAKING_COMMIT.slice(0, 7);
+ const commitUrl = `https://github.com/${owner}/${repo}/commit/${BREAKING_COMMIT}`;
- // the workflow_run payload omits the github login when the commit
- // author isn't matched to a github account, so look it up from
- // the commit itself
- if (!AUTHOR_LOGIN) {
- try {
- const { data: commit } = await github.rest.repos.getCommit({
- owner,
- repo,
- ref: BREAKING_COMMIT,
- });
+ // one issue per failing job, so they can be triaged and assigned separately
+ for (const job of failedJobs) {
+ const description = [
+ `\`${job.name}\` is failing on \`${owner}/${repo}@${BRANCH}\` after ${ATTEMPT} attempts.`,
+ ``,
+ `- **Author:** ${AUTHOR}`,
+ `- **Commit:** [\`${shortSha}\`](${commitUrl})`,
+ `- **Failed job:** [${job.name}](${job.html_url})`,
+ `- **Failed run:** [${FAILED_RUN_NAME}](${FAILED_RUN_URL})`,
+ ].join('\n');
- AUTHOR_LOGIN = commit.author?.login ?? '';
- AUTHOR = AUTHOR || commit.commit?.author?.name || '';
- } catch (error) {
- console.log(`Could not look up the author of ${BREAKING_COMMIT}: ${error.message}`);
+ // never fail this job over Linear — it would pollute our CI stats
+ const result = await createLinearIssue({
+ teamId: LINEAR_TEAM_ID,
+ labelIds: [CI_TRIAGE_LABEL_ID],
+ title: `CI failure on ${BRANCH}: ${job.name} (${shortSha})`,
+ description,
+ linearApiKey: process.env.LINEAR_API_KEY,
+ }).catch(error => ({ success: false, message: error.message }));
+
+ if (result.success) {
+ core.info(`Created Linear issue ${result.issue.identifier}: ${result.issue.url}`);
+ } else {
+ core.warning(`Could not create a Linear issue for ${job.name}: ${result.message}`);
}
}
-
- const failedJobsList = failedJobs.map(job => ({
- "type": "rich_text_section",
- "elements": [
- {
- "type": "link",
- "text": job.name,
- "url": job.html_url,
- }
- ]
- }));
-
- await sendSlackMessage({
- channelName: 'engineering-ci',
- message: 'Failing tests',
- blocks: [
- {
- "type": "header",
- "text": {
- "type": "plain_text",
- "text": `:warning: CI is failing on ${repo}@${BRANCH}`,
- "emoji": true,
- }
- },
- ],
- attachments: [{
- color: BRANCH === 'master' ? '#f85149' : "#ffce33",
- blocks: [
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": `Commit <https://github.com/metabase/metabase/commit/${BREAKING_COMMIT}|${BREAKING_COMMIT.slice(0,7)}> by ${AUTHOR} (${mentionUserByGithubLogin(AUTHOR_LOGIN)}) has failing <${FAILED_RUN_URL}|${FAILED_RUN_NAME}> tests on <https://github.com/${owner}/${repo}/commits/${BRANCH}|\`${BRANCH}\`>`
- },
- },
- {
- "type": "rich_text",
- "block_id": "block1",
- "elements": [
- {
- "type": "rich_text_list",
- "style": "bullet",
- "elements": failedJobsList,
- },
- ],
- }
- ]
- }]
- });
}