Skip to content

Commit

Permalink
add some small, single-purpose scripts (#1491)
Browse files Browse the repository at this point in the history
  • Loading branch information
cofyc authored and sre-bot committed Jan 8, 2020
1 parent 51663f7 commit cb35092
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 85 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ check-setup:
@which retool >/dev/null 2>&1 || GO111MODULE=off go get github.com/twitchtv/retool
@GO111MODULE=off retool sync

check: check-setup lint tidy check-static check-codegen check-terraform check-boilerplate
check: check-setup lint tidy check-static check-codegen check-terraform check-boilerplate check-openapi-spec check-crd-groups

check-static:
@ # Not running vet and fmt through metalinter becauase it ends up looking at vendor
Expand All @@ -158,6 +158,12 @@ check-terraform:
check-boilerplate:
./hack/verify-boilerplate.sh

check-openapi-spec:
./hack/verify-openapi-spec.sh

check-crd-groups:
./hack/verify-crd-groups.sh

# TODO: staticcheck is too slow currently
staticcheck:
@echo "gometalinter staticcheck"
Expand Down
78 changes: 0 additions & 78 deletions hack/crd-groups.sh

This file was deleted.

26 changes: 26 additions & 0 deletions hack/update-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Copyright 2020 PingCAP, Inc.
#
# 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,
# See the License for the specific language governing permissions and
# limitations under the License.

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

ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
cd $ROOT

hack/update-codegen.sh
hack/update-test-codegen.sh
hack/update-openapi-spec.sh
hack/update-crd-groups.sh
2 changes: 0 additions & 2 deletions hack/codegen.sh → hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/pingcap/tidb-operator/pkg/apis \
pingcap:v1alpha1 \
--go-header-file ./hack/boilerplate/boilerplate.generatego.txt

./hack/crd-groups.sh generate
40 changes: 40 additions & 0 deletions hack/update-crd-groups.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

# Copyright 2020 PingCAP, Inc.
#
# 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,
# See the License for the specific language governing permissions and
# limitations under the License.

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

ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
cd $ROOT

source "${ROOT}/hack/lib.sh"

crd_target="$ROOT/manifests/crd.yaml"

# Ensure that we find the binaries we build before anything else.
export GOBIN="${OUTPUT_BIN}"
PATH="${GOBIN}:${PATH}"

# Enable go modules explicilty.
export GO111MODULE=on
go install github.com/pingcap/tidb-operator/cmd/to-crdgen

to-crdgen generate tidbcluster > $crd_target
to-crdgen generate backup >> $crd_target
to-crdgen generate restore >> $crd_target
to-crdgen generate backupschedule >> $crd_target
to-crdgen generate tidbmonitor >> $crd_target
to-crdgen generate tidbinitializer >> $crd_target
35 changes: 35 additions & 0 deletions hack/update-openapi-spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# Copyright 2020 PingCAP, Inc.
#
# 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,
# See the License for the specific language governing permissions and
# limitations under the License.

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

ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
cd $ROOT

source "${ROOT}/hack/lib.sh"

# Ensure that we find the binaries we build before anything else.
export GOBIN="${OUTPUT_BIN}"
PATH="${GOBIN}:${PATH}"

# Enable go modules explicilty.
export GO111MODULE=on
go install k8s.io/code-generator/cmd/openapi-gen

openapi-gen --go-header-file=./hack/boilerplate/boilerplate.generatego.txt \
-i github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/api/core/v1 \
-p apis/pingcap/v1alpha1 -O openapi_generated -o ./pkg
File renamed without changes.
24 changes: 24 additions & 0 deletions hack/verify-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

# Copyright 2020 PingCAP, Inc.
#
# 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,
# See the License for the specific language governing permissions and
# limitations under the License.

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

ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
cd $ROOT

make check-setup
make check
6 changes: 2 additions & 4 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ cleanup
mkdir -p "${TMP_DIFFROOT}"
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"

"${ROOT}/hack/codegen.sh"
"${ROOT}/hack/update-codegen.sh"
echo "diffing ${DIFFROOT} against freshly generated codegen"
ret=0
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}"
if [[ $ret -eq 0 ]]; then
echo "${DIFFROOT} up to date."
else
echo "${DIFFROOT} is out of date. Please run hack/codegen.sh"
echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh"
exit 1
fi

${ROOT}/hack/crd-groups.sh verify
38 changes: 38 additions & 0 deletions hack/verify-crd-groups.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# Copyright 2020 PingCAP, Inc.
#
# 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,
# See the License for the specific language governing permissions and
# limitations under the License.

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

ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
cd $ROOT

target="manifests/crd.yaml"
verify_tmp=$(mktemp)
trap "rm -f $verify_tmp" EXIT

cp "$target" "${verify_tmp}"

hack/update-crd-groups.sh

echo "diffing $target with $verify_tmp" >&2
diff=$(diff "$target" "$verify_tmp") || true
if [[ -n "${diff}" ]]; then
echo "${diff}" >&2
echo >&2
echo "Run ./hack/update-crd-groups.sh" >&2
exit 1
fi
38 changes: 38 additions & 0 deletions hack/verify-openapi-spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# Copyright 2020 PingCAP, Inc.
#
# 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,
# See the License for the specific language governing permissions and
# limitations under the License.

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

ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
cd $ROOT

target="pkg/apis/pingcap/v1alpha1/openapi_generated.go"
verify_tmp=$(mktemp)
trap "rm -f $verify_tmp" EXIT

cp "$target" "${verify_tmp}"

hack/update-openapi-spec.sh

echo "diffing $target with $verify_tmp" >&2
diff=$(diff "$target" "$verify_tmp") || true
if [[ -n "${diff}" ]]; then
echo "${diff}" >&2
echo >&2
echo "Run ./hack/update-openapi-spec.sh" >&2
exit 1
fi

0 comments on commit cb35092

Please sign in to comment.