Skip to content

Commit

Permalink
Add scripts to verify generated codes and Go Modules (#1999)
Browse files Browse the repository at this point in the history
Signed-off-by: tenzen-y <[email protected]>

Signed-off-by: tenzen-y <[email protected]>
  • Loading branch information
tenzen-y authored Nov 30, 2022
1 parent bd91301 commit 6b54eb2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/test-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,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
36 changes: 29 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ HAS_LINT := $(shell command -v golangci-lint;)
HAS_YAMLLINT := $(shell command -v yamllint;)
HAS_SHELLCHECK := $(shell command -v shellcheck;)
HAS_SETUP_ENVTEST := $(shell command -v setup-envtest;)
HAS_MOCKGEN := $(shell command -v mockgen;)

COMMIT := v1beta1-$(shell git rev-parse --short=7 HEAD)
KATIB_REGISTRY := docker.io/kubeflowkatib
CPU_ARCH ?= amd64
ENVTEST_K8S_VERSION ?= 1.25
MOCKGEN_VERSION ?= $(shell grep 'github.com/golang/mock' go.mod | cut -d ' ' -f 2)
GO_VERSION=$(shell grep '^go' go.mod | cut -d ' ' -f 2)

# for pytest
PYTHONPATH := $(PYTHONPATH):$(CURDIR)/pkg/apis/manager/v1beta1/python:$(CURDIR)/pkg/apis/manager/health/python
Expand All @@ -21,26 +24,26 @@ test: envtest
envtest:
ifndef HAS_SETUP_ENVTEST
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@2c3a6fa2996c026b284c7fe2b055274cd9a556bc #v0.13.0
@echo "setup-envtest has been installed"
$(info "setup-envtest has been installed")
endif
@echo "setup-envtest has already installed"
$(info "setup-envtest has already installed")

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

fmt:
hack/verify-gofmt.sh

lint:
ifndef HAS_LINT
go install github.com/golangci/golangci-lint/cmd/[email protected]
@echo "golangci-lint has been installed"
$(info "golangci-lint has been installed")
endif
hack/verify-golangci-lint.sh

yamllint:
ifndef HAS_YAMLLINT
pip install yamllint
@echo "yamllint has been installed"
$(info "yamllint has been installed")
endif
hack/verify-yamllint.sh

Expand All @@ -50,7 +53,7 @@ vet:
shellcheck:
ifndef HAS_SHELLCHECK
bash hack/install-shellcheck.sh
@echo "shellcheck has been installed"
$(info "shellcheck has been installed")
endif
hack/verify-shellcheck.sh

Expand All @@ -65,19 +68,38 @@ deploy:
undeploy:
bash scripts/v1beta1/undeploy.sh

generated-codes: generate
ifneq ($(shell bash hack/verify-generated-codes.sh '.'; echo $$?),0)
$(error 'Please run "make generate" to generate codes')
endif

go-mod: sync-go-mod
ifneq ($(shell bash hack/verify-generated-codes.sh 'go.*'; echo $$?),0)
$(error 'Please run "go mod tidy -go $(GO_VERSION)" to sync Go modules')
endif

sync-go-mod:
go mod tidy -go $(GO_VERSION)

# Run this if you update any existing controller APIs.
# 1. Genereate deepcopy, clientset, listers, informers for the APIs (hack/update-codegen.sh)
# 1. Generate deepcopy, clientset, listers, informers for the APIs (hack/update-codegen.sh)
# 2. Generate open-api for the APIs (hack/update-openapigen)
# 3. Generate Python SDK for Katib (hack/gen-python-sdk/gen-sdk.sh)
# 4. Generate gRPC manager APIs (pkg/apis/manager/v1beta1/build.sh and pkg/apis/manager/health/build.sh)
# 5. Generate Go mock codes
generate:
ifndef GOPATH
$(error GOPATH not defined, please define GOPATH. Run "go help gopath" to learn more about GOPATH)
endif
ifndef HAS_MOCKGEN
go install github.com/golang/mock/mockgen@$(MOCKGEN_VERSION)
$(info "mockgen has been installed")
endif
go generate ./pkg/... ./cmd/...
hack/gen-python-sdk/gen-sdk.sh
pkg/apis/manager/v1beta1/build.sh
pkg/apis/manager/health/build.sh
hack/update-mockgen.sh

# Build images for the Katib v1beta1 components.
build: generate
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

PATHS=( "${@}" )
cd "$(dirname "$0")/.."

git diff --exit-code -- "${PATHS[@]}" > /dev/null

0 comments on commit 6b54eb2

Please sign in to comment.