Skip to content

Commit

Permalink
Add consistency check for deepcopy generated files (#1127)
Browse files Browse the repository at this point in the history
Add consistency check for deepcopy generated files
  • Loading branch information
varungup90 authored Jun 2, 2023
1 parent fe29409 commit 70ef243
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/consistency-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
- name: Verify Codegen
working-directory: ./ray-operator
run: ./hack/verify-codegen.sh

- name: Verify Generated Files
working-directory: ./ray-operator
run: ./hack/verify-generated-files.sh
# 1. Check consistency between types.go and CRD YAML files.
# 2. Check consistency between kubebuilder markers and RBAC.
ray-operator-verify-crd-rbac:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ jobs:
skip-pkg-cache: true

- name: Run goimports
run: test -z "$(set -o pipefail && $(go env GOPATH)/bin/goimports -l apiserver/ ray-operator/ cli/ | tee goimports.out)" || { cat goimports.out && exit 1; }
run: test -z "$(set -o pipefail && $(go env GOPATH)/bin/goimports -l apiserver/ cli/ $(find ./ray-operator -name "*.go" | grep -v zz_generated.deepcopy.go) | tee goimports.out)" || { cat goimports.out && exit 1; }

- name: Open this to see how to fix goimports if it fails
run: |
echo "Run command 'goimports -w apiserver/ ray-operator/ cli/' to correct your code format."
echo "Run command 'goimports -w apiserver/ cli/ $(find ./ray-operator -name "*.go" | grep -v zz_generated.deepcopy.go)' to correct your code format."
echo "Proposed format changes:"
$(go env GOPATH)/bin/goimports -d apiserver/ ray-operator/ cli/
$(go env GOPATH)/bin/goimports -d apiserver/ cli/ $(find ./ray-operator -name "*.go" | grep -v zz_generated.deepcopy.go)
if: failure()

- name: Run gofumpt
Expand Down
2 changes: 1 addition & 1 deletion ray-operator/apis/ray/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions ray-operator/hack/verify-generated-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..

DIFFROOT="${SCRIPT_ROOT}/apis"
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/apis"
_tmp="${SCRIPT_ROOT}/_tmp"

cleanup() {
rm -rf "${_tmp}"
}
trap "cleanup" EXIT SIGINT

cleanup

mkdir -p "${TMP_DIFFROOT}"
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"

make generate
echo "diffing ${DIFFROOT} against freshly generated deepcopy files"
ret=0
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
if [[ $ret -eq 0 ]]
then
echo "${DIFFROOT} up to date."
else
echo "${DIFFROOT} is out of date. Please run make generate"
exit 1
fi

0 comments on commit 70ef243

Please sign in to comment.