Skip to content

Commit 42581eb

Browse files
committed
fix: release mechanism with Lerna
1 parent f3497c9 commit 42581eb

File tree

7 files changed

+63
-224
lines changed

7 files changed

+63
-224
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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@ jobs:
3737
LAME_SKIP_DOWNLOAD: "1"
3838
run: pnpm install --frozen-lockfile
3939

40-
- name: Lint
41-
run: pnpm run lint
42-
43-
- name: Typecheck
44-
run: pnpm run typecheck
45-
46-
- name: Unit tests
47-
run: pnpm run test:unit
48-
49-
- name: Integration tests
50-
run: pnpm run test:integration
51-
5240
- name: Determine changelog mode
5341
id: changelog
5442
run: |
@@ -72,6 +60,7 @@ jobs:
7260
SKIP_CHANGELOG: ${{ steps.changelog.outputs.skip }}
7361
run: |
7462
set -eo pipefail
63+
git checkout -B master ${{ github.event.workflow_run.head_commit.id }}
7564
pnpm run release:version > version.log 2>&1 || STATUS=$?
7665
cat version.log
7766
if [ -n "$STATUS" ]; then
@@ -88,4 +77,4 @@ jobs:
8877
if: steps.version.outputs.skip != 'true'
8978
env:
9079
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91-
run: git push --follow-tags
80+
run: git push --set-upstream origin master --follow-tags

.github/workflows/release.yml

Lines changed: 3 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,13 @@ name: Release
22

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

99
jobs:
10-
build-binaries:
11-
if: >
12-
github.event.workflow_run.conclusion == 'success' &&
13-
github.event.workflow_run.head_branch == 'master' &&
14-
startsWith(github.event.workflow_run.head_commit.message, 'chore(release)')
15-
runs-on: ubuntu-latest
16-
strategy:
17-
fail-fast: false
18-
matrix:
19-
include:
20-
- platform: linux
21-
arch: x64
22-
binary: vendor/lame/linux-x64/lame
23-
- platform: darwin
24-
arch: arm64
25-
binary: vendor/lame/darwin-arm64/lame
26-
- platform: win32
27-
arch: x64
28-
binary: vendor/lame/win32-x64/lame.exe
29-
steps:
30-
- name: Checkout
31-
uses: actions/checkout@v4
32-
with:
33-
repository: ${{ github.event.workflow_run.head_repository.full_name }}
34-
ref: ${{ github.event.workflow_run.head_commit.id }}
35-
fetch-depth: 0
36-
37-
- name: Setup pnpm
38-
uses: pnpm/action-setup@v4
39-
40-
- name: Setup Node.js
41-
uses: actions/setup-node@v4
42-
with:
43-
node-version: 20.x
44-
cache: pnpm
45-
46-
- name: Install dependencies
47-
env:
48-
LAME_SKIP_DOWNLOAD: "1"
49-
run: pnpm install --frozen-lockfile
50-
51-
- name: Download LAME binary for ${{ matrix.platform }}-${{ matrix.arch }}
52-
env:
53-
NODE_LAME_PLATFORM: ${{ matrix.platform }}
54-
NODE_LAME_ARCH: ${{ matrix.arch }}
55-
LAME_FORCE_DOWNLOAD: "1"
56-
run: node scripts/install-lame.mjs
57-
58-
- name: Package binary
59-
run: node scripts/package-lame.mjs --binary "${{ matrix.binary }}" --platform "${{ matrix.platform }}" --arch "${{ matrix.arch }}" --out-dir artifacts
60-
61-
- name: Upload artifacts
62-
uses: actions/upload-artifact@v4
63-
with:
64-
name: lame-${{ matrix.platform }}-${{ matrix.arch }}
65-
path: artifacts
66-
6710
publish:
68-
needs: build-binaries
69-
if: >
70-
github.event.workflow_run.conclusion == 'success' &&
71-
github.event.workflow_run.head_branch == 'master' &&
72-
startsWith(github.event.workflow_run.head_commit.message, 'chore(release)')
11+
if: github.event.workflow_run.conclusion == 'success'
7312
runs-on: ubuntu-latest
7413
permissions:
7514
contents: write
@@ -95,49 +34,11 @@ jobs:
9534
- name: Install dependencies
9635
run: pnpm install --frozen-lockfile
9736

98-
- name: Download artifacts
99-
uses: actions/download-artifact@v4
100-
with:
101-
path: artifacts
102-
103-
- name: Unpack binaries into vendor directory
104-
run: node scripts/unpack-lame-artifacts.mjs artifacts vendor/lame
105-
10637
- name: Build package
10738
run: pnpm run build
10839

109-
- name: Prepare release assets
110-
run: |
111-
set -eo pipefail
112-
VERSION=$(node -p "require('./package.json').version")
113-
ASSET_DIR="$PWD/release-assets"
114-
mkdir -p "$ASSET_DIR"
115-
while IFS= read -r manifest; do
116-
base=$(basename "$manifest" .json)
117-
src_dir="vendor/lame/$base"
118-
if [ ! -d "$src_dir" ]; then
119-
echo "Skipping $base - no vendor directory"
120-
continue
121-
fi
122-
tmp_dir=$(mktemp -d)
123-
cp "$src_dir"/* "$tmp_dir/"
124-
cp "$manifest" "$tmp_dir/manifest.json"
125-
(cd "$tmp_dir" && zip -qr "$ASSET_DIR/node-lame-v${VERSION}-${base}.zip" .)
126-
rm -rf "$tmp_dir"
127-
done < <(find artifacts -maxdepth 3 -name '*.json')
128-
zip -qr "$ASSET_DIR/node-lame-v${VERSION}-dist.zip" dist
129-
130-
- name: Publish release
40+
- name: Publish package
13141
env:
13242
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
13343
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
134-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13544
run: pnpm run release:publish
136-
137-
- name: Upload assets to GitHub release
138-
env:
139-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140-
run: |
141-
VERSION=$(node -p "require('./package.json').version")
142-
TAG="v${VERSION}"
143-
gh release upload "$TAG" release-assets/*.zip --clobber

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
}

scripts/unpack-lame-artifacts.mjs

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)