fix(gomod): go.mod directive should not bump by default (#28475)

This commit is contained in:
Rhys Arkins 2024-04-17 12:59:13 +02:00 committed by GitHub
parent b652e853f2
commit 2902d17637
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 12 deletions

View file

@ -8,6 +8,7 @@ describe('modules/versioning/go-mod-directive/index', () => {
${'1.15.0'} | ${'1.16'} | ${false}
${'1.19.1'} | ${'1.16'} | ${true}
${'2.0.0'} | ${'1.16'} | ${false}
${'1.22.2'} | ${'1.21.9'} | ${true}
`(
'matches("$version", "$range") === "$expected"',
({ version, range, expected }) => {
@ -70,10 +71,12 @@ describe('modules/versioning/go-mod-directive/index', () => {
${'1.16'} | ${'bump'} | ${'1.16.4'} | ${'1.17.0'} | ${'1.17'}
${'1.16'} | ${'bump'} | ${'1.16.4'} | ${'1.16.4'} | ${'1.16'}
${'1.16'} | ${'replace'} | ${'1.16.4'} | ${'1.16.4'} | ${'1.16'}
${'1.16'} | ${'replace'} | ${'1.21.2'} | ${'1.21.2'} | ${'1.21.2'}
${'1.16'} | ${'replace'} | ${'1.21.2'} | ${'1.21.2'} | ${'1.16'}
${'1.16'} | ${'widen'} | ${'1.16.4'} | ${'1.16.4'} | ${'1.16'}
${'1.16'} | ${'bump'} | ${'1.16.4'} | ${'1.21.3'} | ${'1.21.3'}
${'1.21.2'} | ${'bump'} | ${'1.21.2'} | ${'1.21.3'} | ${'1.21.3'}
${'1.21.2'} | ${'replace'} | ${'1.21.2'} | ${'1.22.2'} | ${'1.21.2'}
${'1.21.2'} | ${'replace'} | ${'1.21.2'} | ${'2.0.0'} | ${'2.0.0'}
`(
'getNewValue("$currentValue", "$rangeStrategy", "$currentVersion", "$newVersion") === "$expected"',
({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => {

View file

@ -30,12 +30,9 @@ function getNewValue({
}
return shorten(newVersion);
}
if (rangeStrategy === 'replace' && !matches(currentValue, newVersion)) {
if (npm.matches(newVersion, '>=1.20.0')) {
if (rangeStrategy === 'replace' && !matches(newVersion, currentValue)) {
return newVersion;
}
return shorten(newVersion);
}
return currentValue;
}