Skip to content

Commit

Permalink
ci: fix post-changelog script
Browse files Browse the repository at this point in the history
- read release commit diff instead of using `conventional-changelog`
- same approach as in frontend/core

chore: remove publish.mjs script

Replaced with GH action publish workflow
  • Loading branch information
mvidalgarcia committed Sep 22, 2023
1 parent bed85f4 commit 7b3d06d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 440 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@kiwicom/browserslist-config": "^4.0.0",
"@lerna/project": "^5.2.0",
"@octokit/rest": "^19.0.5",
"@size-limit/file": "^8.0.0",
"@size-limit/webpack": "^8.0.0",
Expand All @@ -82,7 +81,6 @@
"@typescript-eslint/parser": "^5.57.1",
"babel-jest": "^28.1.3",
"browserslist": "^4.16.6",
"conventional-changelog": "^3.1.24",
"cpy-cli": "^3.1.1",
"cross-env": "^7.0.2",
"dedent": "^0.7.0",
Expand Down
10 changes: 0 additions & 10 deletions scripts/helpers.mjs

This file was deleted.

71 changes: 21 additions & 50 deletions scripts/post-changelog.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { $, fetch, argv } from "zx";
import dotenv from "dotenv-safe";
import conventionalChangelog from "conventional-changelog";
import { getPackages } from "@lerna/project";
import slackify from "slackify-markdown";
import slackifyMarkdown from "slackify-markdown";
import { simpleGit } from "simple-git";
import gitDiffParser from "gitdiff-parser";

/* eslint-disable no-console */

const CHANNEL = `orbit-react`;
const COLOR_CORE = `#00A58E`;
const PACKAGES = ["orbit-components", "orbit-tailwind-preset"];
const PACKAGE_PREFIX = "@kiwicom";
const CHANNEL = "orbit-react";
const COLOR_CORE = "#00A58E";
const PACKAGES = ["orbit-components", "orbit-tailwind-preset", "orbit-design-tokens"];
const SLACK_API_POST_RELEASE_MESSAGE = "https://slack.com/api/chat.postMessage";

function getTitle(pkg) {
Expand All @@ -29,8 +26,9 @@ const apiRequest = async ({ method = "GET", url, body }) =>
},
});

function adjustChangelog(str) {
function format(str, package_, prefix = "@kiwicom") {
const output = str
.replace(/^#+ /, `# _${prefix}/${package_}_ `)
.replace("Bug Fixes", "Bug Fixes 🐛")
.replace("Features", "Features 🆕")
.replace("BREAKING CHANGES", "BREAKING CHANGES 🚨")
Expand All @@ -39,6 +37,16 @@ function adjustChangelog(str) {
return output;
}

function getChangelogFromDiff(files) {
// Only one file as we're only looking at the changelog
const [changelogFile] = files;
const changelog = changelogFile.hunks
.flatMap(hunk => hunk.changes.filter(({ isInsert }) => isInsert).map(({ content }) => content))
.join("\n")
.trim();
return changelog;
}

function getDiff(tag, path) {
return simpleGit().show([tag, path]);
}
Expand Down Expand Up @@ -88,48 +96,8 @@ async function configureSlackToken() {
}
}

async function getChangelogMessage(package_) {
const packages = await getPackages();

return new Promise((resolve, reject) => {
let changelog = "";
const pkg = packages.find(p => p.name === package_);

const stream = conventionalChangelog(
{
lernaPackage: pkg.name,
preset: "angular",
},
{
host: "https://github.com",
title: package_,
owner: "kiwicom",
repository: "orbit",
linkCompare: true,
version: pkg.version,
},
{ path: pkg.location },
);

stream.on("data", data => {
changelog += data.toString();
});

stream.on("end", () => {
changelog = slackify(adjustChangelog(changelog));
resolve(changelog);
});

stream.on("error", err => {
reject(err);
});
});
}

async function publishChangelog(package_) {
try {
const changelog = await getChangelogMessage(`${PACKAGE_PREFIX}/${package_}`);

await simpleGit().fetch(["origin", "master", "--tags"]);
const tags = await simpleGit().tags();
const diff = await getDiff(tags.latest ?? "", changelogPath(package_));
Expand All @@ -138,12 +106,15 @@ async function publishChangelog(package_) {
console.log(`No changes in ${package_}`);
return;
}
const changelog = getChangelogFromDiff(files);
const formattedChangelog = format(changelog, package_);
const slackifiedChangelog = slackifyMarkdown(formattedChangelog);

if (argv.dry) {
console.info(changelog);
console.info(formattedChangelog);
} else {
await configureSlackToken();
await postSlackNotification(changelog, package_);
await postSlackNotification(slackifiedChangelog, package_);
}
} catch (err) {
console.error(err);
Expand Down
175 changes: 0 additions & 175 deletions scripts/publish.mjs

This file was deleted.

Loading

0 comments on commit 7b3d06d

Please sign in to comment.