-
Notifications
You must be signed in to change notification settings - Fork 249
[search] Update search endpoints #1249
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
Changes from all commits
1252ed6
08029df
f0255f8
5c5d3ba
38be343
4c944ac
099cffa
bc74922
8f81a4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,9 @@ | |
"version": "1.6.23" | ||
}, | ||
"[email protected]": { | ||
"last_modified": "2023-05-01T16:53:22Z", | ||
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#go", | ||
"version": "1.20.3" | ||
"last_modified": "2023-05-25T03:54:59Z", | ||
"resolved": "github:NixOS/nixpkgs/8d4d822bc0efa9de6eddc79cb0d82897a9baa750#go", | ||
"version": "1.20.4" | ||
}, | ||
"[email protected]": { | ||
"last_modified": "2023-05-01T16:53:22Z", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2023 Jetpack Technologies Inc and contributors. All rights reserved. | ||
// Use of this source code is governed by the license in the LICENSE file. | ||
|
||
package lock | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"go.jetpack.io/devbox/internal/boxcli/featureflag" | ||
"go.jetpack.io/devbox/internal/boxcli/usererr" | ||
"go.jetpack.io/devbox/internal/nix" | ||
"go.jetpack.io/devbox/internal/searcher" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
// FetchResolvedPackage fetches a resolution but does not write it to the lock | ||
// struct. This allows testing new versions of packages without writing to the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how and why would one test new versions of packages? |
||
// lock. This is useful to avoid changing nixpkgs commit hashes when version has | ||
// not changed. This can happen when doing `devbox update` and search has | ||
// a newer hash than the lock file but same version. In that case we don't want | ||
// to update because it would be slow and wasteful. | ||
func (l *File) FetchResolvedPackage(pkg string) (*Package, error) { | ||
name, version, _ := searcher.ParseVersionedPackage(pkg) | ||
if version == "" { | ||
return nil, usererr.New("No version specified for %q.", name) | ||
} | ||
|
||
packageVersion, err := searcher.Client().Resolve(name, version) | ||
if err != nil { | ||
return nil, errors.Wrapf(nix.ErrPackageNotFound, "%s@%s", name, version) | ||
} | ||
|
||
sysInfos := map[string]*SystemInfo{} | ||
if featureflag.RemoveNixpkgs.Enabled() { | ||
sysInfos = buildLockSystemInfos(packageVersion) | ||
} | ||
packageInfo, err := selectForSystem(packageVersion) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(packageInfo.AttrPaths) == 0 { | ||
return nil, fmt.Errorf("no attr paths found for package %q", name) | ||
} | ||
|
||
return &Package{ | ||
LastModified: time.Unix(int64(packageInfo.LastUpdated), 0).UTC(). | ||
Format(time.RFC3339), | ||
Resolved: fmt.Sprintf( | ||
"github:NixOS/nixpkgs/%s#%s", | ||
packageInfo.CommitHash, | ||
packageInfo.AttrPaths[0], | ||
), | ||
Version: packageInfo.Version, | ||
Systems: sysInfos, | ||
}, nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, wow, this is much cleaner than the old code! Also, a 100 bonus points for having the |
||
|
||
func selectForSystem(pkg *searcher.PackageVersion) (searcher.PackageInfo, error) { | ||
currentSystem, err := nix.System() | ||
if err != nil { | ||
return searcher.PackageInfo{}, err | ||
} | ||
if pi, ok := pkg.Systems[currentSystem]; ok { | ||
return pi, nil | ||
} | ||
if pi, ok := pkg.Systems["x86_64-linux"]; ok { | ||
return pi, nil | ||
} | ||
if len(pkg.Systems) == 0 { | ||
return searcher.PackageInfo{}, | ||
fmt.Errorf("no systems found for package %q", pkg.Name) | ||
} | ||
return maps.Values(pkg.Systems)[0], nil | ||
} | ||
|
||
func buildLockSystemInfos(pkg *searcher.PackageVersion) map[string]*SystemInfo { | ||
sysInfos := map[string]*SystemInfo{} | ||
for sysName, sysInfo := range pkg.Systems { | ||
sysInfos[sysName] = &SystemInfo{ | ||
System: sysName, | ||
FromHash: sysInfo.StoreHash, | ||
StoreName: sysInfo.StoreName, | ||
StoreVersion: sysInfo.StoreVersion, | ||
} | ||
} | ||
return sysInfos | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the Test Plan, it would be good to copy-paste examples of the output from this function. It's hard to imagine in my head...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of get it...but for future PRs, consider this a request.