From c7c6ac8c3bdf40a5b538dc924aae824b8c260a9d Mon Sep 17 00:00:00 2001 From: Suleyman Akbas Date: Tue, 25 Apr 2023 16:28:38 +0200 Subject: [PATCH] chore: add a verify target to check go formatting and generated files Signed-off-by: Suleyman Akbas --- Makefile | 6 ++++++ config/default/manager_custom_env.yaml | 25 +++++++++++++++++++++++++ config/manager/kustomization.yaml | 7 +++++++ hack/verify-bundle.sh | 17 +++++++++++++++++ hack/verify-deps.sh | 17 +++++++++++++++++ hack/verify-generated.sh | 17 +++++++++++++++++ hack/verify-gofmt.sh | 10 ++++++++++ 7 files changed, 99 insertions(+) create mode 100644 config/default/manager_custom_env.yaml create mode 100755 hack/verify-bundle.sh create mode 100755 hack/verify-deps.sh create mode 100755 hack/verify-generated.sh create mode 100755 hack/verify-gofmt.sh diff --git a/Makefile b/Makefile index 19cc6a235..4f01400b6 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,12 @@ fmt: ## Run go fmt against code. vet: ## Run go vet against code. go vet ./... +verify: ## Verify go formatting and generated files + hack/verify-gofmt.sh + hack/verify-deps.sh + hack/verify-bundle.sh + hack/verify-generated.sh + godeps-update: ## Run go mod tidy and go mod vendor. go mod tidy && go mod vendor diff --git a/config/default/manager_custom_env.yaml b/config/default/manager_custom_env.yaml new file mode 100644 index 000000000..66ee86d2d --- /dev/null +++ b/config/default/manager_custom_env.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: operator + namespace: system + annotations: + target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' +spec: + template: + spec: + containers: + - name: manager + env: + - name: TOPOLVM_CSI_IMAGE + value: quay.io/lvms_dev/topolvm:latest + - name: CSI_LIVENESSPROBE_IMAGE + value: k8s.gcr.io/sig-storage/livenessprobe:v2.8.0 + - name: CSI_PROVISIONER_IMAGE + value: k8s.gcr.io/sig-storage/csi-provisioner:v3.3.0 + - name: CSI_REGISTRAR_IMAGE + value: k8s.gcr.io/sig-storage/csi-node-driver-registrar:v2.6.2 + - name: CSI_RESIZER_IMAGE + value: k8s.gcr.io/sig-storage/csi-resizer:v1.6.0 + - name: CSI_SNAPSHOTTER_IMAGE + value: k8s.gcr.io/sig-storage/csi-snapshotter:v6.1.0 diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 4fe5ccaa3..0b5e02e69 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -3,3 +3,10 @@ resources: generatorOptions: disableNameSuffixHash: true +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +images: +- name: controller + newName: quay.io/lvms_dev/lvms-operator + newTag: latest +namePrefix: lvms- diff --git a/hack/verify-bundle.sh b/hack/verify-bundle.sh new file mode 100755 index 000000000..a76610014 --- /dev/null +++ b/hack/verify-bundle.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euo pipefail + +function print_failure { + echo "There are unexpected changes to the tree when running 'make bundle'. Please" + echo "run these commands locally and double-check the Git repository for unexpected changes which may" + echo "need to be committed." + exit 1 +} + +if [ "${OPENSHIFT_CI:-false}" = true ]; then + echo "> generating the OLM bundle" + make bundle + + test -z "$(git status --porcelain | \grep -v '^??')" || print_failure + echo "> verified generated bundle and deep copy" +fi diff --git a/hack/verify-deps.sh b/hack/verify-deps.sh new file mode 100755 index 000000000..73164f799 --- /dev/null +++ b/hack/verify-deps.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euo pipefail + +function print_failure { + echo "There are unexpected changes to the vendor tree following 'go mod vendor' and 'go mod tidy'. Please" + echo "run these commands locally and double-check the Git repository for unexpected changes which may" + echo "need to be committed." + exit 1 +} + +if [ "${OPENSHIFT_CI:-false}" = true ]; then + go mod vendor + go mod tidy + + test -z "$(git status --porcelain)" || print_failure + echo "verified Go modules" +fi diff --git a/hack/verify-generated.sh b/hack/verify-generated.sh new file mode 100755 index 000000000..2511114eb --- /dev/null +++ b/hack/verify-generated.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euo pipefail + +function print_failure { + echo "There are unexpected changes to the tree when running 'make generate' and 'make manifests'. Please" + echo "run these commands locally and double-check the Git repository for unexpected changes which may" + echo "need to be committed." + exit 1 +} + +if [ "${OPENSHIFT_CI:-false}" = true ]; then + make generate + make manifests + + test -z "$(git status --porcelain | \grep -v '^??')" || print_failure + echo "verified generated manifests and deep copy" +fi diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh new file mode 100755 index 000000000..ee15575cb --- /dev/null +++ b/hack/verify-gofmt.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +go_files=$( find . -name '*.go' -not -path './vendor/*' -print ) +bad_files=$(gofmt -s -l ${go_files}) +if [[ -n "${bad_files}" ]]; then + (>&2 echo "!!! gofmt needs to be run on the listed files") + echo "${bad_files}" + (>&2 echo "Try running 'gofmt -s -d [path]' or autocorrect with 'hack/verify-gofmt.sh | xargs -n 1 gofmt -s -w'") + exit 1 +fi