Skip to content

Commit

Permalink
fix(manager/nuget): don't bump version if already done (#23546)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjuraga committed Jul 27, 2023
1 parent d4679f7 commit a9af34c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
19 changes: 19 additions & 0 deletions lib/modules/manager/nuget/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const minimumContent =
'<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><Version>1</Version></PropertyGroup></Project>';
const prereleaseContent =
'<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('bumpPackageVersion', () => {
Expand Down Expand Up @@ -36,6 +40,21 @@ describe('modules/manager/nuget/update', () => {
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', () => {
const { bumpedContent } = bumpPackageVersion(
minimumContent,
Expand Down
17 changes: 10 additions & 7 deletions lib/modules/manager/nuget/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,30 @@ export function bumpPackageVersion(
try {
const project = new XmlDocument(content);
const versionNode = project.descendantWithPath('PropertyGroup.Version')!;
const currentProjVersion = versionNode.val;
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);
if (!newProjVersion) {
throw new Error('semver inc failed');
}

if (currentProjVersion === newProjVersion) {
logger.debug('Version was already bumped');
return { bumpedContent };
}

logger.debug(`newProjVersion: ${newProjVersion}`);
bumpedContent = replaceAt(
content,
versionPosition,
currentValue,
newProjVersion
);

if (bumpedContent === content) {
logger.debug('Version was already bumped');
} else {
logger.debug('project version bumped');
}
} catch (err) {
logger.warn(
{
Expand Down

0 comments on commit a9af34c

Please sign in to comment.