Skip to content

Commit

Permalink
use makefile for generate and test
Browse files Browse the repository at this point in the history
Signed-off-by: Zuhair AlSader <[email protected]>
  • Loading branch information
zalsader committed Apr 3, 2023
1 parent 7ac9561 commit 555de0e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ jobs:
run: |
set -x
sudo apt-get -y update && sudo apt-get -y install git
go install github.com/golang/mock/[email protected]
go install sigs.k8s.io/controller-tools/cmd/[email protected]
go generate ./...
make generate
git diff | cat
git status --porcelain=v1
test $(git status --porcelain=v1 | wc -l) -eq 0
Expand All @@ -43,4 +41,4 @@ jobs:
go-version: ${{ matrix.go }}

- name: Run unit tests
run: go test ./...
run: make test
23 changes: 22 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
.idea

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin
testbin/*
cache/

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
67 changes: 67 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.PHONY: all
all: build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

##@ Build

.PHONY: build
build: generate fmt vet ## Build binary.
go build -o bin/client .

.PHONY: test
test: generate fmt vet ## Run tests.
go test ./... -coverprofile cover.out

.PHONY: generate
generate: controller-gen mockgen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
GOBIN=$(LOCALBIN) go generate ./...

##@ Build Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
MOCKGEN ?= $(LOCALBIN)/mockgen
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen

## Tool Versions
MOCKGEN_VERSION ?= v1.6.0
CONTROLLER_TOOLS_VERSION ?= v0.10.0

.PHONY: mockgen
mockgen: $(MOCKGEN) ## Download mockgen locally if necessary.
$(MOCKGEN): $(LOCALBIN)
test -s $(LOCALBIN)/mockgen || GOBIN=$(LOCALBIN) go install github.com/golang/mock/mockgen@$(MOCKGEN_VERSION)

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This library includes a mock client [mock/interface_mock.go](mock/interface.go)

Example usage of the mocked client can be found in [mock/mock_test.go](mock/mock_test.go).

If you made changes to [interface.go](./interface.go), you should issue the `go generate ./...` command to trigger code generation.
If you made changes to [interface.go](./interface.go), you should issue the `make generate` command to trigger code generation.

## Documentation
For more specific documentation, please refer to the [godoc](https://pkg.go.dev/github.com/mittwald/go-helm-client/) of this library.

0 comments on commit 555de0e

Please sign in to comment.