-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Package Registry client implementation does not support pagination using Link headers #8215
Comments
Thanks for the detailed reproduction steps, I'm seeing a failure to resolve as well. Note that swiftPM-registry-service isn't forwarding the |
@plemarquand : I am putting together a PR for swiftPM-registry-service that DOES forward the I'll update this thread once I have the PR up for swiftPM-registry-service. |
Great, thanks! I have a rough fix in progress in SPM that iterates the I used swiftPM-registry-service for testing and had to rewrite the next/last Links so they pointed back to the swiftPM-registry-service server instead of directly to GitHub in order to have the proper Accept header. If you'd like I can put up a draft PR when my patch is a bit further along and you could check it out, build it and then try to do a |
In [4.1 List Package Releases](https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#41-list-package-releases) it is stated that a server may respond with a `Link` header that contains a pointer to a subsequent page of results. SPM is not checking for this link in the `Link` header and so if a registry returns paginated results only the first page of versions is searched when resolving. Respect the `next` link in the `Link` header by loading the next page of results and building up a list of versions, continuing until there is no `next` link present in the `Link` header of the last result. Issue: swiftlang#8215
@plemarquand : sounds good. I made the same change - rewriting the Link URLs. But I am guessing your change is probably better than mine - I am a Swift developer, and this was my first venture into TypeScript. 😄 |
@plemarquand : I put up a PR in the swiftPM-registry-service repository which returns correct hollyoops/swiftPM-registry-service#2 You can test your SPM draft PR against a service running against swiftPM-registry-service running on my branch. |
In [4.1 List Package Releases](https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md#41-list-package-releases) it is stated that a server may respond with a `Link` header that contains a pointer to a subsequent page of results. SPM is not checking for this link in the `Link` header and so if a registry returns paginated results only the first page of versions is searched when resolving. Respect the `next` link in the `Link` header by loading the next page of results and building up a list of versions, continuing until there is no `next` link present in the `Link` header of the last result. Issue: swiftlang#8215
@plemarquand : thanks so much for the quick action on this! What kind of turnaround time do you typically see on:
I won't really be able to use this fix until it makes it into Xcode. |
The SPM PRs don't take too long to merge, pending review. As for when it will be released in Xcode I'm not sure. |
Is it reproducible with SwiftPM command-line tools:
swift build
,swift test
,swift package
etc?swift build
,swift test
,swift package
etc.Description
In the specification for the Swift Package Registry Service, the specification for the
GET /{scope}/{name}
endpoint says:and provides these examples of a
Link
header:However, it does not appear that the SPM Package Registry client implementation supports pagination for the
GET /{scope}/{name}
endpoint.This is a burden on Swift Package Registry Service (SPRS) implementations. For example, if you were implementing an SPRS service which proxied the Github API, you would most likely use this Github API endpoint to implement the
GET /{scope}/{name}
.Take an example of implementing
GET /{scope}/{name}
for swift-syntax.GET /swiftlang/swift-syntax
from SPM to your SPRSGET https://api.github.com/repos/swiftlang/swift-syntax/tags
per_page
which is 30, and responds with the first 30 tags. Here is theLink
header in that response:This means there are 47 pages of tags for
swift-syntax
. So since the SPM client does not support pagination, then you had to make 47 requests to the GIthub API to fetch all of the tags before you can produce a response for the SPM client.You could always use a
per_page
of 100 (which is the maximum), but that only reduces the number of requests you have to make to 14.It would be much better if the SPRS could respond with its own
Link
header to theGET /{scope}/{name}
response and the SPM client would respect that and make multipleGET /{scope}/{name}
calls in order to fetch all of the package releases (tags).When you request
GET https://api.github.com/repos/swiftlang/swift-syntax/tags
That endpoint has a maximum
per_page
of 100meaning that for repositories with a LOT of tags (like swift-syntax), then your implementation would have to makeExpected behavior
I would expect the SPM Package Registry client to respect the
Link
header withnext
,last
attributes and make multiple requests to theGET /{scope}/{name}
endpoint in order to fetch all of the tags.Actual behavior
The SPM Package Registry client makes ONE request to
GET /{scope}/{name}
. If the expected tag is not in that first page of tags, then package resolution fails.Steps to reproduce
npm install
set GITHUB_ACCESS_TOKEN="Your github token" && npm start
swift package-registry set --global http://127.0.0.1:3001
Package.swift
which depends onswiftlang.swift-syntax
with tag600.0.1
(the latest version)600.0.1
Swift Package Manager version/commit hash
6.0.0-dev
Swift & OS version (output of
swift --version ; uname -a
)The text was updated successfully, but these errors were encountered: