From 88b17cbe9950d9972535d2188c1e4e09102fc6da Mon Sep 17 00:00:00 2001 From: Pantani Date: Mon, 22 Mar 2021 20:44:27 -0300 Subject: [PATCH] add release distribution with Goreleaser (https://goreleaser.com) --- .github/workflows/release.yml | 29 ++++++++++++++++++++++++++++ .goreleaser.yml | 36 +++++++++++++++++++++++++++++++++++ Makefile | 12 ++++++------ README.md | 4 ++-- cli/node/main.go | 20 +++++++++---------- 5 files changed, 83 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6c0ae4a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: goreleaser + +on: + push: + tags: + - '*' + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..8f5efec --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,36 @@ +before: + hooks: + - go mod download + +builds: + - main: ./cli/node/main.go + binary: node + id: node + goos: + - linux + - darwin + - windows + hooks: + pre: make migration-pack + post: make migration-clean + +archives: + - replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ .Tag }}-next" + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/Makefile b/Makefile index 9544cc3..97489e0 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ # Project variables. PACKAGE := github.com/hermeznetwork/hermez-node VERSION := $(shell git describe --tags --always) -BUILD := $(shell git rev-parse --short HEAD) -BUILD_DATE := $(shell date +%Y-%m-%dT%H:%M:%S%z) +COMMIT := $(shell git rev-parse --short HEAD) +DATE := $(shell date +%Y-%m-%dT%H:%M:%S%z) PROJECT_NAME := $(shell basename "$(PWD)") # Go related variables. @@ -23,7 +23,7 @@ CONFIG ?= $(GOBASE)/cli/node/cfg.buidler.toml POSTGRES_PASS ?= yourpasswordhere # Use linker flags to provide version/build settings. -LDFLAGS=-ldflags "-X=main.Version=$(VERSION) -X=main.Build=$(BUILD) -X=main.Date=$(BUILD_DATE)" +LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)" # PID file will keep the process id of the server. PID_PROOF_MOCK := /tmp/.$(PROJECT_NAME).proof.pid @@ -94,11 +94,11 @@ install: @echo " > Checking if there is any missing dependencies..." $(GOENVVARS) go get $(GOCMD)/... $(get) -## run: Run Hermez node. -run: +## run-node: Run Hermez node. +run-node: @bash -c "$(MAKE) clean build" @echo " > Running $(PROJECT_NAME)" - @$(GOBIN)/$(GOBINARY) --mode $(MODE) --cfg $(CONFIG) run + @$(GOBIN)/$(GOBINARY) run --mode $(MODE) --cfg $(CONFIG) ## run-proof-mock: Run proof server mock API. run-proof-mock: stop-proof-mock diff --git a/README.md b/README.md index 12b0a21..38e0673 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,13 @@ there are more information about the config file into [cli/node/README.md](cli/n After setting the config, you can build and run the Hermez Node as a synchronizer: ```shell -$ make run +$ make run-node ``` Or build and run as a coordinator, and also passing the config file from other location: ```shell -$ MODE=sync CONFIG=cli/node/cfg.buidler.toml make run +$ MODE=sync CONFIG=cli/node/cfg.buidler.toml make run-node ``` To check the useful make commands: diff --git a/cli/node/main.go b/cli/node/main.go index e294d84..9f5350b 100644 --- a/cli/node/main.go +++ b/cli/node/main.go @@ -35,18 +35,18 @@ const ( ) var ( - // Version represents the program based on the git tag - Version = "v0.1.0" - // Build represents the program based on the git commit - Build = "dev" - // Date represents the date of application was built - Date = "" + // version represents the program based on the git tag + version = "v0.1.0" + // commit represents the program based on the git commit + commit = "dev" + // date represents the date of application was built + date = "" ) func cmdVersion(c *cli.Context) error { - fmt.Printf("Version = \"%v\"\n", Version) - fmt.Printf("Build = \"%v\"\n", Build) - fmt.Printf("Date = \"%v\"\n", Date) + fmt.Printf("Version = \"%v\"\n", version) + fmt.Printf("Build = \"%v\"\n", commit) + fmt.Printf("Date = \"%v\"\n", date) return nil } @@ -420,7 +420,7 @@ func getConfigAPIServer(c *cli.Context) (*ConfigAPIServer, error) { func main() { app := cli.NewApp() app.Name = "hermez-node" - app.Version = Version + app.Version = version flags := []cli.Flag{ &cli.StringFlag{ Name: flagMode,