Skip to content

Commit

Permalink
Add scripts to verify generated codes and Go Modules
Browse files Browse the repository at this point in the history
Signed-off-by: tenzen-y <[email protected]>
  • Loading branch information
tenzen-y committed Nov 17, 2022
1 parent a351b81 commit 4ff0e5c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/test-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,8 @@ jobs:
with:
go-version-file: ${{ env.GOPATH }}/src/github.com/kubeflow/katib/go.mod

# Verify that go.mod and go.sum is synchronized
- name: Check Go modules
run: |
go mod tidy &&
git add go.* &&
git diff --cached --exit-code || (echo 'Please run "go mod tidy" to sync Go modules' && exit 1)
- name: Run Generate And Go Format Test
run: |
go mod download &&
make check &&
git add pkg/apis hack/gen-python-sdk &&
git diff --cached --exit-code || (echo 'Please run "make check" to generate codes and to format Go codes' && exit 1)
- name: Check Go Modules, Generated Go/Python codes, and Format
run: make check

unittests:
name: Unit Test
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ifndef HAS_SETUP_ENVTEST
endif
$(info "setup-envtest has already installed")

check: generate fmt vet lint
check: generated-codes go-mod fmt vet lint

fmt:
hack/verify-gofmt.sh
Expand Down Expand Up @@ -67,6 +67,12 @@ deploy:
undeploy:
bash scripts/v1beta1/undeploy.sh

generated-codes: generate
bash hack/verify-generated-codes.sh

go-mod:
bash hack/verify-go-mod.sh

# Run this if you update any existing controller APIs.
# 1. Generate deepcopy, clientset, listers, informers for the APIs (hack/update-codegen.sh)
# 2. Generate open-api for the APIs (hack/update-openapigen)
Expand Down
24 changes: 24 additions & 0 deletions hack/verify-generated-codes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

# Copyright 2022 The Kubeflow Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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

cd "$(dirname "$0")/.."

git diff --exit-code -- 'pkg/apis' 'hack/gen-python-sdk' 'sdk/python' 'pkg/mock' > /dev/null || \
(echo 'Please run "make generate" to generate codes' && exit 1)
26 changes: 26 additions & 0 deletions hack/verify-go-mod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Copyright 2022 The Kubeflow Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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

cd "$(dirname "$0")/.."

GO_VERSION="$(grep '^go' go.mod | cut -d ' ' -f 2)"
go mod tidy -go "${GO_VERSION}"
git diff --exit-code -- 'go.*' > /dev/null || \
(echo "Please run \"go mod tidy -go ${GO_VERSION}\" to sync Go modules" && exit 1)

0 comments on commit 4ff0e5c

Please sign in to comment.