Skip to content
Snippets Groups Projects
Unverified Commit 8ce30f63 authored by Ryan Laurie's avatar Ryan Laurie Committed by GitHub
Browse files

Add build start slack message (#39467)

parent e3b1353b
Branches
Tags
No related merge requests found
......@@ -13,6 +13,34 @@ on:
required: true
jobs:
start-message:
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
with:
sparse-checkout: release
- name: Prepare build scripts
run: cd ${{ github.workspace }}/release && yarn && yarn build
- name: Send build start message
uses: actions/github-script@v6
env:
SLACK_RELEASE_CHANNEL: ${{ vars.SLACK_RELEASE_CHANNEL }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
script: | # js
const { sendReleaseMessage } = require('${{ github.workspace }}/release/dist/index.cjs');
await sendReleaseMessage({
stage: 'build-start',
github,
owner: context.repo.owner,
repo: context.repo.repo,
version: '${{ inputs.version }}',
runId: '${{ github.run_id }}',
releaseSha: '${{ inputs.commit }}',
}).catch(console.error);
check-version:
runs-on: ubuntu-22.04
timeout-minutes: 10
......
import { WebClient } from '@slack/web-api';
import type { Issue } from './types';
import { getGenericVersion } from "./version-helpers";
import { findMilestone } from "./github";
import type { ReleaseProps } from "./types";
const slack = new WebClient(process.env.SLACK_BOT_TOKEN);
const SLACK_CHANNEL_NAME = process.env.SLACK_RELEASE_CHANNEL ?? "bot-testing";
export function getChannelTopic(channelName: string) {
return slack.conversations.list({
......@@ -73,3 +77,93 @@ ${openIssues.map(issue => ` • <${issue.html_url}|#${issue.number} - ${issue.t
text: `${version} is scheduled for release on ${date}`,
});
}
type BuildStage =
| "build-start"
| "build-done"
| "test-start"
| "test-done"
| "publish-start"
| "publish-done";
function sendSlackMessage({ channelName = SLACK_CHANNEL_NAME, message }: { channelName?: string, message: string }) {
return slack.chat.postMessage({
channel: channelName,
text: message,
});
}
const getReleaseTitle = (version: string) =>
`:rocket: *${getGenericVersion(version)} Release* :rocket:`;
function slackLink(text: string, url: string) {
return `<${url}|${text}>`;
}
function githubRunLink(
text: string,
runId: string,
owner: string,
repo: string,
) {
return slackLink(
text,
`https://github.com/${owner}/${repo}/actions/runs/${runId}`,
);
}
export async function sendReleaseMessage({
github,
owner,
repo,
stage,
version,
runId,
releaseSha,
}: ReleaseProps & {
stage: BuildStage;
version: string;
runId: string;
releaseSha: string;
}) {
const title = getReleaseTitle(version);
const space = "\n";
let message = "";
if (stage === "build-start") {
const milestone = await findMilestone({ version, github, owner, repo });
console.log("Milestone", milestone);
const milestoneLink = milestone?.number
? slackLink(
`_:direction-sign: Milestone_`,
`https://github.com/${owner}/${repo}/milestone/${milestone.number}?closed=1`,
)
: "";
const releaseCommitLink = slackLink(
`_:merged: Release Commit_`,
`https://github.com/${owner}/${repo}/commit/${releaseSha}`,
);
const githubBuildLink = githubRunLink("_🏗️ CI Build_", runId, owner, repo);
const preReleaseMessage = [
releaseCommitLink,
milestoneLink,
githubBuildLink,
].filter(Boolean).join(" - ");
message = [
title,
preReleaseMessage,
].join(space);
}
if (message) {
await sendSlackMessage({ message });
return;
}
console.error(`No message to send for ${stage}`);
}
......@@ -36,6 +36,11 @@ export const getCanonicalVersion = (
: getOSSVersion(versionString);
};
export const getGenericVersion = (versionString: string) => {
// turn v0.88.0 into 88.0
return getOSSVersion(versionString).replace(/v0\./, "");
};
export const getVersionType = (versionString: string) => {
if (!isValidVersionString(versionString)) {
throw new Error(`Invalid version string: ${versionString}`);
......
......@@ -9,6 +9,7 @@ import {
isLatestVersion,
getBuildRequirements,
getNextVersions,
getGenericVersion,
} from "./version-helpers";
describe("version-helpers", () => {
......@@ -393,4 +394,38 @@ describe("version-helpers", () => {
expect(() => getNextVersions("v0.75-RC2")).toThrow();
});
});
describe("getGenericVersion", () => {
it("should return the generic version for a valid OSS version string", () => {
const testCases: [string, string][] = [
["v0.75.0", "75.0"],
["v0.75.1", "75.1"],
["v0.75.12", "75.12"],
["v0.79.99", "79.99"],
["v0.79.99.0", "79.99.0"],
["v0.75.0-RC2", "75.0-RC2"],
["v0.79.0-rc99", "79.0-rc99"],
];
testCases.forEach(([input, expected]) => {
expect(getGenericVersion(input)).toEqual(expected);
});
});
it("should return the generic version for a valid EE version string", () => {
const testCases: [string, string][] = [
["v1.75.0", "75.0"],
["v1.75.1", "75.1"],
["v1.75.12", "75.12"],
["v1.79.99", "79.99"],
["v1.79.99.0", "79.99.0"],
["v1.75.0-RC2", "75.0-RC2"],
["v1.79.0-rc99", "79.0-rc99"],
];
testCases.forEach(([input, expected]) => {
expect(getGenericVersion(input)).toEqual(expected);
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment