diff --git a/.github/workflows/release_docs.yaml b/.github/workflows/release_docs.yaml index fdb2a683fc..01382b2e07 100644 --- a/.github/workflows/release_docs.yaml +++ b/.github/workflows/release_docs.yaml @@ -30,14 +30,24 @@ jobs: path: docs.konghq.com fetch-depth: 0 - - name: Generate docs + - name: Generate CRDs reference run: | ./scripts/apidocs-gen/post-process-for-konghq.sh \ docs.konghq.com/app/_src/kubernetes-ingress-controller/references/custom-resources-${{ steps.semver_parser.outputs.major }}.${{ steps.semver_parser.outputs.minor }}.x.md + - name: Generate flags reference + run: | + go run ./hack/generate-flags-markdown > docs.konghq.com/app/_src/kubernetes-ingress-controller/references/flags-${{ steps.semver_parser.outputs.major }}.${{ steps.semver_parser.outputs.minor }}.x.md + - name: Detect changes id: detect-changes - run: echo "HAS_CHANGES=$(cd docs.konghq.com && git status --porcelain)" >> $GITHUB_OUTPUT + run: | + if [[ `cd docs.konghq.com && git status --porcelain` ]]; then + echo "Changes detected in docs repo" + echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT + else + echo "No changes detected in docs repo" + fi - name: GPG sign the commits uses: crazy-max/ghaction-import-gpg@82a020f1f7f605c65dd2449b392a52c3fcfef7ef diff --git a/hack/generate-flags-markdown/main.go b/hack/generate-flags-markdown/main.go new file mode 100644 index 0000000000..2e492da225 --- /dev/null +++ b/hack/generate-flags-markdown/main.go @@ -0,0 +1,51 @@ +package main + +import ( + "fmt" + "strings" + + "github.com/kong/kubernetes-ingress-controller/v2/internal/manager" + "github.com/spf13/pflag" +) + +// This program generates markdown documentation for the KIC executable's flags. +// It skips deprecated and hidden flags. +func main() { + cfg := manager.Config{} + flags := cfg.FlagSet() + + markdown := strings.Builder{} + markdown.WriteString("---\ntitle: CLI Arguments\n---\n\nVarious settings and configurations of the controller can be tweaked\nusing CLI flags.\n\n## Environment variables\n\nEach flag defined in the table below can also be configured using\nan environment variable. The name of the environment variable is `CONTROLLER_`\nstring followed by the name of flag in uppercase.\n\nFor example, `--ingress-class` can be configured using the following\nenvironment variable:\n\n```\nCONTROLLER_INGRESS_CLASS=kong-foobar\n```\n\nIt is recommended that all the configuration is done via environment variables\nand not CLI flags.\n\n") + markdown.WriteString("## Flags\n") + markdown.WriteString("| Flag | Type | Description | Default |\n") + markdown.WriteString("| ---- | ---- | ----------- | ------- |\n") + + flags.VisitAll(func(flag *pflag.Flag) { + // Skip deprecated flags. + if flag.Deprecated != "" { + return + } + + name := fmt.Sprintf("`--%s`", flag.Name) + typ := fmt.Sprintf("`%s`", flag.Value.Type()) + + description := flag.Usage + // Make sure the first letter is capitalized. + if first := description[0]; first >= 'a' && first <= 'z' { + description = strings.ToUpper(string(first)) + description[1:] + } + // Make sure the last character is a period. + if last := description[len(description)-1]; last != '.' { + description += "." + } + + defaultValue := "" + if flag.DefValue != "" { + defaultValue = fmt.Sprintf("`%s`", flag.DefValue) + } + + markdown.WriteString(fmt.Sprintf("| %s | %s | %s | %s |\n", name, typ, description, defaultValue)) + }) + + fmt.Println(markdown.String()) +}