Skip to content
Snippets Groups Projects
Unverified Commit a9af34cf authored by bjuraga's avatar bjuraga Committed by GitHub
Browse files

fix(manager/nuget): don't bump version if already done (#23546)

parent d4679f75
Branches
Tags 36.24.4
No related merge requests found
...@@ -7,6 +7,10 @@ const minimumContent = ...@@ -7,6 +7,10 @@ const minimumContent =
'<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><Version>1</Version></PropertyGroup></Project>'; '<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><Version>1</Version></PropertyGroup></Project>';
const prereleaseContent = const prereleaseContent =
'<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><Version>1.0.0-1</Version></PropertyGroup></Project>'; '<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><Version>1.0.0-1</Version></PropertyGroup></Project>';
const issue23526InitialContent =
'<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><Version>4.9.0</Version></PropertyGroup></Project>';
const issue23526ExpectedContent =
'<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><Version>4.10.0</Version></PropertyGroup></Project>';
describe('modules/manager/nuget/update', () => { describe('modules/manager/nuget/update', () => {
describe('bumpPackageVersion', () => { describe('bumpPackageVersion', () => {
...@@ -36,6 +40,21 @@ describe('modules/manager/nuget/update', () => { ...@@ -36,6 +40,21 @@ describe('modules/manager/nuget/update', () => {
expect(bumpedContent).toEqual(bumpedContent2); expect(bumpedContent).toEqual(bumpedContent2);
}); });
it('issue 23526 does not bump version incorrectly', () => {
const { bumpedContent } = bumpPackageVersion(
issue23526InitialContent,
'4.9.0',
'minor'
);
const { bumpedContent: bumpedContent2 } = bumpPackageVersion(
bumpedContent!,
'4.9.0',
'minor'
);
expect(bumpedContent2).toEqual(issue23526ExpectedContent);
});
it('does not bump version if version is not a semantic version', () => { it('does not bump version if version is not a semantic version', () => {
const { bumpedContent } = bumpPackageVersion( const { bumpedContent } = bumpPackageVersion(
minimumContent, minimumContent,
......
...@@ -31,14 +31,23 @@ export function bumpPackageVersion( ...@@ -31,14 +31,23 @@ export function bumpPackageVersion(
try { try {
const project = new XmlDocument(content); const project = new XmlDocument(content);
const versionNode = project.descendantWithPath('PropertyGroup.Version')!; const versionNode = project.descendantWithPath('PropertyGroup.Version')!;
const currentProjVersion = versionNode.val;
const startTagPosition = versionNode.startTagPosition; const startTagPosition = versionNode.startTagPosition;
const versionPosition = content.indexOf(versionNode.val, startTagPosition); const versionPosition = content.indexOf(
currentProjVersion,
startTagPosition
);
const newProjVersion = semver.inc(currentValue, bumpVersion as ReleaseType); const newProjVersion = semver.inc(currentValue, bumpVersion as ReleaseType);
if (!newProjVersion) { if (!newProjVersion) {
throw new Error('semver inc failed'); throw new Error('semver inc failed');
} }
if (currentProjVersion === newProjVersion) {
logger.debug('Version was already bumped');
return { bumpedContent };
}
logger.debug(`newProjVersion: ${newProjVersion}`); logger.debug(`newProjVersion: ${newProjVersion}`);
bumpedContent = replaceAt( bumpedContent = replaceAt(
content, content,
...@@ -46,12 +55,6 @@ export function bumpPackageVersion( ...@@ -46,12 +55,6 @@ export function bumpPackageVersion(
currentValue, currentValue,
newProjVersion newProjVersion
); );
if (bumpedContent === content) {
logger.debug('Version was already bumped');
} else {
logger.debug('project version bumped');
}
} catch (err) { } catch (err) {
logger.warn( logger.warn(
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment