diff --git a/Makefile b/Makefile index 3e49bccab6..701c0cf189 100644 --- a/Makefile +++ b/Makefile @@ -73,7 +73,7 @@ generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/ku .PHONY: generate-docs generate-docs: ## Update/generate the docs in $GOPATH/src/sigs.k8s.io/kubebuilder - go run hack/docs/generate_samples.go + ./hack/docs/generate.sh .PHONY: check-docs check-docs: ## Run the script to ensure that the docs are updated diff --git a/hack/docs/check.sh b/hack/docs/check.sh index 85843ce52c..b41e41bfc6 100755 --- a/hack/docs/check.sh +++ b/hack/docs/check.sh @@ -14,10 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -source "$(dirname "$0")/../../test/common.sh" - -build_kb - check_directory="$(dirname "$0")/../../docs/book/src/" # Check docs directory first. If there are any uncommitted change, fail the test. @@ -27,7 +23,8 @@ if [[ $(git status ${check_directory} --porcelain) ]]; then exit 1 fi -make generate-docs + +$(dirname "$0")/generate.sh # Check if there are any changes to files under testdata directory. if [[ $(git status ${check_directory} --porcelain) ]]; then diff --git a/hack/docs/generate.sh b/hack/docs/generate.sh new file mode 100755 index 0000000000..ac486ab5aa --- /dev/null +++ b/hack/docs/generate.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Copyright 2023 The Kubernetes 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. + +source "$(dirname "$0")/../../test/common.sh" + +build_kb + +docs_gen_directory="$(dirname "$0")/../../hack/docs/generate_samples.go" +go run ${docs_gen_directory} + diff --git a/hack/docs/generate_samples.go b/hack/docs/generate_samples.go index f2a6171003..facecea0e6 100644 --- a/hack/docs/generate_samples.go +++ b/hack/docs/generate_samples.go @@ -21,9 +21,11 @@ import ( componentconfig "sigs.k8s.io/kubebuilder/v3/hack/docs/internal/component-config-tutorial" cronjob "sigs.k8s.io/kubebuilder/v3/hack/docs/internal/cronjob-tutorial" - "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util" ) +// Make sure executing `build_kb` to generate kb executable from the source code +const KubebuilderBinName = "/tmp/kubebuilder/bin/kubebuilder" + func main() { fmt.Println("Generating documents...") @@ -36,7 +38,7 @@ func main() { } func UpdateComponentConfigTutorial() { - binaryPath := util.KubebuilderBinName + binaryPath := KubebuilderBinName samplePath := "docs/book/src/component-config-tutorial/testdata/project/" sp := componentconfig.NewSample(binaryPath, samplePath) @@ -51,7 +53,7 @@ func UpdateComponentConfigTutorial() { } func UpdateCronjobTutorial() { - binaryPath := util.KubebuilderBinName + binaryPath := KubebuilderBinName samplePath := "docs/book/src/cronjob-tutorial/testdata/project/" sp := cronjob.NewSample(binaryPath, samplePath)