From f2a219db56fac192459d92497b3edb5c5daa2348 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 17 Sep 2024 13:29:13 +0200 Subject: [PATCH 1/4] feat(templates): scaffold makefile --- ignite/templates/app/files/Makefile.plush | 78 +++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 ignite/templates/app/files/Makefile.plush diff --git a/ignite/templates/app/files/Makefile.plush b/ignite/templates/app/files/Makefile.plush new file mode 100644 index 0000000000..e4d9ddfd75 --- /dev/null +++ b/ignite/templates/app/files/Makefile.plush @@ -0,0 +1,78 @@ +BRANCH := $(shell git rev-parse --abbrev-ref HEAD) +COMMIT := $(shell git log -1 --format='%H') +APPNAME := <%= AppName %> + +# don't override user values +ifeq (,$(VERSION)) + VERSION := $(shell git describe --exact-match 2>/dev/null) + # if VERSION is empty, then populate it with branch's name and raw commit hash + ifeq (,$(VERSION)) + VERSION := $(BRANCH)-$(COMMIT) + endif +endif + +# Update the ldflags with the app, client & server names +ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(APPNAME) \ + -X github.com/cosmos/cosmos-sdk/version.AppName=$(APPNAME)d \ + -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ + -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) + +BUILD_FLAGS := -ldflags '$(ldflags)' + +################# +### Build ### +################# + +test: + @echo "--> Running tests" + go test -v ./... + +.PHONY: test + +################# +### Install ### +################# + +all: install + +install: + @echo "--> ensure dependencies have not been modified" + @go mod verify + @echo "--> installing $(APPNAME)d" + @go install $(BUILD_FLAGS) -mod=readonly ./cmd/$(APPNAME)d + +.PHONY: all install + +################## +### Protobuf ### +################## + +# Use this proto-image if you do not want to use Ignite for generating proto files +protoVer=0.15.1 +protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer) +protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) + +proto-gen: + @echo "Generating protobuf files..." + @ignite generate proto-go --yes + +.PHONY: proto-gen + +################# +### Linting ### +################# + +golangci_lint_cmd=golangci-lint +golangci_version=v1.61.0 + +lint: + @echo "--> Running linter" + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version) + @$(golangci_lint_cmd) run ./... --timeout 15m + +lint-fix: + @echo "--> Running linter and fixing issues" + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version) + @$(golangci_lint_cmd) run ./... --fix --timeout 15m + +.PHONY: lint lint-fix \ No newline at end of file From f32d68bf7b55ca1885de8d74043ae6ea7d5045a1 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 17 Sep 2024 13:31:06 +0200 Subject: [PATCH 2/4] updates --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index e9d8d49741..f8cd59a91a 100644 --- a/changelog.md +++ b/changelog.md @@ -19,6 +19,7 @@ - [#4300](https://github.com/ignite/cli/pull/4300) Only panics the module in the most top function level - [#4327](https://github.com/ignite/cli/pull/4327) Use the TxConfig from simState instead create a new one - [#4326](https://github.com/ignite/cli/pull/4326) fAdd `buf.build` version to `ignite version` command +- [#4362](https://github.com/ignite/cli/pull/4362) Scaffold `Makefile` ### Changes From 7f12c0b90d198fbb109665a4b5ae17044887792a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 19 Sep 2024 09:29:12 +0200 Subject: [PATCH 3/4] Update ignite/templates/app/files/Makefile.plush Co-authored-by: Danilo Pantani --- ignite/templates/app/files/Makefile.plush | 69 ++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/ignite/templates/app/files/Makefile.plush b/ignite/templates/app/files/Makefile.plush index e4d9ddfd75..3d2032a79a 100644 --- a/ignite/templates/app/files/Makefile.plush +++ b/ignite/templates/app/files/Makefile.plush @@ -75,4 +75,71 @@ lint-fix: @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version) @$(golangci_lint_cmd) run ./... --fix --timeout 15m -.PHONY: lint lint-fix \ No newline at end of file +.PHONY: lint lint-fix + +############################################################################### +### Development ### +############################################################################### + +## govet: Run go vet. +govet: + @echo Running go vet... + @go vet ./... + +## govulncheck: Run govulncheck +govulncheck: + @echo Running govulncheck... + @go run golang.org/x/vuln/cmd/govulncheck ./... + +FIND_ARGS := -name '*.go' -type f -not -name '*.pb.go' -not -name '*.pb.gw.go' -not -path './api/*' + +## format: Run gofumpt and goimports. +format: + @echo Formatting... + @go install mvdan.cc/gofumpt + @go install golang.org/x/tools/cmd/goimports + @find . $(FIND_ARGS) | xargs gofumpt -w . + @find . $(FIND_ARGS) | xargs goimports -w -local github.com/ignite/network + +.PHONY: format govet govulncheck + + +############################################################################### +### Test ### +############################################################################### + +## test-unit: Run the unit tests. +test-unit: + @echo Running unit tests... + @VERSION=$(VERSION) go test -mod=readonly -v -timeout 30m $(PACKAGES) + +## test-race: Run the unit tests checking for race conditions +test-race: + @echo Running unit tests with race condition reporting... + @VERSION=$(VERSION) go test -mod=readonly -v -race -timeout 30m $(PACKAGES) + +## test-cover: Run the unit tests and create a coverage html report +test-cover: + @echo Running unit tests and creating coverage report... + @VERSION=$(VERSION) go test -mod=readonly -v -timeout 30m -coverprofile=$(COVER_FILE) -covermode=atomic $(PACKAGES) + @go tool cover -html=$(COVER_FILE) -o $(COVER_HTML_FILE) + @rm $(COVER_FILE) + +## bench: Run the unit tests with benchmarking enabled +bench: + @echo Running unit tests with benchmarking... + @VERSION=$(VERSION) go test -mod=readonly -v -timeout 30m -bench=. $(PACKAGES) + +## test: Run unit and integration tests. +test: govet govulncheck test-unit + +.PHONY: test test-unit test-race test-cover bench + +help: Makefile + @echo + @echo " Choose a command run in "$(APPNAME)", or just run 'make' for install" + @echo + @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' + @echo + +.PHONY: help \ No newline at end of file From f57c7f789975cf2787783ba1db9f6a4362a4557e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 19 Sep 2024 09:35:16 +0200 Subject: [PATCH 4/4] updates --- ignite/templates/app/files/Makefile.plush | 94 +++++++---------------- 1 file changed, 29 insertions(+), 65 deletions(-) diff --git a/ignite/templates/app/files/Makefile.plush b/ignite/templates/app/files/Makefile.plush index 3d2032a79a..54e9a72e80 100644 --- a/ignite/templates/app/files/Makefile.plush +++ b/ignite/templates/app/files/Makefile.plush @@ -19,15 +19,31 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(APPNAME) \ BUILD_FLAGS := -ldflags '$(ldflags)' -################# -### Build ### -################# +############## +### Test ### +############## -test: - @echo "--> Running tests" - go test -v ./... +test-unit: + @echo Running unit tests... + @go test -mod=readonly -v -timeout 30m ./... -.PHONY: test +test-race: + @echo Running unit tests with race condition reporting... + @go test -mod=readonly -v -race -timeout 30m ./... + +test-cover: + @echo Running unit tests and creating coverage report... + @go test -mod=readonly -v -timeout 30m -coverprofile=$(COVER_FILE) -covermode=atomic ./... + @go tool cover -html=$(COVER_FILE) -o $(COVER_HTML_FILE) + @rm $(COVER_FILE) + +bench: + @echo Running unit tests with benchmarking... + @go test -mod=readonly -v -timeout 30m -bench=. ./... + +test: govet govulncheck test-unit + +.PHONY: test test-unit test-race test-cover bench ################# ### Install ### @@ -77,69 +93,17 @@ lint-fix: .PHONY: lint lint-fix -############################################################################### -### Development ### -############################################################################### +################### +### Development ### +################### -## govet: Run go vet. govet: @echo Running go vet... @go vet ./... -## govulncheck: Run govulncheck govulncheck: @echo Running govulncheck... - @go run golang.org/x/vuln/cmd/govulncheck ./... - -FIND_ARGS := -name '*.go' -type f -not -name '*.pb.go' -not -name '*.pb.gw.go' -not -path './api/*' - -## format: Run gofumpt and goimports. -format: - @echo Formatting... - @go install mvdan.cc/gofumpt - @go install golang.org/x/tools/cmd/goimports - @find . $(FIND_ARGS) | xargs gofumpt -w . - @find . $(FIND_ARGS) | xargs goimports -w -local github.com/ignite/network - -.PHONY: format govet govulncheck - - -############################################################################### -### Test ### -############################################################################### - -## test-unit: Run the unit tests. -test-unit: - @echo Running unit tests... - @VERSION=$(VERSION) go test -mod=readonly -v -timeout 30m $(PACKAGES) - -## test-race: Run the unit tests checking for race conditions -test-race: - @echo Running unit tests with race condition reporting... - @VERSION=$(VERSION) go test -mod=readonly -v -race -timeout 30m $(PACKAGES) - -## test-cover: Run the unit tests and create a coverage html report -test-cover: - @echo Running unit tests and creating coverage report... - @VERSION=$(VERSION) go test -mod=readonly -v -timeout 30m -coverprofile=$(COVER_FILE) -covermode=atomic $(PACKAGES) - @go tool cover -html=$(COVER_FILE) -o $(COVER_HTML_FILE) - @rm $(COVER_FILE) - -## bench: Run the unit tests with benchmarking enabled -bench: - @echo Running unit tests with benchmarking... - @VERSION=$(VERSION) go test -mod=readonly -v -timeout 30m -bench=. $(PACKAGES) - -## test: Run unit and integration tests. -test: govet govulncheck test-unit - -.PHONY: test test-unit test-race test-cover bench - -help: Makefile - @echo - @echo " Choose a command run in "$(APPNAME)", or just run 'make' for install" - @echo - @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' - @echo + @go install golang.org/x/vuln/cmd/govulncheck@latest + @govulncheck ./... -.PHONY: help \ No newline at end of file +.PHONY: govet govulncheck \ No newline at end of file