Skip to content

Commit

Permalink
fix: remove the v prefix for Swift version values (#24004)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrindel authored Aug 22, 2023
1 parent 33b6a6f commit fe09626
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 8 additions & 1 deletion lib/modules/versioning/swift/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
12 changes: 8 additions & 4 deletions lib/modules/versioning/swift/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fe09626

Please sign in to comment.