From c11396be8a2b91690d57488632e3288cfcb2075a Mon Sep 17 00:00:00 2001 From: liyang Date: Fri, 14 Feb 2025 16:31:59 +0800 Subject: [PATCH 1/2] Use hawkeye to generate and check license Signed-off-by: liyang --- .github/workflows/license.yaml | 23 ++++++++++++++ Makefile | 20 +++++++++++- README.md | 5 +++ api/v1alpha1/etcdcluster_types.go | 28 ++++++++--------- api/v1alpha1/groupversion_info.go | 28 ++++++++--------- api/v1alpha1/zz_generated.deepcopy.go | 30 +++++++++--------- cmd/main.go | 28 ++++++++--------- hack/license-header.txt | 13 ++++++++ internal/controller/etcdcluster_controller.go | 28 ++++++++--------- .../controller/etcdcluster_controller_test.go | 30 +++++++++--------- internal/controller/suite_test.go | 31 +++++++++---------- internal/controller/utils.go | 16 ++++++++++ internal/controller/utils_test.go | 16 ++++++++++ internal/etcdutils/etcdutils.go | 16 ++++++++++ internal/etcdutils/etcdutils_test.go | 16 ++++++++++ licenserc.toml | 17 ++++++++++ pkg/certificate/auto/doc.go | 16 ++++++++++ pkg/certificate/cert-manager/doc.go | 16 ++++++++++ pkg/certificate/certificate.go | 16 ++++++++++ pkg/certificate/interfaces/interface.go | 16 ++++++++++ test/e2e/e2e_suite_test.go | 31 +++++++++---------- test/e2e/e2e_test.go | 31 +++++++++---------- test/utils/utils.go | 30 +++++++++--------- tools/mod/doc.go | 28 +++++++++-------- tools/mod/tools.go | 28 +++++++++-------- 25 files changed, 377 insertions(+), 180 deletions(-) create mode 100644 .github/workflows/license.yaml create mode 100644 hack/license-header.txt create mode 100644 licenserc.toml diff --git a/.github/workflows/license.yaml b/.github/workflows/license.yaml new file mode 100644 index 0000000..9cd3e0d --- /dev/null +++ b/.github/workflows/license.yaml @@ -0,0 +1,23 @@ +name: License Header Check + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + + push: + branches: + - "main" + +jobs: + license-header-check: + name: license-header-check + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check License Header + uses: korandoru/hawkeye@v6 diff --git a/Makefile b/Makefile index 02dc2b3..81051da 100644 --- a/Makefile +++ b/Makefile @@ -88,6 +88,18 @@ lint: golangci-lint ## Run golangci-lint linter lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes $(GOLANGCI_LINT) run --fix +.PHONY: check-license +check-license: ## Check License Header. + hawkeye check --config licenserc.toml + +.PHONY: format-license +format-license: ## Format License Header. + hawkeye format --config licenserc.toml + +.PHONY: remove-license +remove-license: ## Remove License Header. + hawkeye remove --config licenserc.toml + ##@ Build .PHONY: build @@ -180,6 +192,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest GOLANGCI_LINT = $(LOCALBIN)/golangci-lint CRD_REF_DOCS ?= $(LOCALBIN)/crd-ref-docs +HAWKEYE ?= $(LOCALBIN)/hawkeye ## Tool Versions KUSTOMIZE_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} sigs.k8s.io/kustomize/kustomize/v5) @@ -187,6 +200,7 @@ CONTROLLER_TOOLS_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} si ENVTEST_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} sigs.k8s.io/controller-runtime/tools/setup-envtest) GOLANGCI_LINT_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} github.com/golangci/golangci-lint) CRD_REF_DOCS_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} github.com/elastic/crd-ref-docs) +KAWKEYE_VERSION ?= v6.0.0 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. @@ -198,13 +212,17 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar $(CONTROLLER_GEN): $(LOCALBIN) $(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION)) +.PHONY: hawkeye +hawkeye: ## Download hawkeye locally if necessary, ref: https://github.com/korandoru/hawkeye. + curl --proto '=https' --tlsv1.2 -LsSf https://github.com/korandoru/hawkeye/releases/download/${KAWKEYE_VERSION}/hawkeye-installer.sh | sh + .PHONY: envtest envtest: $(ENVTEST) ## Download setup-envtest locally if necessary. $(ENVTEST): $(LOCALBIN) $(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION)) .PHONY: crd-ref-docs -crd-ref-docs: $(CRD_REF_DOCS) ## Install crd-ref-docs tool, ref: https://github.com/elastic/crd-ref-docs. +crd-ref-docs: $(CRD_REF_DOCS) ## Download crd-ref-docs locally if necessary, ref: https://github.com/elastic/crd-ref-docs. $(CRD_REF_DOCS): $(LOCALBIN) $(call go-install-tool,$(CRD_REF_DOCS),github.com/elastic/crd-ref-docs,$(CRD_REF_DOCS_VERSION)) diff --git a/README.md b/README.md index 318f408..09e9001 100644 --- a/README.md +++ b/README.md @@ -111,3 +111,8 @@ kubectl apply -f https://raw.githubusercontent.com//etcd-operator/ Date: Fri, 14 Feb 2025 16:46:32 +0800 Subject: [PATCH 2/2] delete kawkeye variable Signed-off-by: liyang --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 81051da..fea3103 100644 --- a/Makefile +++ b/Makefile @@ -192,7 +192,6 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest GOLANGCI_LINT = $(LOCALBIN)/golangci-lint CRD_REF_DOCS ?= $(LOCALBIN)/crd-ref-docs -HAWKEYE ?= $(LOCALBIN)/hawkeye ## Tool Versions KUSTOMIZE_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} sigs.k8s.io/kustomize/kustomize/v5)