Skip to content

Commit

Permalink
ci(publish): update release template
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Oct 18, 2024
1 parent 6b0ce8f commit a7c1272
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 38 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@vitest/coverage-v8": "^2.1.3",
"conventional-changelog-conventionalcommits": "^8.0.0",
"conventional-changelog-writer": "^8.0.0",
"conventional-recommended-bump": "^10.0.0",
"dotenv-cli": "^7.4.2",
"happy-dom": "^15.7.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/simulation-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@morpho-org/simulation-sdk",
"description": "Framework-agnostic package that defines methods to simulate interactions on Morpho (such as `Supply`, `Borrow`) and Morpho Vaults (such as `Deposit`, `Withdraw`).",
"version": "1.12.4",
"version": "2.0.0-next.4",
"author": "Morpho Association <contact@morpho.org>",
"contributors": ["Rubilmax <rmilon@gmail.com>"],
"repository": "github:morpho-org/sdks",
Expand Down
54 changes: 54 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 19 additions & 9 deletions scripts/release/bumper.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import { basename } from "node:path";
import createPreset from "conventional-changelog-conventionalcommits";
import { Bumper } from "conventional-recommended-bump";

export const { commits: commitOpts, parser, writer } = createPreset();

export const prefix = `@morpho-org/${basename(process.cwd())}-`;
export const bumper = new Bumper().tag({ prefix }).commits({ path: "." });
export const bumper = new Bumper()
.tag({ prefix })
.commits({ ...commitOpts, path: "." }, parser);

export let commits;

export const whatBump = async (_commits) => {
commits = _commits;

export const whatBump = (commits) => {
if (commits.length === 0) return;

let level = 2;

commits.forEach((commit) => {
if (commit.notes.length > 0) {
level = 0;
} else if (commit.type === "feat") {
if (level === 2) {
level = 1;
}
}
if (commit.notes.length > 0) level = 0;
else if (
level === 2 &&
(commit.type === "feat" || commit.type === "feature")
)
level = 1;
});

return { level };
Expand All @@ -31,3 +39,5 @@ if (!version) {
console.error("Cannot find version from tags");
process.exit(1);
}

export const tag = `${prefix}v${version}`;
65 changes: 37 additions & 28 deletions scripts/release/publish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { spawnSync } from "node:child_process";
import { writeChangelogString } from "conventional-changelog-writer";
import { inc } from "semver";
import { branch, bumper, prefix, version, whatBump } from "./bumper.js";
import {
branch,
bumper,
commits,
prefix,
tag,
version,
whatBump,
writer,
} from "./bumper.js";

let { releaseType } = await bumper.bump(whatBump);

Expand All @@ -14,6 +24,8 @@ if (releaseType) {
"0",
);

const newTag = `${prefix}v${newVersion}`;

console.debug(
`Version bump from ${version} to ${newVersion} on branch ${branch} (release type: ${releaseType})`,
);
Expand Down Expand Up @@ -45,32 +57,6 @@ if (releaseType) {
process.exit(1);
}

const tag = `${prefix}v${version}`;
const newTag = `${prefix}v${newVersion}`;

const notesReq = await fetch(
"https://api.github.com/repos/morpho-org/sdks/releases/generate-notes",
{
method: "POST",
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
"X-GitHub-Api-Version": "2022-11-28",
},
body: JSON.stringify({
tag_name: newTag,
target_commitish: branch,
previous_tag_name: tag,
}),
},
);

const notes = await notesReq.json();
if (!notesReq.ok) {
console.error(notes);
process.exit(1);
}

const createReq = await fetch(
"https://api.github.com/repos/morpho-org/sdks/releases",
{
Expand All @@ -81,7 +67,28 @@ if (releaseType) {
"X-GitHub-Api-Version": "2022-11-28",
},
body: JSON.stringify({
...notes,
name: newTag,
body: await writeChangelogString(
commits,
{
version: `[${newTag}](https://github.com/morpho-org/sdks/compare/${tag}...${newTag})`,
host: "https://github.com",
owner: "morpho-org",
repository: "sdks",
commit: "commit",
types: [
{ type: "feat", section: "Features" },
{ type: "fix", section: "Bug Fixes" },
{ type: "chore", hidden: true },
{ type: "docs", hidden: true },
{ type: "style", hidden: true },
{ type: "refactor", hidden: true },
{ type: "perf", hidden: true },
{ type: "test", hidden: true },
],
},
writer,
),
tag_name: newTag,
target_commitish: branch,
prerelease: branch !== "main",
Expand All @@ -95,3 +102,5 @@ if (releaseType) {
process.exit(1);
}
} else console.debug(`No version bump from ${version} on branch ${branch}`);

process.exit(0); // Sometimes hangs.

0 comments on commit a7c1272

Please sign in to comment.