Skip to content

Commit

Permalink
Refactoring makefile to separate lint, proto and test out of it.
Browse files Browse the repository at this point in the history
  • Loading branch information
arhamchordia committed Jul 22, 2024
1 parent 66d5733 commit c4af91f
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 78 deletions.
97 changes: 38 additions & 59 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

include scripts/makefiles/build.mk
include scripts/makefiles/docker.mk
include scripts/makefiles/lint.mk
include scripts/makefiles/proto.mk
include scripts/makefiles/test.mk
include tests/e2e/Makefile

.DEFAULT_GOAL := help
help:
Expand Down Expand Up @@ -117,30 +121,47 @@ ifeq (,$(findstring nostrip,$(QUASAR_BUILD_OPTIONS)))
endif

###############################################################################
### Proto & Mock Generation ###
### Build & Install ###
###############################################################################

proto-all: proto-format proto-gen
BUF_VERSION=1.26.1
BUILDER_VERSION=0.13.5
proto-gen:
@echo "Generating Protobuf files"
@sh ./scripts/protocgen.sh
update-deps:
@go mod tidy;

build: build-check-version go.sum
# back up before build
@cp go.mod go.mod.backup
@cp go.sum go.sum.backup
@go mod tidy

mkdir -p $(BUILDDIR)/
GOWORK=off go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ $(GO_MODULE)/cmd/quasarnoded

proto-gen-1:
@echo "🤖 Generating code from protobuf..."
@echo "PWD is $(PWD)"
# clean up before install
@mv go.mod.backup go.mod
@mv go.sum.backup go.sum
@rm -f go.mod.bak
@go mod tidy

@docker run --rm --volume "$(PWD)":/workspace --workdir /workspace \
ghcr.io/cosmos/proto-builder:$(BUILDER_VERSION) sh ./scripts/protocgen.sh
@echo "✅ Completed code generation!"
install: build-check-version go.sum
# back up before build
@cp go.mod go.mod.backup
@cp go.sum go.sum.backup
@go mod tidy

proto-doc:
@echo "Generating Protoc docs"
@sh ./scripts/generate-docs.sh
GOWORK=off go install -mod=readonly $(BUILD_FLAGS) $(GO_MODULE)/cmd/quasarnoded

.PHONY: proto-gen proto-doc
# clean up before install
@mv go.mod.backup go.mod
@mv go.sum.backup go.sum
@rm -f go.mod.bak
@go mod tidy

###############################################################################
### Go Mock ###
###############################################################################

# todo : need ideas on external libraries
# example : mockgen -source=/path/to/go/pkg/mod/github.com/cosmos/ibc-go/[email protected]/modules/core/05-port/types/module.go -destination=/path/to/quasar/mock/ics4_wrapper_mocks.go -package=mock -mock_names=MockICS4Wrapper
mocks: $(MOCKSDIR)/
mockgen -package=mock -destination=$(MOCKSDIR)/ibc_channel_mocks.go $(GOMOD)/x/qoracle/types ChannelKeeper
# mockgen -package=mock -destination=$(MOCKSDIR)/ica_mocks.go $(GOMOD)/x/intergamm/types ICAControllerKeeper
Expand All @@ -153,48 +174,6 @@ mocks: $(MOCKSDIR)/
$(MOCKSDIR)/:
mkdir -p $(MOCKSDIR)/

###############################################################################
### Tests & Simulation ###
###############################################################################

PACKAGES_UNIT=$(shell go list ./x/epochs/... ./x/qoracle/... ./x/tokenfactory/... | grep -E -v "simapp|e2e" | grep -E -v "x/qoracle/client/cli")
PACKAGES_E2E=$(shell go list ./... | grep '/tests/e2e')
PACKAGES_SIM=$(shell go list ./... | grep '/tests/simulator')
TEST_PACKAGES=./...

include tests/e2e/Makefile

test: test-unit test-build

test-all: check test-race test-cover

test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock norace' $(PACKAGES_UNIT)

test-race:
@VERSION=$(VERSION) go test -mod=readonly -race -tags='ledger test_ledger_mock' $(PACKAGES_UNIT)

test-cover:
@VERSION=$(VERSION) go test -mod=readonly -timeout 30m -coverprofile=coverage.txt -tags='norace' -covermode=atomic $(PACKAGES_UNIT)

