Skip to content

Commit 6146c19

Browse files
committed
fix: CI/CD canary builds bump version automatically
1 parent 36c1fee commit 6146c19

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

scripts/copy.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,26 @@ function getNextVersion(bump: typeof options['bump']) {
4343
// the package might not have been published yet
4444
}
4545

46+
if (bump) {
47+
const [_, major, minor, patch] = pkgJson.version.match(/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-.+\.\d+)?/);
48+
49+
switch (bump) {
50+
case 'major':
51+
return `${Number(major) + 1}.0.0`;
52+
case 'minor':
53+
return `${major}.${Number(minor) + 1}.0`;
54+
case 'patch':
55+
return `${major}.${minor}.${Number(patch) + 1}`;
56+
default:
57+
throw new Error(`Unknown bump type: ${bump}`);
58+
}
59+
}
60+
4661
if (options.canary) {
4762
if (versions.some((v) => v === pkgJson.version)) {
4863
// eslint-disable-next-line no-console
49-
console.error(`before-deploy: A release with version ${pkgJson.version} already exists. Please increment version accordingly.`);
50-
process.exit(1);
64+
console.warn(`Version ${pkgJson.version} already exists on npm. Bumping patch version.`);
65+
pkgJson.version = getNextVersion('patch');
5166
}
5267

5368
const preid = options.preid ?? 'alpha';
@@ -58,18 +73,6 @@ function getNextVersion(bump: typeof options['bump']) {
5873

5974
return `${pkgJson.version}-${preid}.${lastPrereleaseNumber + 1}`;
6075
}
61-
const [_, major, minor, patch] = pkgJson.version.match(/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-.+\.\d+)?/);
62-
63-
switch (bump) {
64-
case 'major':
65-
return `${Number(major) + 1}.0.0`;
66-
case 'minor':
67-
return `${major}.${Number(minor) + 1}.0`;
68-
case 'patch':
69-
return `${major}.${minor}.${Number(patch) + 1}`;
70-
default:
71-
throw new Error(`Unknown bump type: ${bump}`);
72-
}
7376
}
7477

7578
// as we publish only the dist folder, we need to copy some meta files inside (readme/license/package.json)

0 commit comments

Comments
 (0)