Skip to content

Commit

Permalink
Add devbox to the project
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderboltsid committed Jul 22, 2024
1 parent 3e4dd87 commit 0f9afcd
Show file tree
Hide file tree
Showing 12 changed files with 1,411 additions and 154 deletions.
7 changes: 7 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Automatically sets up your devbox environment whenever you cd into this
# directory via our direnv integration:

eval "$(devbox generate direnv --print-envrc)"

# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/
# for more details
4 changes: 2 additions & 2 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ env:
EXPORT_RESULT: true
on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:
Expand Down
18 changes: 18 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
linters:
enable:
- errcheck
- gofmt
- gofumpt
- gosimple
- govet
- ineffassign
- nolintlint
- staticcheck
- unused
linters-settings:
nolintlint:
require-explanation: true
require-specific: true
run:
concurrency: 4
timeout: 5m
7 changes: 7 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends: default

rules:
indentation: disable
document-start: disable
comments: disable
line-length: disable
56 changes: 10 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
SHELL := /bin/bash
GOCMD=go
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
BINARY_NAME=nutanixclient
EXPORT_RESULT?=false # for CI please set EXPORT_RESULT to true

Expand All @@ -20,50 +17,21 @@ build: ## Build your project and put the output binary in bin/
mkdir -p bin
$(GOCMD) build -o bin/$(BINARY_NAME) .

# go-get-tool will 'go install' any package $2 and install it to $1.
# originally copied from kubebuilder
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
BIN_PATH=$$(realpath $$(dirname $(1))) ;\
PKG_BIN_NAME=$$(echo "$(2)" | sed 's,^.*/\(.*\)@v.*$$,\1,') ;\
BIN_NAME=$$(basename $(1)) ;\
echo "Install dir $$BIN_PATH" ;\
echo "Downloading $(2)" ;\
GOBIN=$$BIN_PATH go install $(2) ;\
[[ $$PKG_BIN_NAME == $$BIN_NAME ]] || mv -f $$BIN_PATH/$$PKG_BIN_NAME $$BIN_PATH/$$BIN_NAME ;\
}
endef

TOOLS_BIN_DIR := hack/tools/bin

$(TOOLS_BIN_DIR):
mkdir -p $(TOOLS_BIN_DIR)

CONTROLLER_GEN_BIN := controller-gen
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)
# CRD_OPTIONS define options to add to the CONTROLLER_GEN
CRD_OPTIONS ?= "crd:crdVersions=v1"

$(CONTROLLER_GEN): $(TOOLS_BIN_DIR)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])

KEPLOY_VER := v0.7.12
KEPLOY_BIN := server-$(KEPLOY_VER)
KEPLOY := $(TOOLS_BIN_DIR)/$(KEPLOY_BIN)
KEPLOY_PKG := go.keploy.io/server/cmd/server

.PHONY: $(KEPLOY)
$(KEPLOY): $(TOOLS_BIN_DIR)
$(call go-get-tool,$(KEPLOY),$(KEPLOY_PKG)@$(KEPLOY_VER))

.PHONY: run-keploy
run-keploy: $(KEPLOY)
$(KEPLOY) run &
run-keploy:
server run &

.PHONY: stop-keploy
stop-keploy:
@-pkill "$(KEPLOY_BIN)"
@-pkill "server"

generate: $(CONTROLLER_GEN) ## Generate zz_generated.deepcopy.go
$(CONTROLLER_GEN) paths="./..." object:headerFile="hack/boilerplate.go.txt"
Expand All @@ -75,18 +43,15 @@ clean: ## Remove build related file
## Test:
test: run-keploy ## Run the tests of the project
ifeq ($(EXPORT_RESULT), true)
go install github.com/jstemmer/go-junit-report
$(eval OUTPUT_OPTIONS = | tee /dev/tty | go-junit-report -set-exit-code > junit-report.xml)
endif
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS)
go test -v -race ./... $(OUTPUT_OPTIONS)
@$(MAKE) stop-keploy

coverage: run-keploy ## Run the tests of the project and export the coverage
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
$(GOCMD) tool cover -func profile.cov
go test -cover -covermode=count -coverprofile=profile.cov ./...
go tool cover -func profile.cov
ifeq ($(EXPORT_RESULT), true)
go install github.com/AlekSi/gocov-xml
go install github.com/axw/gocov/gocov
gocov convert profile.cov | gocov-xml > coverage.xml
endif
@$(MAKE) stop-keploy
Expand All @@ -96,18 +61,17 @@ lint: lint-go lint-yaml lint-kubebuilder ## Run all available linters

lint-go: ## Use golintci-lint on your project
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle ./... | tee /dev/tty > checkstyle-report.xml" || echo "" ))
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --enable gofmt --fix --enable gofumpt $(OUTPUT_OPTIONS)
golangci-lint run -v

lint-yaml: ## Use yamllint on the yaml file of your projects
ifeq ($(EXPORT_RESULT), true)
go install github.com/thomaspoignant/yamllint-checkstyle
$(eval OUTPUT_OPTIONS = | tee /dev/tty | yamllint-checkstyle > yamllint-checkstyle.xml)
endif
docker run --rm -it -v $(shell pwd):/data cytopia/yamllint -c yamllint-config.yaml -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)
yamllint -c .yamllint --no-warnings -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)

.PHONY: lint-kubebuilder
lint-kubebuilder: $(CONTROLLER_GEN) ## Lint Kubebuilder annotations by generating objects and checking if it is successful
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=.
lint-kubebuilder: ## Lint Kubebuilder annotations by generating objects and checking if it is successful
controller-gen $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=.

## Help:
help: ## Show this help.
Expand Down
22 changes: 22 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://raw.githubusercontent.com/jetpack-io/devbox/0.10.1/.schema/devbox.schema.json",
"packages": [
"bash@latest",
"coreutils@latest",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"path:./hack/flakes#go-apidiff",
"path:./hack/flakes#go-mod-upgrade",
"path:./hack/flakes#go-junit-report",
"path:./hack/flakes#gocov",
"path:./hack/flakes#gocov-xml",
"path:./hack/flakes#golangci-lint",
"path:./hack/flakes#yamllint-checkstyle",
"path:./hack/flakes#setup-envtest",
"path:./hack/flakes#keploy"
]
}
Loading

0 comments on commit 0f9afcd

Please sign in to comment.