-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(e2e): parse go mod for babylond version (#67)
Ensures that our e2e tests version use a correct version of babylond from go.mod
- Loading branch information
Showing
4 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package testutil | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/mod/modfile" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// GetBabylonVersion returns babylond version from go.mod | ||
func GetBabylonVersion() (string, error) { | ||
goModPath := filepath.Join("..", "go.mod") | ||
data, err := os.ReadFile(goModPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Parse the go.mod file | ||
modFile, err := modfile.Parse("go.mod", data, nil) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
const modName = "github.com/babylonlabs-io/babylon" | ||
for _, require := range modFile.Require { | ||
if require.Mod.Path == modName { | ||
return require.Mod.Version, nil | ||
} | ||
} | ||
|
||
return "", fmt.Errorf("module %s not found", modName) | ||
} |