github.com/jenkins-x/jx-api@v0.0.24/Makefile.codegen (about) 1 CODE_GEN_BIN_NAME := codegen 2 CODE_GEN_GO_DEPENDENCIES := $(call rwildcard,cmd/codegen/,*.go) 3 CODE_GEN_BUILDFLAGS := 4 ifdef DEBUG 5 CODE_GEN_BUILDFLAGS := -gcflags "all=-N -l" $(CODE_GEN_BUILDFLAGS) 6 endif 7 8 PEGOMOCK_VERSION := v2.7.0 9 CLIENTSET_GENERATOR_VERSION := kubernetes-1.15.12 10 GEN_APIDOCS_VERSION := v0.0.0-20190912061656-a61bc210ee54 11 OPENAPI_GEN_VERSION := 36ebc4887cdc 12 13 build-codegen: build/$(CODE_GEN_BIN_NAME) ## Build the code generator 14 15 build/$(CODE_GEN_BIN_NAME): $(CODE_GEN_GO_DEPENDENCIES) 16 CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(CODE_GEN_BUILDFLAGS) -o build/$(CODE_GEN_BIN_NAME) cmd/codegen/codegen.go 17 18 test-codegen: ## Test the code geneator 19 CGO_ENABLED=$(CGO_ENABLED) $(GO) test -v -short ./cmd/codegen/... 20 21 # Generate go code using generate directives in files and kubernetes code generation 22 # Anything generated by this target should be checked in 23 generate: build-codegen install-generate-deps generate-mocks generate-openapi generate-client ## Generate the Go code (crds, mocks, openapi, client) 24 @$(MAKE) fmt 25 @$(MAKE) importfmt 26 @echo "Generation complete" 27 28 install-generate-deps: 29 $(GO) get github.com/petergtz/pegomock/...@$(PEGOMOCK_VERSION) 30 31 generate-mocks: install-generate-deps go-generate fmt importfmt ## Generate the mocks 32 33 go-generate: 34 @echo "Generating Mocks using pegomock" 35 $(GO) generate ./... 36 37 generate-client: codegen-clientset codegen-config fmt importfmt ## Generate the client 38 39 codegen-clientset: build-codegen ## Generate the k8s types and clients 40 # sleep for one second to prevent collision with previous codegen's replacement of go.mod 41 sleep 1 42 @echo "Generating Kubernetes Clients for pkg/apis in pkg/client for jenkins.io:v1" 43 ./build/$(CODE_GEN_BIN_NAME) --generator-version $(CLIENTSET_GENERATOR_VERSION) clientset --output-package=pkg/client --input-package=pkg/apis --group-with-version=jenkins.io:v1 44 45 codegen-config: build-codegen ## Generate the deepcopy for the config, jenkinsfile, and tekton/syntax packages 46 # sleep for one second to prevent collision with previous codegen's replacement of go.mod 47 sleep 1 48 ./build/$(CODE_GEN_BIN_NAME) --generator-version $(CLIENTSET_GENERATOR_VERSION) clientset --generator deepcopy --output-package=pkg --input-package=pkg --group-with-version=config: 49 50 # Generated docs are not checked in 51 generate-docs: build-codegen ## Generate the docs 52 @echo "Generating HTML docs for Kubernetes Clients" 53 ./build/$(CODE_GEN_BIN_NAME) --generator-version $(GEN_APIDOCS_VERSION) docs 54 55 generate-openapi: codegen-openapi fmt importfmt 56 57 codegen-openapi: build-codegen 58 @echo "Generating OpenAPI structs for Kubernetes Clients" 59 ./build/$(CODE_GEN_BIN_NAME) --generator-version $(OPENAPI_GEN_VERSION) openapi --output-package=pkg/client --input-package=github.com/jenkins-x/jx-api/pkg/apis --group-with-version=jenkins.io:v1 --version=1.0 --module-name=github.com/jenkins-x/jx-api 60 61 install-refdocs: 62 $(GO) get github.com/jenkins-x/gen-crd-api-reference-docs 63 64 generate-refdocs: generate-api-refdocs generate-config-refdocs 65 66 generate-api-refdocs: install-refdocs 67 ${GOPATH}/bin/gen-crd-api-reference-docs -config "docs/refdocs/config.json" \ 68 -template-dir docs/refdocs/templates \ 69 -api-dir "./pkg/apis/jenkins.io" \ 70 -out-file docs/apidocs.md 71 72 generate-config-refdocs: 73 ${GOPATH}/bin/gen-crd-api-reference-docs -config "docs/configdocs/config.json" \ 74 -template-dir docs/configdocs/templates \ 75 -api-dir "./pkg/config" \ 76 -out-file docs/config.md 77 78 stash: 79 # Making sure repo has no outstanding changes 80 git stash 81 82 # Verifies that generated code is in sync with implementation 83 verify-generation-complete: stash generate ## Verify the generated code is up to date 84 $(eval CHANGED = $(shell git ls-files --modified --others --exclude-standard)) 85 @if [ "$(CHANGED)" == "" ]; \ 86 then \ 87 echo "All generated files up to date"; \ 88 else \ 89 echo "Code generation is out of date"; \ 90 echo "$(CHANGED)"; \ 91 git diff; \ 92 exit 1; \ 93 fi 94