Skip to content

Commit

Permalink
feat: automatically update componentconfig tutorial
Browse files Browse the repository at this point in the history
Co-authored-by: Camila Macedo <7708031+camilamacedo86@users.noreply.github.com>

chore: refactor
  • Loading branch information
Eileen-Yu committed Feb 3, 2023
1 parent fc673e4 commit 0ba2830
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/testdata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
run: sudo rm -f /usr/local/bin/kustomize
- name: Verify testdata directory
run: make check-testdata
- name: Verify docs update
run: make check-docs
- name: Report failure
uses: nashmaniac/create-issue-action@v1.1
# Only report failures of pushes (PRs have are visible through the Checks section) to the default branch
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright 2019 The Kubernetes Authors.
# 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.
Expand Down Expand Up @@ -63,14 +63,22 @@ install: build ## Build and install the binary with the current source code. Use
##@ Development

.PHONY: generate
generate: generate-testdata ## Update/generate all mock data. You should run this commands to update the mock data after your changes.
generate: generate-testdata generate-docs ## Update/generate all mock data. You should run this commands to update the mock data after your changes.
go mod tidy

.PHONY: generate-testdata
generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/kubebuilder
rm -rf testdata/
./test/testdata/generate.sh

.PHONY: generate-docs
generate-docs: ## Update/generate the docs in $GOPATH/src/sigs.k8s.io/kubebuilder
go run hack/docs/generate_samples.go

.PHONY: check-docs
check-docs: ## Run the script to ensure that the docs are updated
./hack/docs/check.sh

.PHONY: lint
lint: golangci-lint yamllint ## Run golangci-lint linter & yamllint
$(GOLANGCI_LINT) run
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ More information can be found via the [Kubebuilder Documentation](https://book.k

## License

Copyright 2023.
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023.
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023.
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.
Expand Down Expand Up @@ -49,7 +49,6 @@ type ProjectConfig struct {

Spec ProjectConfigSpec `json:"spec,omitempty"`
Status ProjectConfigStatus `json:"status,omitempty"`

// ControllerManagerConfigurationSpec returns the configurations for controllers
cfg.ControllerManagerConfigurationSpec `json:",inline"`

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023.
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023.
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.
Expand Down
38 changes: 38 additions & 0 deletions hack/docs/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/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.


check_directory="$(dirname "$0")/../../docs/book/src/"

# Check docs directory first. If there are any uncommitted change, fail the test.
if [[ $(git status ${check_directory} --porcelain) ]]; then
echo "Generate Docs test precondition failed!"
echo "Please commit the change under docs directory before running the Generate Docs test"
exit 1
fi

make generate-docs

# Check if there are any changes to files under testdata directory.
if [[ $(git status ${check_directory} --porcelain) ]]; then
git status ${check_directory} --porcelain
git diff ${check_directory}
echo "Generate Docs failed!"
echo "Please, if you have changed the scaffolding make sure you have run: make generate"
exit 1
else
echo "Generate Docs passed!"
fi
49 changes: 49 additions & 0 deletions hack/docs/generate_samples.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
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.
*/

package main

import (
"fmt"

componentconfig "sigs.k8s.io/kubebuilder/v3/hack/docs/internal"
)

func main() {
fmt.Println("Generating documents...")

fmt.Println("Generating component-config tutorial...")
UpdateComponentConfigTutorial()

// TODO: Generate cronjob-tutorial

// TODO: Generate multiversion-tutorial
}

func UpdateComponentConfigTutorial() {
binaryPath := "/tmp/kubebuilder/bin/kubebuilder"
samplePath := "docs/book/src/component-config-tutorial/testdata/project/"

sp := componentconfig.NewSample(binaryPath, samplePath)

sp.Prepare()

sp.GenerateSampleProject()

sp.UpdateTutorial()

sp.CodeGen()
}
Loading

0 comments on commit 0ba2830

Please sign in to comment.