diff --git a/lib/modules/versioning/swift/index.spec.ts b/lib/modules/versioning/swift/index.spec.ts index 2ee3e7a820b0e5..97dc9f24e52b09 100644 --- a/lib/modules/versioning/swift/index.spec.ts +++ b/lib/modules/versioning/swift/index.spec.ts @@ -109,14 +109,21 @@ describe('modules/versioning/swift/index', () => { it.each` currentValue | rangeStrategy | currentVersion | newVersion | expected ${'1.2.3'} | ${'auto'} | ${'1.2.3'} | ${'1.2.4'} | ${'1.2.3'} - ${'v1.2.3'} | ${'auto'} | ${'v1.2.3'} | ${'v1.2.4'} | ${'v1.2.3'} + ${'1.2.3'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.4'} | ${'1.2.3'} ${'from: "1.2.3"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.4'} | ${'from: "1.2.4"'} + ${'from: "1.2.3"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.4'} | ${'from: "1.2.4"'} ${'from: "1.2.2"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.4'} | ${'from: "1.2.4"'} + ${'from: "1.2.2"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.4'} | ${'from: "1.2.4"'} ${'"1.2.3"...'} | ${'auto'} | ${'1.2.3'} | ${'1.2.4'} | ${'"1.2.4"...'} + ${'"1.2.3"...'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.4'} | ${'"1.2.4"...'} ${'"1.2.3"..."1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.5'} | ${'"1.2.3"..."1.2.5"'} + ${'"1.2.3"..."1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.5'} | ${'"1.2.3"..."1.2.5"'} ${'"1.2.3"..<"1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.5'} | ${'"1.2.3"..<"1.2.5"'} + ${'"1.2.3"..<"1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.5'} | ${'"1.2.3"..<"1.2.5"'} ${'..."1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.5'} | ${'..."1.2.5"'} + ${'..."1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.5'} | ${'..."1.2.5"'} ${'..<"1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'1.2.5'} | ${'..<"1.2.5"'} + ${'..<"1.2.4"'} | ${'auto'} | ${'1.2.3'} | ${'v1.2.5'} | ${'..<"1.2.5"'} `( 'getNewValue("$currentValue", "$rangeStrategy", "$currentVersion", "$newVersion") === "$expected"', ({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => { diff --git a/lib/modules/versioning/swift/range.ts b/lib/modules/versioning/swift/range.ts index 017cdfb09b1ce5..f22b81623be1f7 100644 --- a/lib/modules/versioning/swift/range.ts +++ b/lib/modules/versioning/swift/range.ts @@ -6,6 +6,7 @@ const fromParam = regEx(/^\s*from\s*:\s*"([^"]+)"\s*$/); const fromRange = regEx(/^\s*"([^"]+)"\s*\.\.\.\s*$/); const binaryRange = regEx(/^\s*"([^"]+)"\s*(\.\.[.<])\s*"([^"]+)"\s*$/); const toRange = regEx(/^\s*(\.\.[.<])\s*"([^"]+)"\s*$/); +const vPrefix = regEx(/^v([0-9]+)/); function toSemverRange(range: string): string | null { const fromParamMatch = fromParam.exec(range); @@ -49,26 +50,29 @@ function toSemverRange(range: string): string | null { } function getNewValue({ currentValue, newVersion }: NewValueConfig): string { + // Remove the v prefix if it exists + const cleanNewVersion = newVersion.replace(vPrefix, '$1'); + if (fromParam.test(currentValue)) { - return currentValue.replace(regEx(/".*?"/), `"${newVersion}"`); + return currentValue.replace(regEx(/".*?"/), `"${cleanNewVersion}"`); } const fromRangeMatch = fromRange.exec(currentValue); if (fromRangeMatch) { const [, version] = fromRangeMatch; - return currentValue.replace(version, newVersion); + return currentValue.replace(version, cleanNewVersion); } const binaryRangeMatch = binaryRange.exec(currentValue); if (binaryRangeMatch) { const [, , , version] = binaryRangeMatch; - return currentValue.replace(version, newVersion); + return currentValue.replace(version, cleanNewVersion); } const toRangeMatch = toRange.exec(currentValue); if (toRangeMatch) { const [, , version] = toRangeMatch; - return currentValue.replace(version, newVersion); + return currentValue.replace(version, cleanNewVersion); } return currentValue;