add protobuf verification script
Signed-off-by: guoyao <1015105054@qq.com>
This commit is contained in:
parent
acfd7e2b73
commit
7ecd80d1fe
|
@ -9,6 +9,8 @@ jobs:
|
|||
name: lint
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- name: Install Protoc
|
||||
uses: arduino/setup-protoc@v1
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: install Go
|
||||
|
@ -21,6 +23,8 @@ jobs:
|
|||
run: hack/verify-staticcheck.sh
|
||||
- name: import alias
|
||||
run: hack/verify-import-aliases.sh
|
||||
- name: protobuf
|
||||
run: hack/verify-estimator-protobuf.sh
|
||||
codegen:
|
||||
name: codegen
|
||||
runs-on: ubuntu-18.04
|
||||
|
|
|
@ -4,6 +4,8 @@ set -o errexit
|
|||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
KARMADA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
|
||||
|
||||
# Use `hack/generate-proto.sh` to generate proto files.
|
||||
|
||||
export GOPATH=$(go env GOPATH | awk -F ':' '{print $1}')
|
||||
|
@ -13,6 +15,17 @@ GO111MODULE=on go install golang.org/x/tools/cmd/goimports
|
|||
GO111MODULE=on go install k8s.io/code-generator/cmd/go-to-protobuf
|
||||
GO111MODULE=on go install github.com/gogo/protobuf/protoc-gen-gogo
|
||||
|
||||
#ref https://github.com/kubernetes/kubernetes/blob/master/hack/update-generated-protobuf-dockerized.sh
|
||||
if [[ -z "$(which protoc)" || "$(protoc --version)" != "libprotoc 3."* ]]; then
|
||||
echo "Generating protobuf requires protoc 3.0.0-beta1 or newer. Please download and"
|
||||
echo "install the platform appropriate Protobuf package for your OS: "
|
||||
echo
|
||||
echo " https://github.com/protocolbuffers/protobuf/releases"
|
||||
echo
|
||||
echo "WARNING: Protobuf changes are not being validated"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PACKAGES=(
|
||||
github.com/karmada-io/karmada/pkg/estimator/pb
|
||||
)
|
||||
|
@ -30,13 +43,14 @@ ${GOPATH}/bin/go-to-protobuf \
|
|||
--go-header-file=./hack/boilerplate/boilerplate.go.txt \
|
||||
--apimachinery-packages=$(IFS=, ; echo "${APIMACHINERY_PKGS[*]}") \
|
||||
--packages=$(IFS=, ; echo "${PACKAGES[*]}") \
|
||||
--proto-import ./vendor \
|
||||
--proto-import ./third_party/protobuf/
|
||||
--proto-import="${KARMADA_ROOT}/vendor" \
|
||||
--proto-import="${KARMADA_ROOT}/third_party/protobuf"
|
||||
|
||||
|
||||
# The `go-to-protobuf` tool will modify all import proto files in vendor, so we should use go mod vendor to prevent.
|
||||
go mod vendor
|
||||
|
||||
SERVICE_PROTO_FILES=$(find . -name "service.proto")
|
||||
SERVICE_PROTO_FILES=$(find . -not -path *./_tmp/* -name "service.proto")
|
||||
|
||||
for file in ${SERVICE_PROTO_FILES[*]}; do
|
||||
protoc \
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
KARMADA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
|
||||
_tmp="${KARMADA_ROOT}/_tmp"
|
||||
ESTIMATORPB="pkg/estimator/pb"
|
||||
|
||||
cleanup() {
|
||||
rm -rf "${_tmp}"
|
||||
}
|
||||
|
||||
trap "cleanup" EXIT SIGINT
|
||||
|
||||
cleanup
|
||||
|
||||
mkdir -p "${_tmp}/${ESTIMATORPB}"
|
||||
|
||||
cp -a "${KARMADA_ROOT}/${ESTIMATORPB}"/* "${_tmp}/${ESTIMATORPB}/"
|
||||
|
||||
source "$KARMADA_ROOT/hack/update-estimator-protobuf.sh"
|
||||
|
||||
echo "diffing ${ESTIMATORPB} against freshly generated estimator protobuf"
|
||||
ret=0
|
||||
diff -Naupr "${KARMADA_ROOT}/${ESTIMATORPB}" "${_tmp}/${ESTIMATORPB}" || ret=$?
|
||||
cp -a "${_tmp}/${ESTIMATORPB}"/* "${KARMADA_ROOT}/${ESTIMATORPB}/"
|
||||
if [[ $ret -eq 0 ]]; then
|
||||
echo "${ESTIMATORPB} is up to date."
|
||||
else
|
||||
echo "${ESTIMATORPB} is out of date. Please run hack/update-estimator-protobuf.sh to update."
|
||||
exit 1
|
||||
fi
|
Loading…
Reference in New Issue