commit-and-tag-version 12.6.0 → 12.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yaml +1 -1
- package/.github/workflows/release-please.yml +1 -1
- package/CHANGELOG.md +20 -0
- package/README.md +14 -0
- package/command.js +6 -0
- package/index.js +1 -0
- package/lib/lifecycles/bump.js +154 -0
- package/lib/updaters/types/gradle.js +1 -1
- package/lib/updaters/types/maven.js +12 -13
- package/package.json +6 -7
- package/test/core.spec.js +94 -0
- package/test/git.integration-test.js +39 -0
- package/test/mocks/build-6.4.0-snapshot.gradle.kts +14 -0
- package/test/mocks/jest-mocks.js +18 -0
- package/test/mocks/pom-6.4.0-crlf.xml +1 -4
- package/test/mocks/pom-6.4.0-lf.xml +1 -4
|
@@ -23,7 +23,7 @@ jobs:
|
|
|
23
23
|
OS: ${{ matrix.os }}
|
|
24
24
|
NODE_VERSION: ${{ matrix.node }}
|
|
25
25
|
steps:
|
|
26
|
-
- uses: actions/checkout@
|
|
26
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
|
|
27
27
|
- run: git fetch --prune --unshallow
|
|
28
28
|
- run: git config --global user.name 'Actions'
|
|
29
29
|
- run: git config --global user.email 'dummy@example.org'
|
|
@@ -15,7 +15,7 @@ jobs:
|
|
|
15
15
|
release-type: node
|
|
16
16
|
package-name: commit-and-tag-version
|
|
17
17
|
# The logic below handles the npm publication:
|
|
18
|
-
- uses: actions/checkout@
|
|
18
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
|
|
19
19
|
# these if statements ensure that a publication only occurs when
|
|
20
20
|
# a new release is created:
|
|
21
21
|
if: ${{ steps.release.outputs.release_created }}
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [12.7.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.6.1...v12.7.0) (2026-03-17)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add --noBumpWhenEmptyChanges flag ([#274](https://github.com/absolute-version/commit-and-tag-version/issues/274)) ([b60fb23](https://github.com/absolute-version/commit-and-tag-version/commit/b60fb237b78622a5d523423d1b40e87aeb8631b5))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* make prerelease-flag work with gradle files ([#273](https://github.com/absolute-version/commit-and-tag-version/issues/273)) ([24e2f02](https://github.com/absolute-version/commit-and-tag-version/commit/24e2f028ac5634f278bcd2980d87faabd70647e4))
|
|
16
|
+
|
|
17
|
+
## [12.6.1](https://github.com/absolute-version/commit-and-tag-version/compare/v12.6.0...v12.6.1) (2025-12-01)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **bump:** auto-increment prerelease when tag already exists ([#258](https://github.com/absolute-version/commit-and-tag-version/issues/258)) ([75d69a6](https://github.com/absolute-version/commit-and-tag-version/commit/75d69a6a63c545062525c5566b60d2903a4666f4))
|
|
23
|
+
* use `fast-xml-parser` to parse and build XML. This substantially reduces the bundle size. ([#234](https://github.com/absolute-version/commit-and-tag-version/issues/234)) ([6075f4b](https://github.com/absolute-version/commit-and-tag-version/commit/6075f4bb1e34d55fc403a3b5b49390af0e760684))
|
|
24
|
+
|
|
5
25
|
## [12.6.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.5.2...v12.6.0) (2025-08-27)
|
|
6
26
|
|
|
7
27
|
|
package/README.md
CHANGED
|
@@ -284,6 +284,20 @@ npm run release -- --prerelease alpha
|
|
|
284
284
|
|
|
285
285
|
This will tag the version as: `1.0.1-alpha.0`
|
|
286
286
|
|
|
287
|
+
#### Prerelease Tag Collision Avoidance
|
|
288
|
+
|
|
289
|
+
When cutting a prerelease with `--prerelease`, `commit-and-tag-version` automatically checks existing git tags (respecting your `tagPrefix` configuration) for the same base version and prerelease channel. If a tag already exists, the numeric suffix is automatically incremented to avoid conflicts.
|
|
290
|
+
|
|
291
|
+
For example, if you're working with multiple prerelease channels simultaneously:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
commit-and-tag-version --prerelease xyz # Creates v1.4.3-xyz.0
|
|
295
|
+
commit-and-tag-version --prerelease abc # Creates v1.4.3-abc.0
|
|
296
|
+
commit-and-tag-version --prerelease xyz # Creates v1.4.3-xyz.1 (auto-incremented)
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
This behavior applies to both named prereleases (e.g., `-alpha.0`, `-beta.1`) and unnamed prereleases (e.g., `-0`, `-1`), ensuring that you can safely cut multiple prerelease versions without encountering git tag conflicts.
|
|
300
|
+
|
|
287
301
|
### Release as a Target Type Imperatively (`npm version`-like)
|
|
288
302
|
|
|
289
303
|
To forgo the automated version bump use `--release-as` with the argument `major`, `minor` or `patch`.
|
package/command.js
CHANGED
|
@@ -138,6 +138,12 @@ const yargs = require('yargs')
|
|
|
138
138
|
alias: 'c',
|
|
139
139
|
describe: 'Path to a custom configuration file',
|
|
140
140
|
})
|
|
141
|
+
.option('noBumpWhenEmptyChanges', {
|
|
142
|
+
type: 'boolean',
|
|
143
|
+
default: false,
|
|
144
|
+
describe:
|
|
145
|
+
'Avoid bumping files and generating changelog if there are no changes.',
|
|
146
|
+
})
|
|
141
147
|
.check((argv) => {
|
|
142
148
|
if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) {
|
|
143
149
|
throw Error('scripts must be an object');
|
package/index.js
CHANGED
|
@@ -85,6 +85,7 @@ module.exports = async function standardVersion(argv) {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
const newVersion = await bump(args, version);
|
|
88
|
+
if (!newVersion) return;
|
|
88
89
|
await changelog(args, newVersion);
|
|
89
90
|
await commit(args, newVersion);
|
|
90
91
|
await tag(newVersion, pkg ? pkg.private : false, args);
|
package/lib/lifecycles/bump.js
CHANGED
|
@@ -12,9 +12,48 @@ const runLifecycleScript = require('../run-lifecycle-script');
|
|
|
12
12
|
const semver = require('semver');
|
|
13
13
|
const writeFile = require('../write-file');
|
|
14
14
|
const { resolveUpdaterObjectFromArgument } = require('../updaters');
|
|
15
|
+
const gitSemverTags = require('git-semver-tags');
|
|
16
|
+
const addBangNotes = require('conventional-changelog-conventionalcommits/add-bang-notes');
|
|
15
17
|
let configsToUpdate = {};
|
|
16
18
|
const sanitizeQuotesRegex = /['"]+/g;
|
|
17
19
|
|
|
20
|
+
function noBumpWhenEmptyChanges(config, commits) {
|
|
21
|
+
let level = 2;
|
|
22
|
+
let breakings = 0;
|
|
23
|
+
let features = 0;
|
|
24
|
+
let fix = 0;
|
|
25
|
+
|
|
26
|
+
commits.forEach((commit) => {
|
|
27
|
+
addBangNotes(commit);
|
|
28
|
+
if (commit.notes.length > 0) {
|
|
29
|
+
breakings += commit.notes.length;
|
|
30
|
+
level = 0;
|
|
31
|
+
} else if (commit.type === 'feat' || commit.type === 'feature') {
|
|
32
|
+
features += 1;
|
|
33
|
+
if (level === 2) {
|
|
34
|
+
level = 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (commit.type === 'fix') {
|
|
38
|
+
fix += 1;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (config.preMajor && level < 2) {
|
|
43
|
+
level++;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!breakings && !features && !fix) return {};
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
level,
|
|
50
|
+
reason:
|
|
51
|
+
breakings === 1
|
|
52
|
+
? `There is ${breakings} BREAKING CHANGE and ${features} features`
|
|
53
|
+
: `There are ${breakings} BREAKING CHANGES and ${features} features`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
18
57
|
async function Bump(args, version) {
|
|
19
58
|
// reset the cache of updated config files each
|
|
20
59
|
// time we perform the version bump step.
|
|
@@ -41,6 +80,7 @@ async function Bump(args, version) {
|
|
|
41
80
|
const prebumpString = stdout.trim().replace(sanitizeQuotesRegex, '');
|
|
42
81
|
if (semver.valid(prebumpString)) args.releaseAs = prebumpString;
|
|
43
82
|
}
|
|
83
|
+
|
|
44
84
|
if (!args.firstRelease) {
|
|
45
85
|
if (semver.valid(args.releaseAs)) {
|
|
46
86
|
const releaseAs = new semver.SemVer(args.releaseAs);
|
|
@@ -75,6 +115,11 @@ async function Bump(args, version) {
|
|
|
75
115
|
newVersion = semvarToVersionStr(newVersion, releaseAs.build);
|
|
76
116
|
} else {
|
|
77
117
|
const release = await bumpVersion(args.releaseAs, version, args);
|
|
118
|
+
|
|
119
|
+
if (!Object.keys(release).length) {
|
|
120
|
+
checkpoint(args, 'no commits found, so not bumping version', []);
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
78
123
|
const releaseType = getReleaseType(
|
|
79
124
|
args.prerelease,
|
|
80
125
|
release.releaseType,
|
|
@@ -83,6 +128,15 @@ async function Bump(args, version) {
|
|
|
83
128
|
|
|
84
129
|
newVersion = semver.inc(version, releaseType, args.prerelease);
|
|
85
130
|
}
|
|
131
|
+
|
|
132
|
+
// If creating a prerelease, ensure the computed version is unique among existing git tags
|
|
133
|
+
if (isString(args.prerelease) && newVersion) {
|
|
134
|
+
newVersion = await resolveUniquePrereleaseVersion(
|
|
135
|
+
newVersion,
|
|
136
|
+
args.tagPrefix,
|
|
137
|
+
args.prerelease,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
86
140
|
updateConfigs(args, newVersion);
|
|
87
141
|
} else {
|
|
88
142
|
checkpoint(
|
|
@@ -202,6 +256,13 @@ function bumpVersion(releaseAs, currentVersion, args) {
|
|
|
202
256
|
),
|
|
203
257
|
}
|
|
204
258
|
: {}),
|
|
259
|
+
...(args.noBumpWhenEmptyChanges
|
|
260
|
+
? {
|
|
261
|
+
whatBump(commits) {
|
|
262
|
+
return noBumpWhenEmptyChanges(presetOptions, commits);
|
|
263
|
+
},
|
|
264
|
+
}
|
|
265
|
+
: {}),
|
|
205
266
|
},
|
|
206
267
|
args.parserOpts,
|
|
207
268
|
function (err, release) {
|
|
@@ -261,3 +322,96 @@ function updateConfigs(args, newVersion) {
|
|
|
261
322
|
}
|
|
262
323
|
|
|
263
324
|
module.exports = Bump;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Ensure prerelease version uniqueness by checking existing git tags.
|
|
328
|
+
* If a tag for the same base version and prerelease identifier exists, bump the numeric suffix.
|
|
329
|
+
* @param {string} proposedVersion The version computed by bump logic, may include build metadata.
|
|
330
|
+
* @param {string} tagPrefix The tag prefix to respect when reading tags (e.g., 'v').
|
|
331
|
+
* @param {string} prereleaseId The prerelease identifier (e.g., 'alpha', 'beta', 'rc').
|
|
332
|
+
* @returns {Promise<string>} The adjusted version that does not collide with existing tags.
|
|
333
|
+
*/
|
|
334
|
+
async function resolveUniquePrereleaseVersion(
|
|
335
|
+
proposedVersion,
|
|
336
|
+
tagPrefix,
|
|
337
|
+
prereleaseId,
|
|
338
|
+
) {
|
|
339
|
+
try {
|
|
340
|
+
const parsed = new semver.SemVer(proposedVersion);
|
|
341
|
+
const base = `${parsed.major}.${parsed.minor}.${parsed.patch}`;
|
|
342
|
+
const build = parsed.build; // preserve build metadata if present
|
|
343
|
+
|
|
344
|
+
// Determine current numeric index depending on named vs unnamed prerelease
|
|
345
|
+
let currentNum = 0;
|
|
346
|
+
if (Array.isArray(parsed.prerelease) && parsed.prerelease.length) {
|
|
347
|
+
if (prereleaseId === '' && typeof parsed.prerelease[0] === 'number') {
|
|
348
|
+
// unnamed prerelease like 1.2.3-0
|
|
349
|
+
currentNum = parsed.prerelease[0];
|
|
350
|
+
} else if (typeof parsed.prerelease[1] === 'number') {
|
|
351
|
+
// named prerelease like 1.2.3-alpha.0
|
|
352
|
+
currentNum = parsed.prerelease[1];
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const tags = await new Promise((resolve, reject) => {
|
|
357
|
+
gitSemverTags({ tagPrefix }, (err, t) =>
|
|
358
|
+
err ? reject(err) : resolve(t || []),
|
|
359
|
+
);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// strip prefix and clean
|
|
363
|
+
const cleaned = tags
|
|
364
|
+
.map((t) => t.replace(new RegExp('^' + tagPrefix), ''))
|
|
365
|
+
.map((t) => (semver.valid(t) ? semver.clean(t) : null))
|
|
366
|
+
.filter(Boolean);
|
|
367
|
+
|
|
368
|
+
// collect numeric suffix for same base and prerelease id (or unnamed prerelease)
|
|
369
|
+
const nums = cleaned
|
|
370
|
+
.filter((t) => {
|
|
371
|
+
const v = new semver.SemVer(t);
|
|
372
|
+
if (!Array.isArray(v.prerelease) || v.prerelease.length === 0)
|
|
373
|
+
return false;
|
|
374
|
+
const sameBase =
|
|
375
|
+
v.major === parsed.major &&
|
|
376
|
+
v.minor === parsed.minor &&
|
|
377
|
+
v.patch === parsed.patch;
|
|
378
|
+
if (!sameBase) return false;
|
|
379
|
+
if (prereleaseId === '') {
|
|
380
|
+
// unnamed prerelease: include tags where first prerelease token is numeric
|
|
381
|
+
return typeof v.prerelease[0] === 'number';
|
|
382
|
+
}
|
|
383
|
+
// named prerelease: match by identifier
|
|
384
|
+
return String(v.prerelease[0]) === String(prereleaseId);
|
|
385
|
+
})
|
|
386
|
+
.map((t) => {
|
|
387
|
+
const v = new semver.SemVer(t);
|
|
388
|
+
if (prereleaseId === '') {
|
|
389
|
+
return typeof v.prerelease[0] === 'number' ? v.prerelease[0] : 0;
|
|
390
|
+
}
|
|
391
|
+
return typeof v.prerelease[1] === 'number' ? v.prerelease[1] : 0;
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
if (nums.length === 0) {
|
|
395
|
+
// no collisions possible
|
|
396
|
+
return proposedVersion;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const maxExisting = Math.max(...nums);
|
|
400
|
+
// If our proposed numeric index is already used or below max, bump to max + 1
|
|
401
|
+
if (currentNum <= maxExisting) {
|
|
402
|
+
let candidate =
|
|
403
|
+
prereleaseId === ''
|
|
404
|
+
? `${base}-${maxExisting + 1}`
|
|
405
|
+
: `${base}-${prereleaseId}.${maxExisting + 1}`;
|
|
406
|
+
// re-append build metadata if any
|
|
407
|
+
if (build && build.length) {
|
|
408
|
+
candidate = semvarToVersionStr(candidate, build);
|
|
409
|
+
}
|
|
410
|
+
return candidate;
|
|
411
|
+
}
|
|
412
|
+
return proposedVersion;
|
|
413
|
+
} catch {
|
|
414
|
+
// If anything goes wrong, fall back to proposedVersion
|
|
415
|
+
return proposedVersion;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
const jsdom = require('jsdom');
|
|
2
|
-
const serialize = require('w3c-xmlserializer');
|
|
3
1
|
const detectNewline = require('detect-newline');
|
|
2
|
+
const { XMLParser, XMLBuilder } = require('fast-xml-parser');
|
|
3
|
+
|
|
4
4
|
const CRLF = '\r\n';
|
|
5
5
|
const LF = '\n';
|
|
6
6
|
|
|
7
7
|
function pomDocument(contents) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
return parser.parseFromString(contents, 'application/xml');
|
|
8
|
+
const parser = new XMLParser();
|
|
9
|
+
return parser.parse(contents);
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
function
|
|
14
|
-
const
|
|
12
|
+
function pomVersion(document) {
|
|
13
|
+
const version = document?.project?.version;
|
|
15
14
|
|
|
16
|
-
if (!
|
|
15
|
+
if (!version) {
|
|
17
16
|
throw new Error(
|
|
18
17
|
'Failed to read the version field in your pom file - is it present?',
|
|
19
18
|
);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
return
|
|
21
|
+
return version;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
module.exports.readVersion = function (contents) {
|
|
26
25
|
const document = pomDocument(contents);
|
|
27
|
-
return
|
|
26
|
+
return pomVersion(document);
|
|
28
27
|
};
|
|
29
28
|
|
|
30
29
|
module.exports.writeVersion = function (contents, version) {
|
|
31
30
|
const newline = detectNewline(contents);
|
|
32
31
|
const document = pomDocument(contents);
|
|
33
|
-
const versionElement = pomVersionElement(document);
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
document.project.version = version;
|
|
36
34
|
|
|
37
|
-
const
|
|
35
|
+
const builder = new XMLBuilder({ format: true });
|
|
36
|
+
const xml = builder.build(document);
|
|
38
37
|
|
|
39
38
|
if (newline === CRLF) {
|
|
40
39
|
return xml.replace(/\n/g, CRLF) + CRLF;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commit-and-tag-version",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.7.0",
|
|
4
4
|
"description": "replacement for `npm version` with automatic CHANGELOG generation",
|
|
5
5
|
"bin": "bin/cli.js",
|
|
6
6
|
"scripts": {
|
|
@@ -47,23 +47,22 @@
|
|
|
47
47
|
"detect-indent": "^6.1.0",
|
|
48
48
|
"detect-newline": "^3.1.0",
|
|
49
49
|
"dotgitignore": "^2.1.0",
|
|
50
|
+
"fast-xml-parser": "^5.3.4",
|
|
50
51
|
"figures": "^3.2.0",
|
|
51
52
|
"find-up": "^5.0.0",
|
|
52
53
|
"git-semver-tags": "^5.0.1",
|
|
53
|
-
"jsdom": "^25.0.1",
|
|
54
54
|
"semver": "^7.7.2",
|
|
55
|
-
"w3c-xmlserializer": "^5.0.0",
|
|
56
55
|
"yaml": "^2.6.0",
|
|
57
56
|
"yargs": "^17.7.2"
|
|
58
57
|
},
|
|
59
58
|
"devDependencies": {
|
|
60
|
-
"@eslint/js": "^9.
|
|
59
|
+
"@eslint/js": "^9.36.0",
|
|
61
60
|
"eslint": "^9.13.0",
|
|
62
|
-
"eslint-config-prettier": "^
|
|
61
|
+
"eslint-config-prettier": "^10.1.8",
|
|
63
62
|
"eslint-plugin-import": "^2.31.0",
|
|
64
63
|
"eslint-plugin-jest": "^28.8.3",
|
|
65
|
-
"eslint-plugin-n": "^17.
|
|
66
|
-
"eslint-plugin-promise": "^7.1
|
|
64
|
+
"eslint-plugin-n": "^17.21.3",
|
|
65
|
+
"eslint-plugin-promise": "^7.2.1",
|
|
67
66
|
"jest": "^29.7.0",
|
|
68
67
|
"jest-serial-runner": "^1.2.1",
|
|
69
68
|
"prettier": "^3.3.3",
|
package/test/core.spec.js
CHANGED
|
@@ -158,6 +158,7 @@ function mock({
|
|
|
158
158
|
bump,
|
|
159
159
|
changelog,
|
|
160
160
|
tags,
|
|
161
|
+
commits,
|
|
161
162
|
existingChangelog,
|
|
162
163
|
testFiles,
|
|
163
164
|
realTestFiles,
|
|
@@ -174,6 +175,10 @@ function mock({
|
|
|
174
175
|
tags,
|
|
175
176
|
});
|
|
176
177
|
|
|
178
|
+
mockers.mockGitRawCommits({
|
|
179
|
+
commits,
|
|
180
|
+
});
|
|
181
|
+
|
|
177
182
|
// needs to be set after mockery, but before mock-fs
|
|
178
183
|
standardVersion = require('../index');
|
|
179
184
|
|
|
@@ -913,6 +918,58 @@ describe('cli', function () {
|
|
|
913
918
|
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
914
919
|
expect(consoleInfoSpy).not.toHaveBeenCalled();
|
|
915
920
|
});
|
|
921
|
+
|
|
922
|
+
it('bumps using actual recommendedBump when there are no semver relevant changes and --noBumpWhenEmptyChanges flag is not set', async function () {
|
|
923
|
+
mock({
|
|
924
|
+
bump: jest.requireActual('conventional-recommended-bump'),
|
|
925
|
+
changelog: ['chore release\n'],
|
|
926
|
+
tags: ['v1.0.0'],
|
|
927
|
+
commits: ['chore: update deps\n\n-hash-\nabc123\n'],
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
await exec();
|
|
931
|
+
|
|
932
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.0.1' });
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
it('bumps using actual recommendedBump when there are semver relevant changes and --noBumpWhenEmptyChanges flag is not set', async function () {
|
|
936
|
+
mock({
|
|
937
|
+
bump: jest.requireActual('conventional-recommended-bump'),
|
|
938
|
+
changelog: ['feat release\n'],
|
|
939
|
+
tags: ['v1.0.0'],
|
|
940
|
+
commits: ['feat: shiny new stuff\n\n-hash-\nabc123\n'],
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
await exec();
|
|
944
|
+
|
|
945
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
it('does not bump when there are no semver relevant changes and --noBumpWhenEmptyChanges flag is set', async function () {
|
|
949
|
+
mock({
|
|
950
|
+
bump: jest.requireActual('conventional-recommended-bump'),
|
|
951
|
+
changelog: ['chore release\n'],
|
|
952
|
+
tags: ['v1.0.0'],
|
|
953
|
+
commits: ['chore: update deps\n\n-hash-\nabc123\n'],
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
await exec('--noBumpWhenEmptyChanges');
|
|
957
|
+
|
|
958
|
+
expect(writeFileSyncSpy).not.toHaveBeenCalled();
|
|
959
|
+
});
|
|
960
|
+
|
|
961
|
+
it('bumps when there are semver relevant changes and --noBumpWhenEmptyChanges flag is set', async function () {
|
|
962
|
+
mock({
|
|
963
|
+
bump: jest.requireActual('conventional-recommended-bump'),
|
|
964
|
+
changelog: ['feat release\n'],
|
|
965
|
+
tags: ['v1.0.0'],
|
|
966
|
+
commits: ['feat: shiny new stuff\n\n-hash-\nabc123\n'],
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
await exec('--noBumpWhenEmptyChanges');
|
|
970
|
+
|
|
971
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
|
|
972
|
+
});
|
|
916
973
|
});
|
|
917
974
|
|
|
918
975
|
describe('commit-and-tag-version', function () {
|
|
@@ -1388,6 +1445,43 @@ describe('cli', function () {
|
|
|
1388
1445
|
expect(calledWithContentStr).toEqual(expected);
|
|
1389
1446
|
});
|
|
1390
1447
|
|
|
1448
|
+
it('bumps to prerelease version in Gradle `build.gradle.kts` file', async function () {
|
|
1449
|
+
const expected = fs.readFileSync(
|
|
1450
|
+
'./test/mocks/build-6.4.0-snapshot.gradle.kts',
|
|
1451
|
+
'utf-8',
|
|
1452
|
+
);
|
|
1453
|
+
|
|
1454
|
+
const filename = 'build.gradle.kts';
|
|
1455
|
+
mock({
|
|
1456
|
+
bump: 'minor',
|
|
1457
|
+
realTestFiles: [
|
|
1458
|
+
{
|
|
1459
|
+
filename,
|
|
1460
|
+
path: './test/mocks/build-6.3.1.gradle.kts',
|
|
1461
|
+
},
|
|
1462
|
+
],
|
|
1463
|
+
});
|
|
1464
|
+
|
|
1465
|
+
await exec({
|
|
1466
|
+
prerelease: 'SNAPSHOT',
|
|
1467
|
+
packageFiles: [{ filename, type: 'gradle' }],
|
|
1468
|
+
bumpFiles: [{ filename, type: 'gradle' }],
|
|
1469
|
+
});
|
|
1470
|
+
|
|
1471
|
+
// filePath is the first arg passed to writeFileSync
|
|
1472
|
+
const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
|
|
1473
|
+
writeFileSyncSpy,
|
|
1474
|
+
filename,
|
|
1475
|
+
});
|
|
1476
|
+
|
|
1477
|
+
if (!packageJsonWriteFileSynchCall) {
|
|
1478
|
+
throw new Error(`writeFileSynch not invoked with path ${filename}`);
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
const calledWithContentStr = packageJsonWriteFileSynchCall[1];
|
|
1482
|
+
expect(calledWithContentStr).toEqual(expected);
|
|
1483
|
+
});
|
|
1484
|
+
|
|
1391
1485
|
it('bumps version in .NET `Project.csproj` file', async function () {
|
|
1392
1486
|
const expected = fs.readFileSync(
|
|
1393
1487
|
'./test/mocks/Project-6.4.0.csproj',
|
|
@@ -248,6 +248,45 @@ describe('git', function () {
|
|
|
248
248
|
expect(getPackageVersion()).toEqual('1.1.0-0');
|
|
249
249
|
});
|
|
250
250
|
|
|
251
|
+
it('increments unnamed prerelease number when unnamed prerelease tag already exists', async function () {
|
|
252
|
+
writePackageJson('1.2.3');
|
|
253
|
+
// Existing unnamed prerelease tag 1.2.3-0 exists
|
|
254
|
+
mock({ bump: 'patch', tags: ['v1.2.3-0'] });
|
|
255
|
+
await exec('--prerelease');
|
|
256
|
+
expect(getPackageVersion()).toEqual('1.2.4-0');
|
|
257
|
+
// Now start from a prerelease of same base to trigger unnamed collision
|
|
258
|
+
writePackageJson('1.2.3-0');
|
|
259
|
+
mock({ bump: 'patch', tags: ['v1.2.3-0'] });
|
|
260
|
+
await exec('--prerelease');
|
|
261
|
+
expect(getPackageVersion()).toEqual('1.2.3-1');
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('increments unnamed prerelease number with gitTagFallback when unnamed prerelease tag already exists', async function () {
|
|
265
|
+
shell.rm('package.json');
|
|
266
|
+
mock({ bump: 'patch', tags: ['v1.2.3-0'] });
|
|
267
|
+
await exec({ packageFiles: [], gitTagFallback: true, prerelease: '' });
|
|
268
|
+
const output = shell.exec('git tag').stdout;
|
|
269
|
+
expect(output).toMatch(/v1\.2\.3-1/);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('increments prerelease number when same prerelease tag already exists', async function () {
|
|
273
|
+
writePackageJson('1.4.3-abc.0');
|
|
274
|
+
// Simulate existing tags where v1.4.3-xyz.0 already exists from git history
|
|
275
|
+
mock({ bump: 'patch', tags: ['v1.4.3-xyz.0'] });
|
|
276
|
+
await exec('--prerelease xyz');
|
|
277
|
+
// Base remains 1.4.3 when switching prerelease channel mid-cycle; must bump numeric suffix to avoid tag collision
|
|
278
|
+
expect(getPackageVersion()).toEqual('1.4.3-xyz.1');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('increments prerelease number with gitTagFallback when same prerelease tag already exists', async function () {
|
|
282
|
+
// Setup without package.json and with existing tags only
|
|
283
|
+
shell.rm('package.json');
|
|
284
|
+
mock({ bump: 'patch', tags: ['v1.4.3-xyz.0'] });
|
|
285
|
+
await exec({ packageFiles: [], gitTagFallback: true, prerelease: 'xyz' });
|
|
286
|
+
const output = shell.exec('git tag').stdout;
|
|
287
|
+
expect(output).toMatch(/v1\.4\.3-xyz\.1/);
|
|
288
|
+
});
|
|
289
|
+
|
|
251
290
|
describe('gitTagFallback', function () {
|
|
252
291
|
beforeEach(function () {
|
|
253
292
|
setup();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
plugins {
|
|
2
|
+
id("org.springframework.boot") version "2.4.6"
|
|
3
|
+
kotlin("jvm") version "1.4.31"
|
|
4
|
+
kotlin("plugin.spring") version "1.4.31"
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
version = "6.4.0-SNAPSHOT.0"
|
|
8
|
+
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
|
9
|
+
|
|
10
|
+
repositories {
|
|
11
|
+
mavenLocal()
|
|
12
|
+
mavenCentral()
|
|
13
|
+
}
|
|
14
|
+
|
package/test/mocks/jest-mocks.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
const gitSemverTags = require('git-semver-tags');
|
|
2
2
|
const conventionalChangelog = require('conventional-changelog');
|
|
3
3
|
const conventionalRecommendedBump = require('conventional-recommended-bump');
|
|
4
|
+
const gitRawCommits = require('git-raw-commits');
|
|
4
5
|
|
|
5
6
|
const { Readable } = require('stream');
|
|
6
7
|
|
|
7
8
|
jest.mock('conventional-changelog');
|
|
8
9
|
jest.mock('conventional-recommended-bump');
|
|
9
10
|
jest.mock('git-semver-tags');
|
|
11
|
+
jest.mock('git-raw-commits');
|
|
10
12
|
|
|
11
13
|
const mockGitSemverTags = ({ tags = [] }) => {
|
|
12
14
|
gitSemverTags.mockImplementation((opts, cb) => {
|
|
@@ -15,6 +17,21 @@ const mockGitSemverTags = ({ tags = [] }) => {
|
|
|
15
17
|
});
|
|
16
18
|
};
|
|
17
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @param { { commits: string[] } }
|
|
22
|
+
* a commit should look like `<rawBody>\n\n-hash-\n<hash>\n`
|
|
23
|
+
*/
|
|
24
|
+
const mockGitRawCommits = ({ commits = [] }) => {
|
|
25
|
+
gitRawCommits.mockImplementation(() => {
|
|
26
|
+
return new Readable({
|
|
27
|
+
read() {
|
|
28
|
+
commits.forEach((c) => this.push(c));
|
|
29
|
+
this.push(null);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
18
35
|
const mockConventionalChangelog = ({ changelog }) => {
|
|
19
36
|
conventionalChangelog.mockImplementation(
|
|
20
37
|
(opt) =>
|
|
@@ -43,6 +60,7 @@ const mockRecommendedBump = ({ bump }) => {
|
|
|
43
60
|
|
|
44
61
|
module.exports = {
|
|
45
62
|
mockGitSemverTags,
|
|
63
|
+
mockGitRawCommits,
|
|
46
64
|
mockConventionalChangelog,
|
|
47
65
|
mockRecommendedBump,
|
|
48
66
|
};
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
<project>
|
|
2
2
|
<modelVersion>4.0.0</modelVersion>
|
|
3
|
-
|
|
4
3
|
<parent>
|
|
5
4
|
<groupId>com.mycompany.app</groupId>
|
|
6
5
|
<artifactId>my-app</artifactId>
|
|
7
6
|
<version>3.0.0</version>
|
|
8
7
|
</parent>
|
|
9
|
-
|
|
10
8
|
<groupId>com.mycompany.app</groupId>
|
|
11
9
|
<artifactId>my-module</artifactId>
|
|
12
10
|
<version>6.4.0</version>
|
|
13
|
-
|
|
14
11
|
<properties>
|
|
15
12
|
<some.version>2.0.0</some.version>
|
|
16
13
|
</properties>
|
|
17
|
-
|
|
18
14
|
<dependencies>
|
|
19
15
|
<dependency>
|
|
20
16
|
<groupId>org.some.dependency</groupId>
|
|
@@ -28,3 +24,4 @@
|
|
|
28
24
|
</dependency>
|
|
29
25
|
</dependencies>
|
|
30
26
|
</project>
|
|
27
|
+
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
<project>
|
|
2
2
|
<modelVersion>4.0.0</modelVersion>
|
|
3
|
-
|
|
4
3
|
<parent>
|
|
5
4
|
<groupId>com.mycompany.app</groupId>
|
|
6
5
|
<artifactId>my-app</artifactId>
|
|
7
6
|
<version>3.0.0</version>
|
|
8
7
|
</parent>
|
|
9
|
-
|
|
10
8
|
<groupId>com.mycompany.app</groupId>
|
|
11
9
|
<artifactId>my-module</artifactId>
|
|
12
10
|
<version>6.4.0</version>
|
|
13
|
-
|
|
14
11
|
<properties>
|
|
15
12
|
<some.version>2.0.0</some.version>
|
|
16
13
|
</properties>
|
|
17
|
-
|
|
18
14
|
<dependencies>
|
|
19
15
|
<dependency>
|
|
20
16
|
<groupId>org.some.dependency</groupId>
|
|
@@ -28,3 +24,4 @@
|
|
|
28
24
|
</dependency>
|
|
29
25
|
</dependencies>
|
|
30
26
|
</project>
|
|
27
|
+
|