test-sim-suite:
@VERSION=$(VERSION) go test -mod=readonly $(PACKAGES_SIM)

test-sim-app:
@VERSION=$(VERSION) go test -mod=readonly -run ^TestFullAppSimulation -v $(PACKAGES_SIM)

test-sim-determinism:
@VERSION=$(VERSION) go test -mod=readonly -run ^TestAppStateDeterminism -v $(PACKAGES_SIM)

test-sim-bench:
@VERSION=$(VERSION) go test -benchmem -run ^BenchmarkFullAppSimulation -bench ^BenchmarkFullAppSimulation -cpuprofile cpu.out $(PACKAGES_SIM)

benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_UNIT)

lint:
@echo "--> Running linter"
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run --timeout=10m

.PHONY: all build-linux install format lint build \
test test-all test-build test-cover test-unit test-race benchmark
15 changes: 0 additions & 15 deletions scripts/makefiles/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@ build-dev-build:
mkdir -p $(BUILDDIR)/
GOWORK=off go build $(GC_FLAGS) -mod=readonly -ldflags '$(DEBUG_LDFLAGS)' -gcflags "all=-N -l" -trimpath -o $(BUILDDIR) ./...;

all: install lint test

BUILD_TARGETS := build install
#BUILD_TARGETS_DEBUG := build install
build: BUILD_ARGS=-o $(BUILDDIR)/

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
GOWORK=off go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./cmd/quasarnoded

$(BUILD_TARGETS_DEBUG): go.sum $(BUILDDIR)/
GOWORK=off go $@ -mod=readonly $(BUILD_FLAGS_DEBUG) -gcflags='all=-N -l' $(BUILD_ARGS) ./cmd/quasarnoded

$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

###############################################################################
### Build reproducible ###
###############################################################################
Expand Down
1 change: 0 additions & 1 deletion scripts/makefiles/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ docker-help:
@echo " test-e2e Running e2e tests"
@echo " e2e-build Build e2e docker images of the chain needed for interchaintest"


docker: docker-help

docker-build:
Expand Down
47 changes: 47 additions & 0 deletions scripts/makefiles/lint.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
###############################################################################
### Linting ###
###############################################################################
lint-help:
@echo "lint subcommands"
@echo ""
@echo "Usage:"
@echo " make lint-[command]"
@echo ""
@echo "Available Commands:"
@echo " all Run all linters"
@echo " fix-typo Run codespell to fix typos"
@echo " format Run linters with auto-fix"
@echo " markdown Run markdown linter with auto-fix"
@echo " mdlint Run markdown linter"
@echo " setup-pre-commit Set pre-commit git hook"
@echo " typo Run codespell to check typos"
lint: lint-help

lint-all:
@echo "--> Running linter"
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run --timeout=10m
@docker run -v $(PWD):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md"

lint-format:
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run ./... --fix
@go run mvdan.cc/gofumpt -l -w x/ app/ ante/ tests/
@docker run -v $(PWD):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md" --fix

lint-mdlint:
@echo "--> Running markdown linter"
@docker run -v $(PWD):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md"

lint-markdown:
@docker run -v $(PWD):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md" --fix

lint-typo:
@codespell

lint-fix-typo:
@codespell -w

lint-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
@echo "Pre-commit hook installed successfully"
35 changes: 35 additions & 0 deletions scripts/makefiles/proto.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
###############################################################################
### Proto & Mock Generation ###
###############################################################################
proto-help:
@echo "proto subcommands"
@echo ""
@echo "Usage:"
@echo " make proto-[command]"
@echo ""
@echo "Available Commands:"
@echo " all Run proto-format and proto-gen"
@echo " gen Generate Protobuf files"
@echo " gen-1 Generate Protobuf files (old relic)"
@echo " doc Generate proto docs"

proto: proto-help
proto-all: proto-gen

# todo : @AJ needs to address this after removing third_party. Refer this for removal https://github.com/osmosis-labs/osmosis/blob/188abfcd15544ca07d468c0dc0169876ffde6079/scripts/makefiles/proto.mk#L39
proto-gen:
@echo "Generating Protobuf files"
@sh ./scripts/protocgen.sh

