Skip to content

[Collections] Support 'v' prefix in version #3495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Fixtures/Collections/GitHub/releases.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,78 @@
[
{
"url": "https://api.github.com/repos/octocat/Hello-World/releases/1",
"html_url": "https://github.com/octocat/Hello-World/releases/v1.0.0",
"assets_url": "https://api.github.com/repos/octocat/Hello-World/releases/1/assets",
"upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}",
"tarball_url": "https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0",
"zipball_url": "https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0",
"id": 1,
"node_id": "MDc6UmVsZWFzZTE=",
"tag_name": "v2.0.0",
"target_commitish": "master",
"name": "2.0.0",
"body": "Description of the release",
"draft": false,
"prerelease": false,
"created_at": "2013-02-27T19:35:32Z",
"published_at": "2013-02-27T19:35:32Z",
"author": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"assets": [
{
"url": "https://api.github.com/repos/octocat/Hello-World/releases/assets/1",
"browser_download_url": "https://github.com/octocat/Hello-World/releases/download/v1.0.0/example.zip",
"id": 1,
"node_id": "MDEyOlJlbGVhc2VBc3NldDE=",
"name": "example.zip",
"label": "short description",
"state": "uploaded",
"content_type": "application/zip",
"size": 1024,
"download_count": 42,
"created_at": "2013-02-27T19:35:32Z",
"updated_at": "2013-02-27T19:35:32Z",
"uploader": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
}
}
]
},
{
"url": "https://api.github.com/repos/octocat/Hello-World/releases/1",
"html_url": "https://github.com/octocat/Hello-World/releases/v1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion Fixtures/Collections/JSON/good.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"defaultToolsVersion": "5.2"
},
{
"version": "1.8.3",
"version": "v1.8.3",
"manifests": {
"5.0": {
"toolsVersion": "5.0",
Expand Down
2 changes: 1 addition & 1 deletion Fixtures/Collections/JSON/good_signed.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"defaultToolsVersion": "5.2"
},
{
"version": "1.8.3",
"version": "v1.8.3",
"manifests": {
"5.0": {
"toolsVersion": "5.0",
Expand Down
3 changes: 2 additions & 1 deletion Sources/Basics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ add_library(Basics
JSON+Extensions.swift
Sandbox.swift
SwiftVersion.swift
SQLiteBackedCache.swift)
SQLiteBackedCache.swift
Version+Extensions.swift)
target_link_libraries(Basics PUBLIC
TSCBasic
TSCUtility)
Expand Down
24 changes: 24 additions & 0 deletions Sources/Basics/Version+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import TSCUtility

extension Version {
/// Try a version from a git tag.
///
/// - Parameter tag: A version string possibly prepended with "v".
public init?(tag: String) {
if tag.first == "v" {
self.init(string: String(tag.dropFirst()))
} else {
self.init(string: tag)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import TSCBasic

import Basics
import PackageCollectionsModel
import PackageModel

Expand Down Expand Up @@ -89,7 +90,7 @@ extension PackageCollectionModel.V1 {

var nonSemanticVersions = [String]()
let semanticVersions: [TSCUtility.Version] = package.versions.compactMap {
let semver = TSCUtility.Version(string: $0.version)
let semver = TSCUtility.Version(tag: $0.version)
if semver == nil {
nonSemanticVersions.append($0.version)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct GitHubPackageMetadataProvider: PackageMetadataProvider {
keywords: metadata.topics,
// filters out non-semantic versioned tags
versions: releases.compactMap {
guard let version = $0.tagName.flatMap(TSCUtility.Version.init(string:)) else {
guard let version = $0.tagName.flatMap(TSCUtility.Version.init(tag:)) else {
return nil
}
return Model.PackageBasicVersionMetadata(version: version, title: $0.name, summary: $0.body, createdAt: $0.createdAt, publishedAt: $0.publishedAt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ struct JSONPackageCollectionProvider: PackageCollectionProvider {
let packages = collection.packages.map { package -> Model.Package in
let versions = package.versions.compactMap { version -> Model.Package.Version? in
// note this filters out / ignores missing / bad data in attempt to make the most out of the provided set
guard let parsedVersion = TSCUtility.Version(string: version.version) else {
guard let parsedVersion = TSCUtility.Version(tag: version.version) else {
return nil
}

Expand Down
15 changes: 1 addition & 14 deletions Sources/PackageGraph/RepositoryPackageContainer.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -437,16 +437,3 @@ extension Git {
}
}
}

extension Version {
/// Try a version from a git tag.
///
/// - Parameter tag: A version string possibly prepended with "v".
init?(tag: String) {
if tag.first == "v" {
self.init(string: String(tag.dropFirst()))
} else {
self.init(string: tag)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,13 @@ class GitHubPackageMetadataProviderTests: XCTestCase {
let metadata = try tsc_await { callback in provider.get(reference, callback: callback) }

XCTAssertEqual(metadata.summary, "This your first repo!")
XCTAssertEqual(metadata.versions.count, 1)
XCTAssertEqual(metadata.versions[0].version, TSCUtility.Version("1.0.0"))
XCTAssertEqual(metadata.versions[0].title, "1.0.0")
XCTAssertEqual(metadata.versions.count, 2)
XCTAssertEqual(metadata.versions[0].version, TSCUtility.Version(tag: "v2.0.0"))
XCTAssertEqual(metadata.versions[0].title, "2.0.0")
XCTAssertEqual(metadata.versions[0].summary, "Description of the release")
XCTAssertEqual(metadata.versions[1].version, TSCUtility.Version("1.0.0"))
XCTAssertEqual(metadata.versions[1].title, "1.0.0")
XCTAssertEqual(metadata.versions[1].summary, "Description of the release")
XCTAssertEqual(metadata.authors, [PackageCollectionsModel.Package.Author(username: "octocat",
url: URL(string: "https://api.github.com/users/octocat")!,
service: .init(name: "GitHub"))])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
XCTAssertEqual(collection.keywords, ["sample package collection"])
XCTAssertEqual(collection.createdBy?.name, "Jane Doe")
XCTAssertEqual(collection.packages.count, 2)

let package = collection.packages.first!
XCTAssertEqual(package.repository, .init(url: "https://www.example.com/repos/RepoOne.git"))
XCTAssertEqual(package.summary, "Package One")
Expand All @@ -75,6 +76,9 @@ class JSONPackageCollectionProviderTests: XCTestCase {
XCTAssertEqual(version.license, .init(type: .Apache2_0, url: URL(string: "https://www.example.com/repos/RepoOne/LICENSE")!))
XCTAssertNotNil(version.createdAt)
XCTAssertFalse(collection.isSigned)

// "1.8.3" is originally "v1.8.3"
XCTAssertEqual(["2.1.0", "1.8.3"], collection.packages[1].versions.map { $0.version.description })
}
}

Expand All @@ -94,6 +98,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
XCTAssertEqual(collection.keywords, ["sample package collection"])
XCTAssertEqual(collection.createdBy?.name, "Jane Doe")
XCTAssertEqual(collection.packages.count, 2)

let package = collection.packages.first!
XCTAssertEqual(package.repository, .init(url: "https://www.example.com/repos/RepoOne.git"))
XCTAssertEqual(package.summary, "Package One")
Expand All @@ -113,6 +118,9 @@ class JSONPackageCollectionProviderTests: XCTestCase {
XCTAssertEqual(version.verifiedCompatibility!.first!.swiftVersion, SwiftLanguageVersion(string: "5.1")!)
XCTAssertEqual(version.license, .init(type: .Apache2_0, url: URL(string: "https://www.example.com/repos/RepoOne/LICENSE")!))
XCTAssertFalse(collection.isSigned)

// "1.8.3" is originally "v1.8.3"
XCTAssertEqual(["2.1.0", "1.8.3"], collection.packages[1].versions.map { $0.version.description })
}
}

Expand Down Expand Up @@ -386,6 +394,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
XCTAssertEqual(collection.keywords, ["sample package collection"])
XCTAssertEqual(collection.createdBy?.name, "Jane Doe")
XCTAssertEqual(collection.packages.count, 2)

let package = collection.packages.first!
XCTAssertEqual(package.repository, .init(url: "https://www.example.com/repos/RepoOne.git"))
XCTAssertEqual(package.summary, "Package One")
Expand All @@ -411,6 +420,9 @@ class JSONPackageCollectionProviderTests: XCTestCase {
XCTAssertTrue(signature.isVerified)
XCTAssertEqual("Sample Subject", signature.certificate.subject.commonName)
XCTAssertEqual("Sample Issuer", signature.certificate.issuer.commonName)

// "1.8.3" is originally "v1.8.3"
XCTAssertEqual(["2.1.0", "1.8.3"], collection.packages[1].versions.map { $0.version.description })
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2020 Apple Inc. and the Swift project authors
Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -42,6 +42,23 @@ class PackageCollectionValidationTests: XCTestCase {
license: nil,
createdAt: nil
),
Model.Collection.Package.Version(
version: "v1.3.0",
summary: nil,
manifests: [
"5.2": Model.Collection.Package.Version.Manifest(
toolsVersion: "5.2",
packageName: "Foobar",
targets: [.init(name: "Foo", moduleName: "Foo")],
products: [.init(name: "Bar", type: .library(.automatic), targets: ["Foo"])],
minimumPlatformVersions: nil
),
],
defaultToolsVersion: "5.2",
verifiedCompatibility: nil,
license: nil,
createdAt: nil
),
],
readmeURL: nil,
license: nil
Expand Down Expand Up @@ -245,7 +262,7 @@ class PackageCollectionValidationTests: XCTestCase {
keywords: ["test package"],
versions: [
Model.Collection.Package.Version(
version: "v1.3.2",
version: "x1.3.2",
summary: nil,
manifests: [
"5.2": Model.Collection.Package.Version.Manifest(
Expand Down