Skip to content

Commit 4eeb8a4

Browse files
committed
fix: release mechanism with Lerna
1 parent f3497c9 commit 4eeb8a4

File tree

6 files changed

+61
-35
lines changed

6 files changed

+61
-35
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
name: LAME install on ${{ matrix.os }}
6262
runs-on: ${{ matrix.os }}
6363
needs: quality
64+
if: github.ref_name != 'master'
6465
strategy:
6566
fail-fast: false
6667
matrix:

.github/workflows/prepare-release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
SKIP_CHANGELOG: ${{ steps.changelog.outputs.skip }}
7373
run: |
7474
set -eo pipefail
75+
git checkout -B master ${{ github.event.workflow_run.head_commit.id }}
7576
pnpm run release:version > version.log 2>&1 || STATUS=$?
7677
cat version.log
7778
if [ -n "$STATUS" ]; then
@@ -88,4 +89,4 @@ jobs:
8889
if: steps.version.outputs.skip != 'true'
8990
env:
9091
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91-
run: git push --follow-tags
92+
run: git push --set-upstream origin master --follow-tags

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Release
22

33
on:
44
workflow_run:
5-
workflows: ["CI"]
5+
workflows: ["Prepare Release"]
66
types:
77
- completed
88

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"@typescript-eslint/eslint-plugin": "~8.46.2",
8080
"@typescript-eslint/parser": "~8.46.2",
8181
"@vitest/coverage-istanbul": "~4.0.4",
82-
"conventional-changelog-cli": "^5.0.0",
82+
"conventional-changelog-cli": "~5.0.0",
8383
"conventional-changelog-conventionalcommits": "~9.1.0",
8484
"conventional-recommended-bump": "~11.2.0",
8585
"eslint": "~9.38.0",

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/release-version.mjs

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const skipChangelog = process.env.SKIP_CHANGELOG === "1";
55
const packageJson = JSON.parse(
66
readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
77
);
8+
const semverModule = await import("semver");
9+
const semver = semverModule.default ?? semverModule;
10+
const targetVersion = "2.0.0";
11+
const isBeforeTarget = semver.lt(packageJson.version, targetVersion);
812

913
const runCommand = (args) => {
1014
const result = spawnSync("pnpm", args, {
@@ -21,33 +25,39 @@ const runCommand = (args) => {
2125
};
2226

2327
if (skipChangelog) {
24-
const [{ default: conventionalRecommendedBump }, semver] = await Promise.all(
25-
[
26-
import("conventional-recommended-bump"),
27-
import("semver"),
28-
],
29-
);
28+
let releaseType = "patch";
3029

31-
const releaseType = await new Promise((resolve, reject) => {
32-
conventionalRecommendedBump(
33-
{ preset: "conventionalcommits" },
34-
(error, recommendation) => {
35-
if (error) {
36-
reject(error);
37-
return;
38-
}
30+
try {
31+
const module = await import("conventional-recommended-bump");
32+
const candidate =
33+
typeof module.default === "function"
34+
? module.default
35+
: undefined;
3936

40-
resolve(recommendation.releaseType ?? "patch");
41-
},
37+
if (candidate) {
38+
const recommendation = await candidate({
39+
preset: "conventionalcommits",
40+
});
41+
releaseType = recommendation?.releaseType ?? "patch";
42+
} else {
43+
console.warn(
44+
"[release] conventional-recommended-bump did not expose a callable default export. Defaulting to patch bump.",
45+
);
46+
}
47+
} catch (error) {
48+
console.warn(
49+
`[release] Failed to determine recommended bump (${error.message}). Defaulting to patch.`,
4250
);
43-
});
51+
}
4452

45-
const nextVersion = semver.inc(
46-
packageJson.version,
47-
releaseType ?? "patch",
48-
);
49-
if (!nextVersion) {
50-
throw new Error("Unable to determine next version for release.");
53+
let nextVersion =
54+
semver.inc(packageJson.version, releaseType) ?? targetVersion;
55+
56+
if (isBeforeTarget && semver.lt(nextVersion, targetVersion)) {
57+
console.log(
58+
`[release] Forcing version to ${targetVersion} to begin the 2.x line.`,
59+
);
60+
nextVersion = targetVersion;
5161
}
5262

5363
console.log(
@@ -60,18 +70,32 @@ if (skipChangelog) {
6070
nextVersion,
6171
"--yes",
6272
"--no-commit-hooks",
63-
"--no-changelog",
64-
"--no-conventional-commits",
73+
"--conventional-commits",
74+
"--no-push",
6575
]);
6676
} else {
6777
console.log(
6878
"[release] Using Conventional Commits to generate the changelog.",
6979
);
7080

71-
runCommand([
72-
"lerna",
73-
"version",
74-
"--yes",
75-
"--no-commit-hooks",
76-
]);
81+
if (isBeforeTarget) {
82+
console.log(
83+
`[release] Forcing version to ${targetVersion} to begin the 2.x line.`,
84+
);
85+
runCommand([
86+
"lerna",
87+
"version",
88+
targetVersion,
89+
"--yes",
90+
"--no-commit-hooks",
91+
"--conventional-commits",
92+
]);
93+
} else {
94+
runCommand([
95+
"lerna",
96+
"version",
97+
"--yes",
98+
"--no-commit-hooks",
99+
]);
100+
}
77101
}

0 commit comments

Comments
 (0)