1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 07:26:55 +00:00

chore: verify codegen in CI (#3343)

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-03-07 10:43:36 +01:00 committed by GitHub
parent e0503088ec
commit 51db68ba20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 5 deletions

View file

@ -64,6 +64,9 @@ jobs:
run: |
make unused-package-check
- name: Verify generated code is up to date
run: make verify-codegen
tests:
runs-on: ubuntu-latest
needs: pre-checks

View file

@ -3,6 +3,7 @@
##################################
# DEFAULTS
##################################
GIT_VERSION := $(shell git describe --match "v[0-9]*" --tags $(git rev-list --tags --max-count=1))
GIT_VERSION_DEV := $(shell git describe --match "[0-9].[0-9]-dev*")
GIT_BRANCH := $(shell git branch | grep \* | cut -d ' ' -f2)
@ -29,6 +30,7 @@ LD_FLAGS_DEV="-s -w -X $(PACKAGE)/pkg/version.BuildVersion=$(GIT_VERSION_DEV) -X
K8S_VERSION ?= $(shell kubectl version --short | grep -i server | cut -d" " -f3 | cut -c2-)
export K8S_VERSION
TEST_GIT_BRANCH ?= main
##################################
# KYVERNO
##################################
@ -50,6 +52,7 @@ PWD := $(CURDIR)
##################################
# INIT CONTAINER
##################################
INITC_PATH := cmd/initContainer
INITC_IMAGE := kyvernopre
initContainer: fmt vet
@ -91,9 +94,11 @@ docker-push-initContainer-dev: docker-buildx-builder
docker-get-initContainer-digest-dev:
@docker buildx imagetools inspect --raw $(REPO)/$(INITC_IMAGE):$(IMAGE_TAG_DEV) | perl -pe 'chomp if eof' | openssl dgst -sha256 | sed 's/^.* //'
##################################
# KYVERNO CONTAINER
##################################
.PHONY: docker-build-kyverno docker-push-kyverno
KYVERNO_PATH := cmd/kyverno
KYVERNO_IMAGE := kyverno
@ -134,8 +139,8 @@ docker-push-kyverno-dev: docker-buildx-builder
docker-get-kyverno-digest-dev:
@docker buildx imagetools inspect --raw $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG_DEV) | perl -pe 'chomp if eof' | openssl dgst -sha256 | sed 's/^.* //'
##################################
##################################
# Generate Docs for types.go
##################################
@ -193,9 +198,6 @@ create-e2e-infrastruture: docker-build-initContainer-local docker-build-kyverno-
chmod a+x $(PWD)/scripts/create-e2e-infrastruture.sh
$(PWD)/scripts/create-e2e-infrastruture.sh
##################################
##################################
# Testing & Code-Coverage
##################################
@ -296,13 +298,20 @@ release-notes:
@bash -c 'while IFS= read -r line ; do if [[ "$$line" == "## "* && "$$line" != "## $(VERSION)" ]]; then break ; fi; echo "$$line"; done < "CHANGELOG.md"' \
true
##################################
# CODEGEN
##################################
.PHONY: kyverno-crd
kyverno-crd: controller-gen
$(CONTROLLER_GEN) crd paths=./api/kyverno/... crd:crdVersions=v1 output:dir=./config/crds
.PHONY: report-crd
report-crd: controller-gen
$(CONTROLLER_GEN) crd paths=./api/policyreport/... crd:crdVersions=v1 output:dir=./config/crds
# install the right version of controller-gen
.PHONY: install-controller-gen
install-controller-gen:
@{ \
set -e ;\
@ -315,6 +324,7 @@ install-controller-gen:
CONTROLLER_GEN=$(GOPATH)/bin/controller-gen
# setup controller-gen with the right version, if necessary
.PHONY: controller-gen
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
@ -334,9 +344,22 @@ CONTROLLER_GEN=$(shell which controller-gen)
endif
# Bootstrap auto-generable code associated with deepcopy
.PHONY: deepcopy-autogen
deepcopy-autogen: controller-gen
$(CONTROLLER_GEN) object:headerFile="scripts/boilerplate.go.txt" paths="./..."
.PHONY: codegen
codegen: kyverno-crd report-crd deepcopy-autogen
.PHONY: verify-codegen
verify-codegen: codegen
git add --all
git diff api
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen".'
@echo 'To correct this, locally run "make codegen", commit the changes, and re-run tests.'
git diff --quiet --exit-code api
.PHONY: goimports
goimports:
ifeq (, $(shell which goimports))
@{ \
@ -349,9 +372,11 @@ GO_IMPORTS=$(shell which goimports)
endif
# Run go fmt against code
.PHONY: fmt
fmt: goimports
go fmt ./... && $(GO_IMPORTS) -w ./
.PHONY: vet
vet:
go vet ./...
@ -362,4 +387,3 @@ vet:
.PHONY: gen-helm-docs
gen-helm-docs: ## Generate Helm docs
@docker run -v ${PWD}:/work -w /work jnorwood/helm-docs:v1.6.0 -s file