Skip to content

Commit f45e027

Browse files
rmainworkRubenSandwichboruszak
authored
Publish documentation to UDR instead of the Consul repo (#4953)
* Rename docs path to something more meaningful * Write docs to UDR instead of consul repo * Update instructions for UDR instead of consul repo * Fix incorrect error reporting code Co-authored-by: Ruben Nic <RubenSandwich@users.noreply.github.com> * Fail Early Fail early if any of the following are true: - versionMetadata is empty - versionMetadata fails to parse - latestVersion is not set --------- Co-authored-by: Ruben Nic <RubenSandwich@users.noreply.github.com> Co-authored-by: Jeff Boruszak <104028618+boruszak@users.noreply.github.com>
1 parent f76d45d commit f45e027

File tree

3 files changed

+76
-17
lines changed

3 files changed

+76
-17
lines changed

CONTRIBUTING.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,23 +1184,35 @@ generated from our `values.yaml` file.
11841184

11851185
To generate the docs and update the `helm.mdx` file:
11861186

1187-
1. Fork `hashicorp/consul` (https://github.com/hashicorp/consul) on GitHub.
1187+
1. Fork `hashicorp/web-unified-docs` (https://github.com/hashicorp/web-unified-docs) on GitHub.
11881188
1. Clone your fork:
11891189
```shell-session
1190-
git clone https://github.com/<your-username>/consul.git
1190+
git clone https://github.com/<your-username>/web-unified-docs.git
1191+
```
1192+
1. Change directory to `web-unified-docs`:
1193+
```shell-session
1194+
cd /path/to/web-unified-docs
1195+
```
1196+
1. Install NPM dependencies
1197+
```shell-session
1198+
npm i
1199+
```
1200+
1. Compile version metadata file
1201+
```shell-session
1202+
npm run prebuild -- --onlyVersionMetadata
11911203
```
11921204
1. Change directory into your `consul-k8s` repo:
11931205
```shell-session
11941206
cd /path/to/consul-k8s
11951207
```
11961208
1. Run `make gen-helm-docs` using the path to your consul (not consul-k8s) repo:
11971209
```shell-session
1198-
make gen-helm-docs consul=<path-to-consul-repo>
1210+
make gen-helm-docs docsRepo=<path-to-docs-repo>
11991211
# Examples:
1200-
# make gen-helm-docs consul=/Users/my-name/code/hashicorp/consul
1201-
# make gen-helm-docs consul=../consul
1212+
# make gen-helm-docs docsRepo=/Users/my-name/code/web-unified-docs
1213+
# make gen-helm-docs docsRepo=../web-unified-docs
12021214
```
1203-
1. Open up a pull request to `hashicorp/consul` (in addition to your `hashicorp/consul-k8s` pull request)
1215+
1. Open up a pull request to `hashicorp/web-unified-docs` (in addition to your `hashicorp/consul-k8s` pull request)
12041216

12051217
### values.yaml Annotations
12061218

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ GOTESTSUM_PATH?=$(shell command -v gotestsum)
1515

1616
.PHONY: gen-helm-docs
1717
gen-helm-docs: ## Generate Helm reference docs from values.yaml and update Consul website. Usage: make gen-helm-docs consul=<path-to-consul-repo>.
18-
@cd hack/helm-reference-gen; go run ./... $(consul)
18+
@cd hack/helm-reference-gen; go run ./... $(docsRepo)
1919

2020
.PHONY: copy-crds-to-chart
2121
copy-crds-to-chart: ## Copy generated CRD YAML into charts/consul. Usage: make copy-crds-to-chart
@@ -315,7 +315,7 @@ ifeq (, $(shell which copywrite))
315315
@echo "Installing copywrite"
316316
@go install github.com/hashicorp/copywrite@latest
317317
endif
318-
@copywrite headers --spdx "MPL-2.0"
318+
@copywrite headers --spdx "MPL-2.0"
319319

320320
##@ CI Targets
321321

hack/helm-reference-gen/main.go

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"text/template"
2323

2424
"gopkg.in/yaml.v3"
25+
"encoding/json"
2526
)
2627

2728
const (
@@ -75,7 +76,7 @@ var (
7576

7677
func main() {
7778
validateFlag := flag.Bool("validate", false, "only validate that the markdown can be generated, don't actually generate anything")
78-
consulRepoPath := "../../../consul"
79+
docsRepoPath := "../../../web-unified-docs"
7980
flag.Parse()
8081

8182
if len(os.Args) > 3 {
@@ -86,17 +87,17 @@ func main() {
8687
if !*validateFlag {
8788
// Only argument is path to Consul repo. If not set then we default.
8889
if len(os.Args) < 2 {
89-
abs, _ := filepath.Abs(consulRepoPath)
90-
fmt.Printf("Defaulting to Consul repo path: %s\n", abs)
90+
abs, _ := filepath.Abs(docsRepoPath)
91+
fmt.Printf("Defaulting to docs repo path: %s\n", abs)
9192
} else {
9293
// Support absolute and relative paths to the Consul repo.
9394
if filepath.IsAbs(os.Args[1]) {
94-
consulRepoPath = os.Args[1]
95+
docsRepoPath = os.Args[1]
9596
} else {
96-
consulRepoPath = filepath.Join("../..", os.Args[1])
97+
docsRepoPath = filepath.Join("../..", os.Args[1])
9798
}
98-
abs, _ := filepath.Abs(consulRepoPath)
99-
fmt.Printf("Using Consul repo path: %s\n", abs)
99+
abs, _ := filepath.Abs(docsRepoPath)
100+
fmt.Printf("Using docs repo path: %s\n", abs)
100101
}
101102
}
102103

@@ -118,8 +119,54 @@ func main() {
118119
os.Exit(0)
119120
}
120121

121-
// Otherwise we'll go on to write the changes to the helm docs.
122-
helmReferenceFile := filepath.Join(consulRepoPath, "website/content/docs/reference/k8s/helm.mdx")
122+
// Open the JSON file containing our list of Consul versions. If this doesn't
123+
// exist, you'll need to generate it by running `npm run build --onlyVersionMetadata`
124+
// in the web-unified-docs repo.
125+
versionMetadataPath := filepath.Join(docsRepoPath, "app/api/versionMetadata.json")
126+
versionMetadataBytes, err := os.ReadFile(versionMetadataPath)
127+
if err != nil {
128+
fmt.Println(err.Error())
129+
os.Exit(1)
130+
}
131+
132+
// Parse versionMetadata.json so we can choose a Consul docs version if desired
133+
// Expected shape: { "consul": [{"version":"v1.22.x","releaseStage":"stable","isLatest":true}, ...], ... }
134+
type ProductVersion struct {
135+
Version string `json:"version"`
136+
ReleaseStage string `json:"releaseStage"`
137+
IsLatest bool `json:"isLatest"`
138+
}
139+
140+
// Fail early: require non-empty file, successful parse, and an explicit latest version.
141+
if len(versionMetadataBytes) == 0 {
142+
fmt.Printf("%s is empty: ", versionMetadataPath)
143+
os.Exit(1)
144+
}
145+
146+
var versionMap map[string][]ProductVersion
147+
if err := json.Unmarshal(versionMetadataBytes, &versionMap); err != nil {
148+
fmt.Printf("failed to parse %s: %v\n", versionMetadataPath, err.Error())
149+
os.Exit(1)
150+
}
151+
152+
consulList, ok := versionMap["consul"]
153+
if !ok || len(consulList) == 0 {
154+
fmt.Printf("no 'consul' key or versions in %s: \n", versionMetadataPath)
155+
os.Exit(1)
156+
}
157+
158+
var latestVersion string
159+
for _, pv := range consulList {
160+
if pv.IsLatest {
161+
latestVersion = pv.Version
162+
break
163+
}
164+
}
165+
if latestVersion == "" {
166+
fmt.Printf("no Consul version marked isLatest=true in %s; cannot continue: \n", versionMetadataPath)
167+
os.Exit(1)
168+
}
169+
helmReferenceFile := filepath.Join(docsRepoPath, "content/consul", latestVersion, "content/docs/reference/k8s/helm.mdx")
123170
helmReferenceBytes, err := os.ReadFile(helmReferenceFile)
124171
if err != nil {
125172
fmt.Println(err.Error())

0 commit comments

Comments
 (0)