# todo : @AK need the reason why it was there earlier
proto-gen-1:
@echo "🤖 Generating code from protobuf..."
@echo "PWD is $(PWD)"

@docker run --rm --volume "$(PWD)":/workspace --workdir /workspace \
ghcr.io/cosmos/proto-builder:$(BUILDER_VERSION) sh ./scripts/protocgen.sh
@echo "✅ Completed code generation!"

proto-doc:
@echo "Generating Protoc docs"
@sh ./scripts/generate-docs.sh
53 changes: 53 additions & 0 deletions scripts/makefiles/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
###############################################################################
### Tests ###
###############################################################################

PACKAGES_UNIT=$(shell go list ./x/epochs/... ./x/qoracle/... ./x/tokenfactory/... ./x/qtransfer/... ./x/qvesting/... ./app/... | grep -E -v "simapp|e2e" | grep -E -v "x/qoracle/client/cli")
PACKAGES_E2E=$(shell go list ./... | grep '/tests/e2e')
PACKAGES_SIM=$(shell go list ./... | grep '/tests/simulator')
TEST_PACKAGES=./...

test-help:
@echo "test subcommands"
@echo ""
@echo "Usage:"
@echo " make test-[command]"
@echo ""
@echo "Available Commands:"
@echo " all Run all tests"
@echo " benchmark Run benchmark tests"
@echo " cover Run coverage tests"
@echo " race Run race tests"
@echo " sim-app Run sim app tests"
@echo " sim-bench Run sim benchmark tests"
@echo " sim-determinism Run sim determinism tests"
@echo " sim-suite Run sim suite tests"
@echo " unit Run unit tests"

test: test-help

test-all: test-unit test-race test-sim-app

test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock norace' $(PACKAGES_UNIT)

test-race:
@VERSION=$(VERSION) go test -mod=readonly -race -tags='ledger test_ledger_mock' $(PACKAGES_UNIT)

test-cover:
@VERSION=$(VERSION) go test -mod=readonly -timeout 30m -coverprofile=coverage.txt -tags='norace' -covermode=atomic $(PACKAGES_UNIT)

test-sim-suite:
@VERSION=$(VERSION) go test -mod=readonly $(PACKAGES_SIM)

test-sim-app:
@VERSION=$(VERSION) go test -mod=readonly -run ^TestFullAppSimulation -v $(PACKAGES_SIM)

test-sim-determinism:
@VERSION=$(VERSION) go test -mod=readonly -run ^TestAppStateDeterminism -v $(PACKAGES_SIM)

test-sim-bench:
@VERSION=$(VERSION) go test -benchmem -run ^BenchmarkFullAppSimulation -bench ^BenchmarkFullAppSimulation -cpuprofile cpu.out $(PACKAGES_SIM)

test-benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_UNIT)
18 changes: 15 additions & 3 deletions tests/e2e/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
e2e-help:
@echo "e2e subcommands"
@echo ""
@echo "Usage:"
@echo " make e2e-[command]"
@echo ""
@echo "Available Commands:"
@echo " test Run tests in the specified folders serially, if CASES is defined; otherwise, run all."
@echo " test-parallel Run tests in the specified folders in parallel, if CASES is defined; otherwise, run all."

e2e: e2e-help

# Find all folders inside ./cases, excluding ones that start with an underscore
TEST_FOLDERS=$(shell find ./cases -mindepth 1 -maxdepth 1 -type d \( -name "[!_]*" \))
TEST_FOLDERS=$(shell find ./tests/e2e/cases -mindepth 1 -maxdepth 1 -type d \( -name "[!_]*" \))

# Run tests in the specified folders serially, if CASES is defined; otherwise, run all.
test-e2e:
e2e-test:
ifdef CASES
# Loop through each folder specified in CASES and run the tests
@for folder in $(filter $(CASES), $(TEST_FOLDERS)); do \
Expand All @@ -18,7 +30,7 @@ else
endif

# Run tests in the specified folders in parallel, if CASES is defined; otherwise, run all.
test-e2e-parallel:
e2e-test-parallel:
ifdef CASES
@for folder in $(filter $(CASES), $(TEST_FOLDERS)); do \
echo "\nRunning tests in directory: $$folder"; \
Expand Down

0 comments on commit c4af91f

Please sign in to comment.