Skip to content

Commit

Permalink
Generate API reference docs for Pipeline
Browse files Browse the repository at this point in the history
This is the first part of addressing tektoncd#1250 (and tektoncd/website#117).

Using https://github.com/ahmetb/gen-crd-api-reference-docs/, the tool Knative uses for this, plus my PR at ahmetb/gen-crd-api-reference-docs#43, forked to https://github.com/tektoncd/ahmetb-gen-crd-api-reference-docs, for an issue with `pkg/apis/pipeline/pod`, this adds generation of `docs/pipeline-api.md` to `hack/update-codegen.sh`.

Signed-off-by: Andrew Bayer <[email protected]>
  • Loading branch information
abayer authored and JeromeJu committed Aug 2, 2022
1 parent 4aeec8a commit e3848b2
Show file tree
Hide file tree
Showing 39 changed files with 19,540 additions and 11 deletions.
9,776 changes: 9,776 additions & 0 deletions docs/pipeline-api.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/tektoncd/pipeline
go 1.17

require (
github.com/ahmetb/gen-crd-api-reference-docs v0.3.1-0.20220720053627-e327d0730470 // Waiting for https://github.com/ahmetb/gen-crd-api-reference-docs/pull/43/files to merge
github.com/cloudevents/sdk-go/v2 v2.10.1
github.com/containerd/containerd v1.5.13
github.com/google/go-cmp v0.5.8
Expand All @@ -16,7 +17,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198
github.com/pkg/errors v0.9.1
github.com/tektoncd/plumbing v0.0.0-20220329085922-d765a5cba75f
github.com/tektoncd/plumbing v0.0.0-20220728121531-8a725746af4f
go.opencensus.io v0.23.0
go.uber.org/zap v1.21.0
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b
Expand Down Expand Up @@ -113,6 +114,7 @@ require (
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/statsd_exporter v0.21.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shurcooL/githubv4 v0.0.0-20190718010115-4ba037080260 // indirect
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
Expand Down Expand Up @@ -149,3 +151,5 @@ require (
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)

replace github.com/ahmetb/gen-crd-api-reference-docs => github.com/tektoncd/ahmetb-gen-crd-api-reference-docs v0.3.1-0.20220729140133-6ce2d5aafcb4 // Waiting for https://github.com/ahmetb/gen-crd-api-reference-docs/pull/43/files to merge
10 changes: 8 additions & 2 deletions go.sum

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

3 changes: 3 additions & 0 deletions hack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ Tekton Pipelines.
- [`update-openapigen.sh`](./update-openapigen.sh): Updates OpenAPI specification and Swagger file.
- [`verify-codegen.sh`](./verify-codegen.sh): Verifies that auto-generated
client libraries are up-to-date.
- [`update-reference-docs.sh`](./update-reference-docs.sh) and related files: Generates [`docs/pipeline-api.md`](../docs/pipeline-api.md).
- [`reference-docs-gen-config.json`](./reference-docs-gen-config.json) is the configuration file for the [`gen-api-reference-docs`](https://github.com/tektoncd/ahmetb-gen-crd-api-reference-docs) binary.
- [`reference-docs-template`](./reference-docs-template) contains Go templates for the generated Markdown.
- Release docs have been moved to [the top-level `tekton` dir](../tekton)
42 changes: 42 additions & 0 deletions hack/reference-docs-gen-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"hideMemberFields": [
"TypeMeta"
],
"hideTypePatterns": [
"ParseError$",
"List$"
],
"externalPackages": [
{
"typeMatchPrefix": "^k8s\\.io/apimachinery/pkg/apis/meta/v1\\.Duration$",
"docsURLTemplate": "https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Duration"
},
{
"typeMatchPrefix": "^k8s\\.io/(api|apimachinery/pkg/apis)/",
"docsURLTemplate": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#{{lower .TypeIdentifier}}-{{arrIndex .PackageSegments -1}}-{{arrIndex .PackageSegments -2}}"
},
{
"typeMatchPrefix": "^knative\\.dev/pkg/apis/duck",
"docsURLTemplate": "https://pkg.go.dev/knative.dev/pkg/apis/duck/{{arrIndex .PackageSegments -1}}#{{.TypeIdentifier}}"
},
{
"typeMatchPrefix": "^knative\\.dev/pkg/apis\\.URL$",
"docsURLTemplate": "https://pkg.go.dev/knative.dev/pkg/apis#URL"
},
{
"typeMatchPrefix": "^knative\\.dev/networking/pkg/apis/networking",
"docsURLTemplate": "https://pkg.go.dev/knative.dev/networking/pkg/apis/networking#{{.TypeIdentifier}}"
},
{
"typeMatchPrefix": "^time\\.Duration$",
"docsURLTemplate": "https://golang.org/pkg/time/#Duration"
}
],
"typeDisplayNamePrefixOverrides": {
"k8s.io/api/": "Kubernetes ",
"k8s.io/apimachinery/pkg/apis/": "Kubernetes "
},
"markdownDisabled": false,
"gitCommitDisabled": true
}

48 changes: 48 additions & 0 deletions hack/reference-docs-template/members.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{ define "members" }}

{{ range .Members }}
{{ if not (hiddenMember .)}}
<tr>
<td>
<code>{{ fieldName . }}</code><br/>
<em>
{{ if linkForType .Type }}
<a href="{{ linkForType .Type}}">
{{ typeDisplayName .Type }}
</a>
{{ else }}
{{ typeDisplayName .Type }}
{{ end }}
</em>
</td>
<td>
{{ if fieldEmbedded . }}
<p>
(Members of <code>{{ fieldName . }}</code> are embedded into this type.)
</p>
{{ end}}

{{ if isOptionalMember .}}
<em>(Optional)</em>
{{ end }}

{{ safe (renderComments .CommentLines) }}

{{ if and (eq (.Type.Name.Name) "ObjectMeta") }}
Refer to the Kubernetes API documentation for the fields of the
<code>metadata</code> field.
{{ end }}

{{ if or (eq (fieldName .) "spec") }}
<br/>
<br/>
<table>
{{ template "members" .Type }}
</table>
{{ end }}
</td>
</tr>
{{ end }}
{{ end }}

{{ end }}
49 changes: 49 additions & 0 deletions hack/reference-docs-template/pkg.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{ define "packages" }}

