Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,51 @@ builds:
- -X github.com/altuslabsxyz/devnet-builder/internal.Version={{.Version}}
- -X github.com/altuslabsxyz/devnet-builder/internal.GitCommit={{.FullCommit}}
- -X github.com/altuslabsxyz/devnet-builder/internal.BuildDate={{.Date}}
- -X github.com/altuslabsxyz/devnet-builder/internal/version.Version={{.Version}}
- -X github.com/altuslabsxyz/devnet-builder/internal/version.GitCommit={{.FullCommit}}
- -X github.com/altuslabsxyz/devnet-builder/internal/version.BuildDate={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"

- id: devnetd
main: ./cmd/devnetd
binary: devnetd
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- -s -w
- -X github.com/altuslabsxyz/devnet-builder/internal.Version={{.Version}}
- -X github.com/altuslabsxyz/devnet-builder/internal.GitCommit={{.FullCommit}}
- -X github.com/altuslabsxyz/devnet-builder/internal.BuildDate={{.Date}}
- -X github.com/altuslabsxyz/devnet-builder/internal/version.Version={{.Version}}
- -X github.com/altuslabsxyz/devnet-builder/internal/version.GitCommit={{.FullCommit}}
- -X github.com/altuslabsxyz/devnet-builder/internal/version.BuildDate={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"

- id: dvb
main: ./cmd/dvb
binary: dvb
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- -s -w
- -X github.com/altuslabsxyz/devnet-builder/internal.Version={{.Version}}
- -X github.com/altuslabsxyz/devnet-builder/internal.GitCommit={{.FullCommit}}
- -X github.com/altuslabsxyz/devnet-builder/internal.BuildDate={{.Date}}
- -X github.com/altuslabsxyz/devnet-builder/internal/version.Version={{.Version}}
- -X github.com/altuslabsxyz/devnet-builder/internal/version.GitCommit={{.FullCommit}}
- -X github.com/altuslabsxyz/devnet-builder/internal/version.BuildDate={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"

universal_binaries:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ GIT_COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
BUILD_DATE ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')

# ldflags for version injection
# Inject to both internal and internal/version for backwards compatibility
LDFLAGS = -X github.com/altuslabsxyz/devnet-builder/internal.Version=$(VERSION) \
-X github.com/altuslabsxyz/devnet-builder/internal.GitCommit=$(GIT_COMMIT) \
-X github.com/altuslabsxyz/devnet-builder/internal.BuildDate=$(BUILD_DATE)
-X github.com/altuslabsxyz/devnet-builder/internal.BuildDate=$(BUILD_DATE) \
-X github.com/altuslabsxyz/devnet-builder/internal/version.Version=$(VERSION) \
-X github.com/altuslabsxyz/devnet-builder/internal/version.GitCommit=$(GIT_COMMIT) \
-X github.com/altuslabsxyz/devnet-builder/internal/version.BuildDate=$(BUILD_DATE)

# Default target
.DEFAULT_GOAL := build
Expand Down
91 changes: 47 additions & 44 deletions cmd/devnet-builder/commands/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,73 @@ package core
import (
"encoding/json"
"fmt"
"runtime"
"strings"

"github.com/altuslabsxyz/devnet-builder/internal"
"github.com/altuslabsxyz/devnet-builder/internal/infrastructure/network"
"github.com/altuslabsxyz/devnet-builder/internal/version"
"github.com/altuslabsxyz/devnet-builder/types/ctxconfig"
"github.com/spf13/cobra"
)

// VersionInfo contains version details.
type VersionInfo struct {
Version string `json:"version"`
GitCommit string `json:"git_commit"`
BuildDate string `json:"build_date"`
GoVersion string `json:"go_version"`
Platform string `json:"platform"`
BuildNetworks string `json:"build_networks"`
Networks []string `json:"networks"` // Actual registered networks
// ExtendedVersionInfo contains version details with network plugin info.
type ExtendedVersionInfo struct {
version.Info `yaml:",inline"`
Networks []string `json:"networks,omitempty" yaml:"networks,omitempty"`
}

// NewVersionCmd creates the version command.
func NewVersionCmd() *cobra.Command {
var long bool

cmd := &cobra.Command{
Use: "version",
Short: "Show version information",
Long: "Show version information including build details.",
RunE: runVersion,
}
Long: "Show version information including build details. Use --long for detailed dependency info.",
RunE: func(cmd *cobra.Command, args []string) error {
cfg := ctxconfig.FromContext(cmd.Context())
jsonMode := cfg.JSONMode()

return cmd
}
// Get actual registered networks
registeredNetworks := network.List()

func runVersion(cmd *cobra.Command, args []string) error {
cfg := ctxconfig.FromContext(cmd.Context())
jsonMode := cfg.JSONMode()
// Create base version info
info := version.NewInfo("devnet-builder", "devnet-builder")
if long {
info = info.WithBuildDeps()
}

// Get actual registered networks
registeredNetworks := network.List()
// Extend with network info
extInfo := ExtendedVersionInfo{
Info: info,
Networks: registeredNetworks,
}

info := VersionInfo{
Version: internal.Version,
GitCommit: internal.GitCommit,
BuildDate: internal.BuildDate,
GoVersion: runtime.Version(),
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
BuildNetworks: "plugin-based",
Networks: registeredNetworks,
}
if jsonMode {
data, err := json.MarshalIndent(extInfo, "", " ")
if err != nil {
return err
}
fmt.Println(string(data))
return nil
}

if long {
fmt.Print(extInfo.Info.LongString())
if len(registeredNetworks) > 0 {
fmt.Printf("networks: %s\n", strings.Join(registeredNetworks, ", "))
}
} else {
fmt.Print(extInfo.Info.String())
if len(registeredNetworks) > 0 {
fmt.Printf(" networks: %s\n", strings.Join(registeredNetworks, ", "))
}
}

if jsonMode {
data, err := json.MarshalIndent(info, "", " ")
if err != nil {
return err
}
fmt.Println(string(data))
return nil
return nil
},
}

fmt.Printf("devnet-builder %s\n", info.Version)
fmt.Printf(" Git commit: %s\n", info.GitCommit)
fmt.Printf(" Build date: %s\n", info.BuildDate)
fmt.Printf(" Go version: %s\n", info.GoVersion)
fmt.Printf(" Platform: %s\n", info.Platform)
fmt.Printf(" Networks: %s\n", strings.Join(registeredNetworks, ", "))
cmd.Flags().BoolVar(&long, "long", false, "Show detailed version info including build dependencies")

return nil
return cmd
}
4 changes: 4 additions & 0 deletions cmd/devnetd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

"github.com/altuslabsxyz/devnet-builder/internal/daemon/server"
"github.com/altuslabsxyz/devnet-builder/internal/version"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -35,6 +36,9 @@ func main() {
rootCmd.Flags().BoolVar(&config.EnableDocker, "docker", false, "Enable Docker container runtime")
rootCmd.Flags().StringVar(&config.DockerImage, "docker-image", "stablelabs/stabled:latest", "Default Docker image for nodes")

// Add version command
rootCmd.AddCommand(version.NewCmd("devnet-builder", "devnetd"))

if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
Expand Down
45 changes: 40 additions & 5 deletions cmd/dvb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

v1 "github.com/altuslabsxyz/devnet-builder/api/proto/gen/v1"
"github.com/altuslabsxyz/devnet-builder/internal/client"
"github.com/altuslabsxyz/devnet-builder/internal/version"
"github.com/fatih/color"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -77,18 +78,52 @@ func main() {
}

func newVersionCmd() *cobra.Command {
return &cobra.Command{
var (
long bool
jsonOutput bool
)

cmd := &cobra.Command{
Use: "version",
Short: "Print version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("dvb version 0.1.0")
Long: "Print version information including build details. Use --long for detailed dependency info.",
RunE: func(cmd *cobra.Command, args []string) error {
info := version.NewInfo("devnet-builder", "dvb")

if long {
info = info.WithBuildDeps()
}

if jsonOutput {
output, err := info.JSON()
if err != nil {
return err
}
fmt.Println(output)
return nil
}

if long {
fmt.Print(info.LongString())
} else {
fmt.Print(info.String())
}

// Show connection mode (dvb-specific feature)
if daemonClient != nil {
fmt.Println("Mode: daemon")
fmt.Println("mode: daemon")
} else {
fmt.Println("Mode: standalone")
fmt.Println("mode: standalone")
}

return nil
},
}

cmd.Flags().BoolVar(&long, "long", false, "Show detailed version info including build dependencies")
cmd.Flags().BoolVar(&jsonOutput, "json", false, "Output version info in JSON format")

return cmd
}

func newDaemonCmd() *cobra.Command {
Expand Down
Loading
Loading