diff --git a/lib/modules/manager/swift/__fixtures__/SamplePackage.swift b/lib/modules/manager/swift/__fixtures__/SamplePackage.swift index 2c8e2a13d011435e13b23f662de392622b7c8be9..ffec76f9836620f336daca32b4d9f69e955d94c0 100644 --- a/lib/modules/manager/swift/__fixtures__/SamplePackage.swift +++ b/lib/modules/manager/swift/__fixtures__/SamplePackage.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.2 +// swift-tools-version:5.6 import PackageDescription @@ -41,6 +41,7 @@ let package = Package( .package(url: "baz", from: "1.2.3.4"), .package(url: "https://github.com/avito-tech/GraphiteClient.git", .exact( "0.1.0" )), .package(url: "https://github.com/IBM-Swift/BlueSignals.git", .exact("1.0.16")), + .package(url: "https://github.com/apple/swift-argument-parser", exact: "1.2.1"), .package(url: "https://github.com/beefon/Shout", .branch("UpdateSocket")), .package(url: "https://github.com/daltoniam/Starscream.git", .exact("3.0.6")), .package(url: "https://github.com/httpswift/swifter.git", .exact("1.4.6")), diff --git a/lib/modules/manager/swift/__snapshots__/index.spec.ts.snap b/lib/modules/manager/swift/__snapshots__/index.spec.ts.snap index 67cac674038b8ee4c9c3955062d397c0fc5989a1..45441e342e90a165e9ae250cf2743c77a89abfa5 100644 --- a/lib/modules/manager/swift/__snapshots__/index.spec.ts.snap +++ b/lib/modules/manager/swift/__snapshots__/index.spec.ts.snap @@ -22,6 +22,12 @@ exports[`modules/manager/swift/index extractPackageFile() parses multiple packag "depName": "IBM-Swift/BlueSignals", "packageName": "https://github.com/IBM-Swift/BlueSignals.git", }, + { + "currentValue": "1.2.1", + "datasource": "git-tags", + "depName": "apple/swift-argument-parser", + "packageName": "https://github.com/apple/swift-argument-parser", + }, { "currentValue": ""UpdateSocket" ", @@ -58,87 +64,3 @@ exports[`modules/manager/swift/index extractPackageFile() parses multiple packag "packageFile": null, } `; - -exports[`modules/manager/swift/index extractPackageFile() parses package descriptions 1`] = ` -{ - "deps": [ - { - "currentValue": "from:"1.2.3"", - "datasource": "git-tags", - "depName": "vapor/vapor", - "packageName": "https://github.com/vapor/vapor.git", - }, - ], - "packageFile": null, -} -`; - -exports[`modules/manager/swift/index extractPackageFile() parses package descriptions 2`] = ` -{ - "deps": [ - { - "currentValue": ""1.2.3"...", - "datasource": "git-tags", - "depName": "vapor/vapor", - "packageName": "https://github.com/vapor/vapor.git", - }, - ], - "packageFile": null, -} -`; - -exports[`modules/manager/swift/index extractPackageFile() parses package descriptions 3`] = ` -{ - "deps": [ - { - "currentValue": ""1.2.3"..."1.2.4"", - "datasource": "git-tags", - "depName": "vapor/vapor", - "packageName": "https://github.com/vapor/vapor.git", - }, - ], - "packageFile": null, -} -`; - -exports[`modules/manager/swift/index extractPackageFile() parses package descriptions 4`] = ` -{ - "deps": [ - { - "currentValue": ""1.2.3"..<"1.2.4"", - "datasource": "git-tags", - "depName": "vapor/vapor", - "packageName": "https://github.com/vapor/vapor.git", - }, - ], - "packageFile": null, -} -`; - -exports[`modules/manager/swift/index extractPackageFile() parses package descriptions 5`] = ` -{ - "deps": [ - { - "currentValue": "..."1.2.3"", - "datasource": "git-tags", - "depName": "vapor/vapor", - "packageName": "https://github.com/vapor/vapor.git", - }, - ], - "packageFile": null, -} -`; - -exports[`modules/manager/swift/index extractPackageFile() parses package descriptions 6`] = ` -{ - "deps": [ - { - "currentValue": "..<"1.2.3"", - "datasource": "git-tags", - "depName": "vapor/vapor", - "packageName": "https://github.com/vapor/vapor.git", - }, - ], - "packageFile": null, -} -`; diff --git a/lib/modules/manager/swift/extract.ts b/lib/modules/manager/swift/extract.ts index 19f95b96a06f1c5d977cedc94517ea3a3784c11b..a2a62d61fa3ba0fd3480a85b5ca9308c327a4266 100644 --- a/lib/modules/manager/swift/extract.ts +++ b/lib/modules/manager/swift/extract.ts @@ -17,6 +17,7 @@ const regExps = { from: regEx(/from/), rangeOp: regEx(/\.\.[.<]/), exactVersion: regEx(/\.\s*exact\s*\(\s*/), + exactVersionLabel: regEx(/\s*exact:/), }; const WILDCARD = 'wildcard'; @@ -32,6 +33,7 @@ const COMMA = 'comma'; const FROM = 'from'; const RANGE_OP = 'rangeOp'; const EXACT_VERSION = 'exactVersion'; +const EXACT_VERSION_LABEL = 'exactVersionLabel'; const searchLabels = { wildcard: WILDCARD, @@ -47,6 +49,7 @@ const searchLabels = { from: FROM, rangeOp: RANGE_OP, exactVersion: EXACT_VERSION, + exactVersionLabel: EXACT_VERSION_LABEL, }; function searchKeysForState(state: string | null): (keyof typeof regExps)[] { @@ -72,11 +75,14 @@ function searchKeysForState(state: string | null): (keyof typeof regExps)[] { STRING_LITERAL, RANGE_OP, EXACT_VERSION, + EXACT_VERSION_LABEL, PACKAGE, END_SECTION, ]; case '.package(url: [depName], .exact(': return [SPACE, STRING_LITERAL, PACKAGE, END_SECTION]; + case '.package(url: [depName], exact:': + return [SPACE, STRING_LITERAL, PACKAGE, END_SECTION]; case '.package(url: [depName], from': return [SPACE, COLON, PACKAGE, END_SECTION]; case '.package(url: [depName], from:': @@ -263,6 +269,8 @@ export function extractPackageFile( state = '.package(url: [depName], [rangeFrom][rangeOp]'; } else if (label === EXACT_VERSION) { state = '.package(url: [depName], .exact('; + } else if (label === EXACT_VERSION_LABEL) { + state = '.package(url: [depName], exact:'; } else if (label === PACKAGE) { yieldDep(); state = '.package('; @@ -280,6 +288,19 @@ export function extractPackageFile( state = '.package('; } break; + case '.package(url: [depName], exact:': + if (label === END_SECTION) { + yieldDep(); + state = null; + } else if (label === STRING_LITERAL) { + currentValue = substr.slice(1, substr.length - 1); + yieldDep(); + state = 'dependencies: ['; + } else if (label === PACKAGE) { + yieldDep(); + state = '.package('; + } + break; case '.package(url: [depName], from': if (label === END_SECTION) { yieldDep(); diff --git a/lib/modules/manager/swift/index.spec.ts b/lib/modules/manager/swift/index.spec.ts index c2f1e6d748c54399c92a5299b85791b2e0658792..0cbaecbdca6759e3e2e33b1cebea3307f9849609 100644 --- a/lib/modules/manager/swift/index.spec.ts +++ b/lib/modules/manager/swift/index.spec.ts @@ -66,6 +66,16 @@ describe('modules/manager/swift/index', () => { `dependencies:[.package(url:"https://github.com/vapor/vapor.git", .exact(]` ) ).toBeNull(); + expect( + extractPackageFile( + `dependencies:[.package(url:"https://github.com/vapor/vapor.git", exact:]` + ) + ).toBeNull(); + expect( + extractPackageFile( + `dependencies:[.package(url:"https://github.com/vapor/vapor.git", exact:.package()]` + ) + ).toBeNull(); }); it('parses packages with invalid versions', () => { @@ -101,32 +111,42 @@ describe('modules/manager/swift/index', () => { extractPackageFile( `dependencies:[.package(url:"https://github.com/vapor/vapor.git",from:"1.2.3")]` ) - ).toMatchSnapshot({ deps: [{ currentValue: 'from:"1.2.3"' }] }); + ).toMatchObject({ deps: [{ currentValue: 'from:"1.2.3"' }] }); expect( extractPackageFile( `dependencies:[.package(url:"https://github.com/vapor/vapor.git","1.2.3"...)]` ) - ).toMatchSnapshot({ deps: [{ currentValue: '"1.2.3"...' }] }); + ).toMatchObject({ deps: [{ currentValue: '"1.2.3"...' }] }); expect( extractPackageFile( `dependencies:[.package(url:"https://github.com/vapor/vapor.git","1.2.3"..."1.2.4")]` ) - ).toMatchSnapshot({ deps: [{ currentValue: '"1.2.3"..."1.2.4"' }] }); + ).toMatchObject({ deps: [{ currentValue: '"1.2.3"..."1.2.4"' }] }); expect( extractPackageFile( `dependencies:[.package(url:"https://github.com/vapor/vapor.git","1.2.3"..<"1.2.4")]` ) - ).toMatchSnapshot({ deps: [{ currentValue: '"1.2.3"..<"1.2.4"' }] }); + ).toMatchObject({ deps: [{ currentValue: '"1.2.3"..<"1.2.4"' }] }); expect( extractPackageFile( `dependencies:[.package(url:"https://github.com/vapor/vapor.git",..."1.2.3")]` ) - ).toMatchSnapshot({ deps: [{ currentValue: '..."1.2.3"' }] }); + ).toMatchObject({ deps: [{ currentValue: '..."1.2.3"' }] }); expect( extractPackageFile( `dependencies:[.package(url:"https://github.com/vapor/vapor.git",..<"1.2.3")]` ) - ).toMatchSnapshot({ deps: [{ currentValue: '..<"1.2.3"' }] }); + ).toMatchObject({ deps: [{ currentValue: '..<"1.2.3"' }] }); + expect( + extractPackageFile( + `dependencies:[.package(url:"https://github.com/vapor/vapor.git",.exact("1.2.3"))]` + ) + ).toMatchObject({ deps: [{ currentValue: '1.2.3' }] }); + expect( + extractPackageFile( + `dependencies:[.package(url:"https://github.com/vapor/vapor.git",exact:"1.2.3"))]` + ) + ).toMatchObject({ deps: [{ currentValue: '1.2.3' }] }); }); it('parses multiple packages', () => { diff --git a/lib/modules/manager/swift/readme.md b/lib/modules/manager/swift/readme.md index b6ebdf8ad21110a94600f0acbd2ef6c3d42f8509..dc1c22d960531c3135478d11a583a5d7e6e4ac53 100644 --- a/lib/modules/manager/swift/readme.md +++ b/lib/modules/manager/swift/readme.md @@ -1,9 +1,11 @@ -Anything other than `.exact(<...>)` will be treated as range with respect to Swift specific. +Anything other than `.exact(<...>)` or `exact:<...>` will be treated as range with respect to Swift specific. Because of this, some PR descriptions will look like `from: <...> => <...>`. Examples: ```swift +package(name: "<...>", .exact("1.2.3")) // => 1.2.3 +package(name: "<...>", exact: "1.2.3") // => 1.2.3 package(name: "<...>", from: "1.2.3") // => from: "2.0.0" package(name: "<...>", "1.2.3"...) // => "2.0.0"... package(name: "<...>", "1.2.3"..."1.3.0") // => "1.2.3"..."2.0.0"