{{ with .packages}}
<p>Packages:</p>
<ul>
{{ range . }}
<li>
<a href="#{{- packageAnchorID . -}}">{{ packageDisplayName . }}</a>
</li>
{{ end }}
</ul>
{{ end}}

{{ range .packages }}
<h2 id="{{- packageAnchorID . -}}">
{{- packageDisplayName . -}}
</h2>

{{ with (index .GoPackages 0 )}}
{{ with .DocComments }}
<div>
{{ safe (renderComments .) }}
</div>
{{ end }}
{{ end }}

Resource Types:
<ul>
{{- range (visibleTypes (sortedTypes .Types)) -}}
{{ if isExportedType . -}}
<li>
<a href="{{ linkForType . }}">{{ typeDisplayName . }}</a>
</li>
{{- end }}
{{- end -}}
</ul>

{{ range (visibleTypes (sortedTypes .Types))}}
{{ template "type" . }}
{{ end }}
<hr/>
{{ end }}

<p><em>
Generated with <code>gen-crd-api-reference-docs</code>
{{ with .gitCommit }} on git commit <code>{{ . }}</code>{{end}}.
</em></p>

{{ end }}
2 changes: 2 additions & 0 deletions hack/reference-docs-template/placeholder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Placeholder file to make Go vendor this directory properly.
package template
81 changes: 81 additions & 0 deletions hack/reference-docs-template/type.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{{ define "type" }}

<h3 id="{{ anchorIDForType . }}">
{{- .Name.Name }}
{{ if eq .Kind "Alias" }}(<code>{{.Underlying}}</code> alias){{ end -}}
</h3>
{{ with (typeReferences .) }}
<p>
(<em>Appears on:</em>
{{- $prev := "" -}}
{{- range . -}}
{{- if $prev -}}, {{ end -}}
{{- $prev = . -}}
<a href="{{ linkForType . }}">{{ typeDisplayName . }}</a>
{{- end -}}
)
</p>
{{ end }}

<div>
{{ safe (renderComments .CommentLines) }}
</div>

{{ with (constantsOfType .) }}
<table>
<thead>
<tr>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{{- range . -}}
<tr>
{{- /*
renderComments implicitly creates a <p> element, so we
add one to the display name as well to make the contents
of the two cells align evenly.
*/ -}}
<td><p>{{ typeDisplayName . }}</p></td>
<td>{{ safe (renderComments .CommentLines) }}</td>
</tr>
{{- end -}}
</tbody>
</table>
{{ end }}

{{ if .Members }}
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{{ if isExportedType . }}
<tr>
<td>
<code>apiVersion</code><br/>
string</td>
<td>
<code>
{{apiGroup .}}
</code>
</td>
</tr>
<tr>
<td>
<code>kind</code><br/>
string
</td>
<td><code>{{.Name.Name}}</code></td>
</tr>
{{ end }}
{{ template "members" .}}
</tbody>
</table>
{{ end }}

{{ end }}
2 changes: 2 additions & 0 deletions hack/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ import (
_ "k8s.io/kube-openapi/cmd/openapi-gen"

_ "knative.dev/pkg/codegen/cmd/injection-gen"

_ "github.com/ahmetb/gen-crd-api-reference-docs"
)
3 changes: 3 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ ${REPO_ROOT_DIR}/hack/update-deps.sh

# Make sure the OpenAPI specification and Swagger file are up-to-date
${REPO_ROOT_DIR}/hack/update-openapigen.sh

# Make sure the generated API reference docs are up-to-date
${REPO_ROOT_DIR}/hack/update-reference-docs.sh
26 changes: 26 additions & 0 deletions hack/update-reference-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Copyright 2020 The Tekton 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.

set -o errexit
set -o nounset

echo "Generating API reference docs ..."
go run github.com/ahmetb/gen-crd-api-reference-docs \
-config "./hack/reference-docs-gen-config.json" \
-api-dir "github.com/tektoncd/pipeline/pkg/apis" \
-template-dir "./hack/reference-docs-template" \
-out-file "./docs/pipeline-api.md"
sed -i '1s/^/<!--\n---\ntitle: Pipeline API\nlinkTitle: Pipeline API\nweight: 1000\n---\n-->\n\n/' ./docs/pipeline-api.md
18 changes: 18 additions & 0 deletions pkg/apis/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2019 The Tekton 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 apis contains API Schema definitions for the various API groups
package apis
5 changes: 3 additions & 2 deletions pkg/apis/pipeline/pod/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// +k8s:openapi-gen=true

// Package pod contains non-versioned pod configuration
// +k8s:openapi-gen=true
// +gencrdrefdocs:unversionedTypes
// +groupName=tekton.dev
package pod
19 changes: 19 additions & 0 deletions pkg/apis/run/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright 2019 The Tekton 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 v1alpha1 contains API Schema definitions for the run v1alpha1 API group
// +groupName=tekton.dev
package v1alpha1
Loading

0 comments on commit e3848b2

Please sign in to comment.