Skip to content

Commit

Permalink
fix Makefile (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
viatoriche authored Dec 18, 2024
1 parent cb7a673 commit eae5f65
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
53 changes: 38 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
# Directory containing the Makefile.
export PATH := $(GOBIN):$(PATH)

GO_VERISON = 1.20.14
GO_VERSION = 1.20.14
GO_VERSION_CMD_RAML = 1.22.10
GOLANGCI_LINT_VERSION = 1.55.2

.PHONY: all
all: lint cover

.PHONY: lint
lint:
@go$(GO_VERISON) run github.com/golangci/golangci-lint/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION) run ./...
lint: go-install
@go$(GO_VERSION) run github.com/golangci/golangci-lint/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION) run ./...

.PHONY: test
test-unit:
@go test ./...
test-unit: go-install
@go$(GO_VERSION) test ./...

# the coverage should be at least 80% for now, but it should be increased in the future to 90% and more
.PHONY: cover
test-cover:
@pkgs=$$(go list ./... | grep -v /Store/) \
go test -coverprofile=cover.out.tmp $${pkgs} -coverpkg=$${pkgs} \
test-cover: go-install
@pkgs=$$(go$(GO_VERSION) list ./... | grep -v /Store/) \
go$(GO_VERSION) test -coverprofile=cover.out.tmp $${pkgs} -coverpkg=$${pkgs} \
&& cat cover.out.tmp | grep -v "rdtparser_base_visitor.go" > cover.out \
&& rm cover.out.tmp \
&& go tool cover -func=cover.out | grep total | awk '{print substr($$3, 1, length($$3)-1)}' | \
&& go$(GO_VERSION) tool cover -func=cover.out | grep total | awk '{print substr($$3, 1, length($$3)-1)}' | \
awk '{if ($$1 < 80) {print "Coverage is below 80%!" ; exit 1}}' \
&& go tool cover -html=cover.out -o cover.html
&& go$(GO_VERSION) tool cover -html=cover.out -o cover.html

.PHONY: test
test: test-cover
Expand All @@ -33,11 +34,33 @@ test: test-cover
build: go-build

.PHONY: go-build
go-build:
@cd cmd/raml && go build -o ../../.build/raml

go-build: go-install-cmd-raml
@echo "Building raml"
@cd cmd/raml && go$(GO_VERSION_CMD_RAML) build -o ../../.build/raml \
&& echo "Build successful in .build/raml using go$(GO_VERSION_CMD_RAML)"

.PHONY: go-install
go-install:
go install golang.org/dl/go$(GO_VERISON)@latest
go$(GO_VERISON) download
@if ! which go$(GO_VERSION) > /dev/null 2>&1; then \
echo "Installing go$(GO_VERSION)"; \
go install golang.org/dl/go$(GO_VERSION)@latest; \
go$(GO_VERSION) download; \
fi

.PHONY: go-install-cmd-raml
go-install-cmd-raml:
@$(MAKE) go-install GO_VERSION=$(GO_VERSION_CMD_RAML)

.PHONY: go
go: go-install
@# Run go command with the specified arguments
@# examples:
@# make go a="mod tidy"
@# make go a="mod vendor"
@go$(GO_VERSION) $(a)

.PHONY: install
install: go-install-cmd-raml
@echo "Installing raml"
@cd cmd/raml && go$(GO_VERSION_CMD_RAML) install . \
&& echo "Installed using go$(GO_VERSION_CMD_RAML) to $(GOPATH)/bin/raml"
2 changes: 1 addition & 1 deletion cmd/raml/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/acronis/go-raml/cmd/raml

go 1.22.6
go 1.22

require (
github.com/acronis/go-raml v0.14.0
Expand Down

0 comments on commit eae5f65

Please sign in to comment.