Skip to content

Commit f9d980d

Browse files
Add devbox to the project (#172)
1 parent 3e4dd87 commit f9d980d

File tree

14 files changed

+1339
-182
lines changed

14 files changed

+1339
-182
lines changed

.envrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Automatically sets up your devbox environment whenever you cd into this
2+
# directory via our direnv integration:
3+
4+
eval "$(devbox generate direnv --print-envrc)"
5+
6+
# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/
7+
# for more details

.github/workflows/build-lint-test.yml

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ env:
33
EXPORT_RESULT: true
44
on:
55
push:
6-
branches: [ "main" ]
6+
branches: ["main"]
77
pull_request:
8-
branches: [ "main" ]
8+
branches: ["main"]
99

1010
jobs:
1111
build:
@@ -15,30 +15,40 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v4
1717

18-
- name: Setup Go
19-
uses: actions/setup-go@v5
18+
- uses: actions/cache@v4
2019
with:
21-
go-version: '^1.21'
22-
23-
- name: Check build
24-
run: make build
20+
path: |
21+
~/.cache/golangci-lint
22+
~/.cache/go-build
23+
~/go/pkg/mod
24+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
25+
restore-keys: |
26+
${{ runner.os }}-go-
27+
28+
- name: Install devbox
29+
uses: jetify-com/devbox-install-action@v0.11.0
30+
with:
31+
enable-cache: "true"
2532

2633
- name: Run golangci-lint
27-
uses: golangci/golangci-lint-action@v3.7.0
28-
with:
29-
args: --enable gofmt --enable gofumpt --timeout 5m
34+
run: devbox run -- make lint-go
3035

3136
- name: Check YAML linting
32-
run: make lint-yaml
37+
run: devbox run -- make lint-yaml
3338

3439
- name: Check Kubebuilder Annotation linting
35-
run: make lint-kubebuilder
40+
run: devbox run -- make lint-kubebuilder
3641

3742
- name: Run tests
38-
run: make test
43+
run: devbox run -- make test
3944

4045
- name: Prepare coverage report
41-
run: make coverage
46+
run: devbox run -- make coverage
4247

4348
- name: Codecov
4449
uses: codecov/codecov-action@v3.1.4
50+
env:
51+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
52+
with:
53+
file: ./coverage.out # Replace with the path to your coverage report
54+
fail_ci_if_error: true

.github/workflows/synopsys.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ jobs:
2020
- name: Setup Go
2121
uses: actions/setup-go@v5
2222
with:
23-
go-version: '^1.17'
24-
25-
- name: Build Project
26-
run: make build
23+
go-version: '^1.21'
2724

2825
- name: Run Synopsys Detect
2926
uses: synopsys-sig/detect-action@v0.3.4

.golangci.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
linters:
2+
enable:
3+
- errcheck
4+
- gofmt
5+
- gofumpt
6+
- gosimple
7+
- govet
8+
- ineffassign
9+
- nolintlint
10+
- staticcheck
11+
- unused
12+
linters-settings:
13+
nolintlint:
14+
require-explanation: true
15+
require-specific: true
16+
run:
17+
concurrency: 4
18+
timeout: 5m

.yamllint

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extends: default
2+
3+
rules:
4+
indentation: disable
5+
document-start: disable
6+
comments: disable
7+
line-length: disable

Makefile

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
SHELL := /bin/bash
2-
GOCMD=go
3-
GOTEST=$(GOCMD) test
4-
GOVET=$(GOCMD) vet
52
BINARY_NAME=nutanixclient
63
EXPORT_RESULT?=false # for CI please set EXPORT_RESULT to true
74

@@ -20,94 +17,54 @@ build: ## Build your project and put the output binary in bin/
2017
mkdir -p bin
2118
$(GOCMD) build -o bin/$(BINARY_NAME) .
2219

23-
# go-get-tool will 'go install' any package $2 and install it to $1.
24-
# originally copied from kubebuilder
25-
define go-get-tool
26-
@[ -f $(1) ] || { \
27-
set -e ;\
28-
BIN_PATH=$$(realpath $$(dirname $(1))) ;\
29-
PKG_BIN_NAME=$$(echo "$(2)" | sed 's,^.*/\(.*\)@v.*$$,\1,') ;\
30-
BIN_NAME=$$(basename $(1)) ;\
31-
echo "Install dir $$BIN_PATH" ;\
32-
echo "Downloading $(2)" ;\
33-
GOBIN=$$BIN_PATH go install $(2) ;\
34-
[[ $$PKG_BIN_NAME == $$BIN_NAME ]] || mv -f $$BIN_PATH/$$PKG_BIN_NAME $$BIN_PATH/$$BIN_NAME ;\
35-
}
36-
endef
37-
3820
TOOLS_BIN_DIR := hack/tools/bin
3921

4022
$(TOOLS_BIN_DIR):
4123
mkdir -p $(TOOLS_BIN_DIR)
4224

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

48-
$(CONTROLLER_GEN): $(TOOLS_BIN_DIR)
49-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0)
50-
51-
KEPLOY_VER := v0.7.12
52-
KEPLOY_BIN := server-$(KEPLOY_VER)
53-
KEPLOY := $(TOOLS_BIN_DIR)/$(KEPLOY_BIN)
54-
KEPLOY_PKG := go.keploy.io/server/cmd/server
55-
56-
.PHONY: $(KEPLOY)
57-
$(KEPLOY): $(TOOLS_BIN_DIR)
58-
$(call go-get-tool,$(KEPLOY),$(KEPLOY_PKG)@$(KEPLOY_VER))
59-
6028
.PHONY: run-keploy
61-
run-keploy: $(KEPLOY)
62-
$(KEPLOY) run &
29+
run-keploy:
30+
server run &
6331

