Skip to content

Commit

Permalink
add good support for package shortname (no version, etc.) to run/gui/…
Browse files Browse the repository at this point in the history
…info
  • Loading branch information
sduchesneau committed Nov 12, 2024
1 parent e2f145e commit 883e29f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
9 changes: 8 additions & 1 deletion cmd/substreams/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/streamingfast/cli"
"github.com/streamingfast/cli/sflags"
"github.com/streamingfast/substreams/info"
"github.com/streamingfast/substreams/manifest"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -58,7 +59,13 @@ func runInfo(cmd *cobra.Command, args []string) error {
return fmt.Errorf("used-modules-only flag requires the output_module arg to be set")
}

pkgInfo, err := info.Extended(manifestPath, outputModule, skipPackageValidation)
opts := []manifest.Option{
manifest.WithRegistryURL(getSubstreamsRegistryEndpoint()),
}
if skipPackageValidation {
opts = append(opts, manifest.SkipPackageValidationReader())
}
pkgInfo, err := info.Extended(manifestPath, outputModule, opts...)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

* Commands `run`, `gui` and `info` now accept the new standard package definition (ex: `ethereum-common@latest`) to reference an spkg file from https://substreams.dev
* Changed `substreams run`: the two positional parameters now align with `gui`: `[package [module_name]]`. Before, it was using fuzzy heuristics to see if a single param was a module name or a package name. You need to be more explicit now, like `gui`.
* Added `substreams publish` to `publish` a package on the substreams registry (check on `https://substreams.dev`).
* Added `substreams registry` to `login` and `publish` on the substreams registry (check on `https://substreams.dev`).
Expand Down
6 changes: 1 addition & 5 deletions info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,7 @@ func Basic(pkg *pbsubstreams.Package, graph *manifest.ModuleGraph) (*BasicInfo,
return manifestInfo, nil
}

func Extended(manifestPath string, outputModule string, skipValidation bool) (*ExtendedInfo, error) {
var opts []manifest.Option
if skipValidation {
opts = append(opts, manifest.SkipPackageValidationReader())
}
func Extended(manifestPath string, outputModule string, opts ...manifest.Option) (*ExtendedInfo, error) {
reader, err := manifest.NewReader(manifestPath, opts...)
if err != nil {
return nil, fmt.Errorf("manifest reader: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion info/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestBasicInfo(t *testing.T) {
}

func TestExtendedInfo(t *testing.T) {
info, err := Extended("https://github.com/streamingfast/substreams-uniswap-v3/releases/download/v0.2.8/substreams.spkg", "graph_out", false)
info, err := Extended("https://github.com/streamingfast/substreams-uniswap-v3/releases/download/v0.2.8/substreams.spkg", "graph_out", nil)
require.NoError(t, err)

r, err := json.MarshalIndent(info, "", " ")
Expand Down
30 changes: 25 additions & 5 deletions manifest/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@ func (r *Reader) resolveInputPath() error {
return nil
}

if r.IsSpkgVersionStandardPackage(input) {
parts := strings.Split(input, "@")
pkgName, version, err := r.ParseStandardPackageAndVersion(input)
if err == nil {
registryURL := r.registryURL
if registryURL == "" {
// This is an extreme fallback, because this should be
// set by the WithRegistryURL option.
registryURL = "https://spkg.io"
}
r.currentInput = fmt.Sprintf("%s/v1/packages/%s/%s", registryURL, parts[0], parts[1])
r.currentInput = fmt.Sprintf("%s/v1/packages/%s/%s", registryURL, pkgName, version)
return nil
}

Expand Down Expand Up @@ -601,8 +601,28 @@ func (r *Reader) IsRemotePackage(input string) bool {
return hasRemotePrefix(input)
}

func (r *Reader) IsSpkgVersionStandardPackage(input string) bool {
return strings.Contains(input, "@")
func (r *Reader) ParseStandardPackageAndVersion(input string) (packageName, version string, err error) {
parts := strings.Split(input, "@")
if len(parts) > 2 {
return "", "", fmt.Errorf("too many '@' in package name: %s", input)
}

packageName = parts[0]
if !moduleNameRegexp.MatchString(packageName) {
return "", "", fmt.Errorf("package name %s does not match regexp %s", packageName, moduleNameRegexp.String())
}

if len(parts) == 1 || parts[1] == "" || parts[1] == "latest" {
version = "latest"
return
}

if !semver.IsValid(parts[1]) {
return "", "", fmt.Errorf("version %q is not valid Semver format", parts[1])
}
version = parts[1]

return
}

// IsLocalManifest determines if reader's input to read the manifest is a local manifest file, which is determined
Expand Down

0 comments on commit 883e29f

Please sign in to comment.