Skip to content

Commit

Permalink
Added version command and goreleaser (#100)
Browse files Browse the repository at this point in the history
* added version command and goreleaser

* added release to Makefile. adapted build and clean scripts to gorelease. changed version short text output

* reverted clean and build scripts. changed path for builds

* added dist field to goreleaser

* added post hook

* disabled archiving

* added archive name template

* changed archive name template

* changed archive name template

* changed goreleaser.yml

* removed pre hooks
  • Loading branch information
francismars authored Sep 21, 2020
1 parent 63bdf3c commit 5af3371
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.env

vendor/
build/
build/
dist/
25 changes: 25 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
builds:
- main: ./cli/main.go
ldflags:
- -s -w -X github.com/vulpemventures/nigiri/cli/cmd.version={{.Version}} -X github.com/vulpemventures/nigiri/cli/cmd.commit={{.Commit}} -X github.com/vulpemventures/nigiri/cli/cmd.date={{.Date}}
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
archives:
-
format: binary
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: install build-arm build-linux build-mac clean cov fmt help vet test
.PHONY: install build-arm build-linux build-mac release dry-release clean cov fmt help vet test

## install: installs dependencies
install:
Expand All @@ -24,6 +24,12 @@ build-mac:
chmod u+x ./scripts/build
./scripts/build darwin amd64

release:
goreleaser

dry-release:
goreleaser --snapshot --skip-publish --rm-dist

## clean: cleans the binary
clean:
@echo "Cleaning..."
Expand Down
8 changes: 4 additions & 4 deletions cli/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ var (
)

var RootCmd = &cobra.Command{
Use: "nigiri",
Short: "Nigiri lets you manage a full dockerized bitcoin environment",
Long: "Nigiri lets you create your dockerized environment with a bitcoin and optionally a liquid node + block explorer powered by an electrum server for every network",
Version: "0.0.5",
Use: "nigiri",
Short: "Nigiri lets you manage a full dockerized bitcoin environment",
Long: "Nigiri lets you create your dockerized environment with a bitcoin and optionally a liquid node + block explorer powered by an electrum server for every network",
}

func init() {
Expand All @@ -49,6 +48,7 @@ func init() {
RootCmd.AddCommand(RpcCmd)
RootCmd.AddCommand(MintCmd)
RootCmd.AddCommand(PushCmd)
RootCmd.AddCommand(VersionCmd)

viper.BindPFlag(constants.Datadir, RootCmd.PersistentFlags().Lookup("datadir"))
viper.BindPFlag(constants.Network, StartCmd.PersistentFlags().Lookup("network"))
Expand Down
53 changes: 53 additions & 0 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
"github.com/vulpemventures/nigiri/cli/constants"
"github.com/vulpemventures/nigiri/cli/controller"
)

var (
version = "dev"
commit = "none"
date = "unknown"
VersionCmd = &cobra.Command{
Use: "version",
Short: "Show the current version",
RunE: versionFunc,
PreRunE: versionChecks,
}
)

func versionChecks(cmd *cobra.Command, args []string) error {
datadir, _ := cmd.Flags().GetString("datadir")

ctl, err := controller.NewController()
if err != nil {
return err
}

if err := ctl.ParseDatadir(datadir); err != nil {
return err
}

if isRunning, err := ctl.IsNigiriRunning(); err != nil {
return err
} else if !isRunning {
return constants.ErrNigiriNotRunning
}

if err := ctl.ReadConfigFile(datadir); err != nil {
return err
}

return nil
}

func versionFunc(cmd *cobra.Command, address []string) error {
fmt.Println("Version: " + version)
fmt.Println("Commit: " + commit)
fmt.Println("Date: " + date)
return nil
}

0 comments on commit 5af3371

Please sign in to comment.