6432
.PHONY: stop-keploy
6533
stop-keploy:
66-
@-pkill "$(KEPLOY_BIN)"
34+
@-pkill "server"
6735

6836
generate: $(CONTROLLER_GEN) ## Generate zz_generated.deepcopy.go
6937
$(CONTROLLER_GEN) paths="./..." object:headerFile="hack/boilerplate.go.txt"
7038

7139
clean: ## Remove build related file
7240
rm -fr ./bin vendor hack/tools/bin
73-
rm -f ./junit-report.xml checkstyle-report.xml ./coverage.xml ./profile.cov yamllint-checkstyle.xml
41+
rm -f checkstyle-report.xml ./coverage.out ./profile.cov yamllint-checkstyle.xml
7442

7543
## Test:
7644
test: run-keploy ## Run the tests of the project
77-
ifeq ($(EXPORT_RESULT), true)
78-
go install github.com/jstemmer/go-junit-report
79-
$(eval OUTPUT_OPTIONS = | tee /dev/tty | go-junit-report -set-exit-code > junit-report.xml)
80-
endif
81-
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS)
45+
go test -race -v ./...
8246
@$(MAKE) stop-keploy
8347

8448
coverage: run-keploy ## Run the tests of the project and export the coverage
85-
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
86-
$(GOCMD) tool cover -func profile.cov
87-
ifeq ($(EXPORT_RESULT), true)
88-
go install github.com/AlekSi/gocov-xml
89-
go install github.com/axw/gocov/gocov
90-
gocov convert profile.cov | gocov-xml > coverage.xml
91-
endif
49+
go test -race -coverprofile=coverage.out -covermode=atomic ./...
9250
@$(MAKE) stop-keploy
9351

9452
## Lint:
9553
lint: lint-go lint-yaml lint-kubebuilder ## Run all available linters
9654

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

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

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

11269
## Help:
11370
help: ## Show this help.

devbox.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/jetpack-io/devbox/0.10.1/.schema/devbox.schema.json",
3+
"packages": [
4+
"bash@latest",
5+
"coreutils@latest",
6+
"gnumake@4.4.1",
7+
"go@1.22.1",
8+
"ginkgo@2.17.0",
9+
"kubernetes-code-generator@0.25.4",
10+
"kubernetes-controller-tools@0.13.0",
11+
"yamllint@1.35.1",
12+
"path:./hack/flakes#golangci-lint",
13+
"path:./hack/flakes#yamllint-checkstyle",
14+
"path:./hack/flakes#keploy"
15+
]
16+
}

0 commit comments

Comments
 (0)