Skip to content

Commit

Permalink
Fix prerelease continuation increased patch version in CI mode (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
pstrh committed Oct 31, 2020
1 parent 1e2e8f3 commit 3021d18
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/plugin/version/Version.js
Expand Up @@ -63,8 +63,7 @@ class Version extends Plugin {

getIncrementedVersionCI(options) {
const { isCI } = this.config;
options.increment = options.increment == null && isCI ? 'patch' : options.increment;
return this.incrementVersion(options);
return this.incrementVersion(options, isCI);
}

async getIncrementedVersion(options) {
Expand Down Expand Up @@ -93,7 +92,7 @@ class Version extends Plugin {
return Boolean(semver.valid(version));
}

incrementVersion({ latestVersion, increment, isPreRelease, preReleaseId }) {
incrementVersion({ latestVersion, increment, isPreRelease, preReleaseId }, isCI) {
if (increment === false) return latestVersion;

const latestIsPreRelease = this.isPreRelease(latestVersion);
Expand All @@ -111,6 +110,10 @@ class Version extends Plugin {
return semver.inc(latestVersion, 'prerelease', preReleaseId);
}

if (isCI && !increment) {
return semver.inc(latestVersion, 'patch');
}

const normalizedType = RELEASE_TYPES.includes(increment) && isPreRelease ? `pre${increment}` : increment;
if (ALL_RELEASE_TYPES.includes(normalizedType)) {
return semver.inc(latestVersion, normalizedType, preReleaseId);
Expand Down
2 changes: 1 addition & 1 deletion test/plugins.js
Expand Up @@ -106,7 +106,7 @@ test.serial('should instantiate plugins and execute all release-cycle methods',
t.is(myLocalPlugin[method].callCount, 1);
});

const incrementBase = { latestVersion: '0.0.0', increment: 'patch', isPreRelease: false, preReleaseId: undefined };
const incrementBase = { latestVersion: '0.0.0', increment: undefined, isPreRelease: false, preReleaseId: undefined };
t.deepEqual(myPlugin.getIncrement.firstCall.args[0], incrementBase);
t.deepEqual(myPlugin.getIncrementedVersionCI.firstCall.args[0], incrementBase);
t.deepEqual(myLocalPlugin.getIncrementedVersionCI.firstCall.args[0], incrementBase);
Expand Down
15 changes: 15 additions & 0 deletions test/version.js
Expand Up @@ -15,11 +15,26 @@ test('isPreRelease', t => {
t.is(v.isPreRelease('1.0.0'), false);
});

test('getIncrementedVersionCI should default increment to patch if no increment is given', t => {
const v = factory(Version);
t.is(v.getIncrementedVersionCI({ latestVersion: '2.0.0', increment: null}), '2.0.1');
});

test('interactive and ci mode should return the same version if no increment is given (prerelease continuation, issue #714)', async t => {
const v = factory(Version);
const options = { latestVersion: '2.0.0-beta.1', increment: null, preReleaseId: 'rc', isPreRelease: true};
const resultInteractiveMode = await v.getIncrementedVersion(options);
t.is(resultInteractiveMode, '2.0.0-rc.0');
const resultCiMode = v.getIncrementedVersionCI(options);
t.is(resultInteractiveMode, resultCiMode);
});

test('should increment latest version', t => {
const v = factory(Version);
const latestVersion = '1.0.0';
t.is(v.incrementVersion({ latestVersion, increment: false }), '1.0.0');
t.is(v.incrementVersion({ latestVersion, increment: null }), undefined);
t.is(v.incrementVersion({ latestVersion, increment: null }, true), '1.0.1');
t.is(v.incrementVersion({ latestVersion, increment: 'foo' }), undefined);
t.is(v.incrementVersion({ latestVersion, increment: 'patsj' }), undefined);
t.is(v.incrementVersion({ latestVersion, increment: 'a.b.c' }), undefined);
Expand Down

0 comments on commit 3021d18

Please sign in to comment.