Skip to content
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

feat: add gno version command #3002

Merged
merged 22 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
5 changes: 4 additions & 1 deletion gnovm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ GOTEST_FLAGS ?= -v -p 1 -timeout=30m
GNOROOT_DIR ?= $(abspath $(lastword $(MAKEFILE_LIST))/../../)
# We can't use '-trimpath' yet as amino use absolute path from call stack
# to find some directory: see #1236
GOBUILD_FLAGS ?= -ldflags "-X github.com/gnolang/gno/gnovm/pkg/gnoenv._GNOROOT=$(GNOROOT_DIR)"
GOBUILD_FLAGS ?= -ldflags "-X github.com/gnolang/gno/gnovm/pkg/version.Version=$(VERSION) -X github.com/gnolang/gno/gnovm/pkg/gnoenv._GNOROOT=$(GNOROOT_DIR)"
# file where to place cover profile; used for coverage commands which are
# more complex than adding -coverprofile, like test.cmd.coverage.
GOTEST_COVER_PROFILE ?= cmd-profile.out

# user for gno version [branch].[N]+[hash]
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || echo "$(shell git rev-parse --abbrev-ref HEAD).$(shell git rev-list --count HEAD)+$(shell git rev-parse --short HEAD)")

########################################
# Dev tools
.PHONY: build
Expand Down
1 change: 1 addition & 0 deletions gnovm/cmd/gno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func newGnocliCmd(io commands.IO) *commands.Command {
newTestCmd(io),
newToolCmd(io),
// version -- show cmd/gno, golang versions
newGnoVersionCmd(io),
// vet
)

Expand Down
24 changes: 24 additions & 0 deletions gnovm/cmd/gno/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"context"

"github.com/gnolang/gno/gnovm/pkg/version"
"github.com/gnolang/gno/tm2/pkg/commands"
)

// newVersionCmd creates a new version command
func newGnoVersionCmd(io commands.IO) *commands.Command {
return commands.NewCommand(
commands.Metadata{
Name: "version",
ShortUsage: "version",
ShortHelp: "display installed gno version",
},
nil,
func(_ context.Context, args []string) error {
io.Println("gno version:", version.Version)
return nil
},
)
}
32 changes: 32 additions & 0 deletions gnovm/cmd/gno/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"testing"

"github.com/gnolang/gno/gnovm/pkg/version"
)

func TestVersionApp(t *testing.T) {
originalVersion := version.Version

t.Cleanup(func() {
version.Version = originalVersion
})

versionValues := []string{"chain/test4.2", "develop", "master"}

testCases := make([]testMainCase, len(versionValues))
for i, v := range versionValues {
testCases[i] = testMainCase{
args: []string{"version"},
stdoutShouldContain: "gno version: " + v,
}
}

for i, testCase := range testCases {
t.Run(versionValues[i], func(t *testing.T) {
version.Version = versionValues[i]
testMainCaseRun(t, []testMainCase{testCase})
})
}
}
3 changes: 3 additions & 0 deletions gnovm/pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

var Version = "develop"
Loading