Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add make help to display the usage for project Makefile #5669

Merged
merged 6 commits into from
Jan 22, 2024
Merged
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

#? all: Run tools build lint test
all: build lint test

# The below include contains the tools and runsim targets.
Expand All @@ -103,10 +104,14 @@ include contrib/devtools/Makefile

BUILD_TARGETS := build install

#? tidy-all: Run go mod tidy for all modules
tidy-all:
./scripts/go-mod-tidy-all.sh

#? build: Build simapp and build_test_matrix
build: BUILD_ARGS=-o $(BUILDDIR)/

#? build-linux: Build simapp and build_test_matrix for GOOS=linux GOARCH=amd64
build-linux:
GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build

Expand All @@ -118,7 +123,10 @@ $(BUILDDIR)/:

.PHONY: build build-linux

#? distclean: Run `make clean`
distclean: clean

#? clean: Clean some auto generated directories
clean:
rm -rf \
$(BUILDDIR)/ \
Expand All @@ -136,6 +144,7 @@ go.sum: go.mod
go mod verify
go mod tidy

#? python-install-deps: Install python dependencies
python-install-deps:
@echo "Installing python dependencies..."
@pip3 install --upgrade pip
Expand All @@ -145,21 +154,26 @@ python-install-deps:
### Documentation ###
###############################################################################

#? godocs: Generate go documentation
godocs:
@echo "--> Wait a few seconds and visit http://localhost:6060/pkg/github.com/cosmos/cosmos-sdk/types"
godoc -http=:6060

#? build-docs: Build documentation
build-docs:
@cd docs && npm ci && npm run build

#? serve-docs: Run docs server
serve-docs:
@cd docs && npm run serve

#? changelog: Show changelog
changelog:
docker run --rm -v "$$(pwd)"/.git:/app/ -v "$$(pwd)/cliff.toml":/app/cliff.toml orhunp/git-cliff:latest --unreleased --tag $(tag)

# If the DOCS_VERSION variable is not set, display an error message and exit
ifndef DOCS_VERSION
#? tag-docs-version: Tag the docs version
tag-docs-version:
@echo "Error: DOCS_VERSION is not set. Use 'make tag-docs-version DOCS_VERSION=<version>' to set it. For example: 'make tag-docs-version DOCS_VERSION=v8.0.x'"
@exit 1
Expand All @@ -178,10 +192,14 @@ endif
# it is useful for testing and development
# Usage: make install && make init-simapp && simd start
# Warning: make init-simapp will remove all data in simapp home directory
#? init-simapp: Run scripts/init-simapp.sh
init-simapp:
./scripts/init-simapp.sh

#? test: Run make test-unit
test: test-unit

#? test-all: Run all test
test-all: test-unit test-ledger-mock test-race test-cover

TEST_PACKAGES=./...
Expand All @@ -207,11 +225,13 @@ $(CHECK_TEST_TARGETS): EXTRA_ARGS=-run=none
$(CHECK_TEST_TARGETS): run-tests

ARGS += -tags "$(test_tags)"
#? run-tests: Runs the go test command for all modules
run-tests:
@ARGS="$(ARGS)" TEST_PACKAGES=$(TEST_PACKAGES) EXTRA_ARGS="$(EXTRA_ARGS)" python3 ./scripts/go-test-all.py

.PHONY: run-tests test test-all $(TEST_TARGETS)

#? test-sim-nondeterminism: Run non-determinism test for simapp
test-sim-nondeterminism:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
Expand Down Expand Up @@ -264,22 +284,26 @@ SIM_NUM_BLOCKS ?= 500
SIM_BLOCK_SIZE ?= 200
SIM_COMMIT ?= true

#? test-sim-benchmark: Run application benchmark
test-sim-benchmark:
@echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!"
@go test -mod=readonly -benchmem -run=^$$ $(SIMAPP) -bench ^BenchmarkFullAppSimulation$$ \
-Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h

#? test-sim-profile: Run application benchmark and output cpuprofile, memprofile
test-sim-profile:
@echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!"
@go test -mod=readonly -benchmem -run=^$$ $(SIMAPP) -bench ^BenchmarkFullAppSimulation$$ \
-Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h -cpuprofile cpu.out -memprofile mem.out

.PHONY: test-sim-profile test-sim-benchmark

#? test-cover: Run contrib/test_cover.sh
test-cover:
@export VERSION=$(VERSION); bash -x contrib/test_cover.sh
.PHONY: test-cover

#? benchmark: Run benchmark tests
benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_NOSIMULATION)
.PHONY: benchmark
Expand All @@ -288,30 +312,37 @@ benchmark:
### Linting ###
###############################################################################

#? setup-pre-commit: Set pre commit git hook
setup-pre-commit:
@cp .git/hooks/pre-commit .git/hooks/pre-commit.bak 2>/dev/null || true
@echo "Installing pre-commit hook..."
@ln -sf ../../scripts/hooks/pre-commit.sh .git/hooks/pre-commit

#? lint: Run golangci-lint on all modules
lint:
@echo "--> Running linter"
@./scripts/go-lint-all.sh --timeout=15m

#? lint-fix: Run golangci-lint and fix issues on all modules
lint-fix:
@echo "--> Running linter"
@./scripts/go-lint-all.sh --fix

#? format: Run gofumpt and mispell
format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs gofumpt -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs misspell -w
.PHONY: format

#? docs-lint: Lint markdown documentation files
docs-lint:
markdownlint-cli2 "**.md"

#? docs-lint-fix: Lint markdown documentation files and fix
docs-lint-fix:
markdownlint-cli2-fix "**.md"

#? docs-link-check: Run markdown-link-check
docs-link-check:
find . -name 'node_modules' -prune -o -name '*.md' -print0 | xargs -0 -n1 markdown-link-check --config ./.github/workflows/link-check-config.json

Expand All @@ -325,27 +356,41 @@ protoVer=0.14.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

#? proto-all: Format, lint and generate Protobuf files
proto-all: proto-format proto-lint proto-gen

#? proto-gen: Generate Protobuf files
proto-gen:
@echo "Generating Protobuf files"
@$(protoImage) sh ./scripts/protocgen.sh

#? proto-swagger-gen: Generate Protobuf Swagger
proto-swagger-gen:
@echo "Generating Protobuf Swagger"
@$(protoImage) sh ./scripts/protoc-swagger-gen.sh

#? proto-format: Format Protobuf files
proto-format:
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;

#? proto-lint: Lint Protobuf files
proto-lint:
@$(protoImage) buf lint --error-format=json

#? proto-check-breaking: Check if Protobuf file contains breaking changes
proto-check-breaking:
@$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main

#? proto-update-deps: Update Protobuf dependencies
proto-update-deps:
@echo "Updating Protobuf dependencies"
$(DOCKER) run --rm -v $(CURDIR)/proto:/workspace --workdir /workspace $(protoImageName) buf mod update

.PHONY: proto-all proto-gen proto-gen-any proto-swagger-gen proto-format proto-lint proto-check-breaking proto-update-deps


#? help: Get more info on make commands
help: Makefile
@echo " Choose a command run in "$(PROJECT_NAME)":"
@sed -n 's/^#?//p' $< | column -t -s ':' | sort | sed -e 's/^/ /'
.PHONY: help
Loading