Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prerelease continuation increased patch version in CI mode #715

Merged
merged 2 commits into from Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
pstrh marked this conversation as resolved.
Show resolved Hide resolved
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 };
pstrh marked this conversation as resolved.
Show resolved Hide resolved
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