Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

feat: add version and Makefile #37

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
VERSION ?= "$(shell git describe --tags --abbrev=0 | cut -c2-)"
COMMIT_HASH ?= "$(shell git describe --long --dirty --always --match "" || true)"

LDFLAGS ?= -s -w \
-X github.com/primevprotocol/mev-commit.version="$(VERSION)" \
-X github.com/primevprotocol/mev-commit.commitHash="$(COMMIT_HASH)"

.PHONY: build
build: bin
go build -ldflags '$(LDFLAGS)' -o bin/mev-commit ./cmd
aloknerurkar marked this conversation as resolved.
Show resolved Hide resolved

bin:
mkdir $@
26 changes: 21 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"io"
"log/slog"
"os"
"path/filepath"
"strings"
"time"

"github.com/ethereum/go-ethereum/crypto"
mevcommit "github.com/primevprotocol/mev-commit"
"github.com/primevprotocol/mev-commit/pkg/node"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v2"
Expand All @@ -30,12 +33,13 @@ var (

func main() {
app := &cli.App{
Name: "mev-commit",
Usage: "Entry point for mev-commit",
Name: "mev-commit",
Usage: "Entry point for mev-commit",
Version: mevcommit.Version(),
Commands: []*cli.Command{
{
Name: "start",
Usage: "Start mev-commit",
Usage: "Start the mev-commit node",
Flags: []cli.Flag{
optionConfig,
},
Expand All @@ -44,7 +48,9 @@ func main() {
},
},
{
Name: "create-key",
Name: "create-key",
Usage: "Create a new ECDSA private key and save it to a file",
ArgsUsage: "<output_file>",
Action: func(c *cli.Context) error {
return createKey(c)
},
Expand Down Expand Up @@ -154,7 +160,17 @@ func start(c *cli.Context) error {
return fmt.Errorf("failed to create logger: %w", err)
}

privKey, err := crypto.LoadECDSA(cfg.PrivKeyFile)
privKeyFile := cfg.PrivKeyFile
if strings.HasPrefix(privKeyFile, "~/") {
homeDir, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("failed to get user home directory: %w", err)
}

privKeyFile = filepath.Join(homeDir, privKeyFile[2:])
}

privKey, err := crypto.LoadECDSA(privKeyFile)
if err != nil {
return fmt.Errorf("failed to load private key from file '%s': %w", cfg.PrivKeyFile, err)
}
Expand Down
14 changes: 14 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package mevcommit

var (
version string
commitHash string
)

// Version returns the version of the binary.
func Version() string {
if version == "" || commitHash == "" {
return "dev-dirty"
}
return version + "-" + commitHash
}