-
Notifications
You must be signed in to change notification settings - Fork 50
193 lines (177 loc) · 8.78 KB
/
generate-crd.yml
File metadata and controls
193 lines (177 loc) · 8.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
name: Generate Kubernetes Reference Docs
on:
workflow_dispatch:
inputs:
tag:
description: 'The Operator release tag for which to generate the docs (such as operator/v2.3.8-25.3.1)'
required: true
type: string
repository_dispatch:
types: [generate-crd-docs]
jobs:
trigger:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
pull-requests: write
steps:
- name: Determine tag
id: tag
run: |
if [ -n "${{ github.event.inputs.tag }}" ]; then
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
elif [ -n "${{ github.event.client_payload.tag }}" ]; then
echo "tag=${{ github.event.client_payload.tag }}" >> $GITHUB_OUTPUT
else
echo "No tag provided as input or dispatch payload" >&2
exit 1
fi
- name: Validate operator tag prefix
id: validate
run: |
TAG="${{ steps.tag.outputs.tag }}"
if [[ "$TAG" =~ ^operator/ ]]; then
echo "OPERATOR_TAG=$TAG" >> $GITHUB_ENV
else
echo "Tag does not have the operator/ prefix: $TAG" >&2
exit 1
fi
# Configure AWS credentials to get the secret for the Redpanda GitHub bot.
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.RP_AWS_CRED_REGION }}
role-to-assume: arn:aws:iam::${{ secrets.RP_AWS_CRED_ACCOUNT_ID }}:role/${{ vars.RP_AWS_CRED_BASE_ROLE_NAME }}${{ github.event.repository.name }}
- uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
,sdlc/prod/github/actions_bot_token
parse-json-secrets: true
- name: Get latest docs version
id: antora_version
shell: bash
run: |
ANTORA_VERSION=$(curl -s https://raw.githubusercontent.com/redpanda-data/docs/main/antora.yml | grep '^version:' | sed -E 's/version: *//')
echo "Latest docs version is: $ANTORA_VERSION"
echo "ANTORA_VERSION=$ANTORA_VERSION" >> $GITHUB_ENV
- name: Determine docs branch
id: set_docs_branch
shell: bash
run: |
TAG="${OPERATOR_TAG}"
echo "Original operator tag: $TAG"
# Filter the tag to include only the vmajor.minor version.
# This will remove any "operator/" prefix and any patch version information.
FILTERED_TAG=$(echo "$TAG" | sed -E 's/^(operator\/)?(v[0-9]+\.[0-9]+).*/\2/')
echo "Filtered tag (vmajor.minor): $FILTERED_TAG"
if [[ "$FILTERED_TAG" == "v2.4" ]]; then
echo "Filtered tag is v2.4. Checking docs version."
if [[ "$ANTORA_VERSION" == "25.1" ]]; then
echo "Docs main branch version is 25.1, using docs branch 'main'."
DOCS_BRANCH="main"
else
echo "Using docs branch v/24.3 for filtered tag v2.4."
if git ls-remote --exit-code --heads https://github.com/redpanda-data/docs.git refs/heads/v/24.3; then
DOCS_BRANCH="v/24.3"
else
echo "Docs branch v/24.3 not found. Skipping."
exit 0
fi
fi
else
echo "Filtered tag is: $FILTERED_TAG"
# For other tags, if the filtered tag matches the latest docs version, then use the main branch.
if [[ "$FILTERED_TAG" == "v${ANTORA_VERSION}" ]]; then
DOCS_BRANCH="main"
else
# Otherwise, derive the docs branch from the filtered tag.
DOCS_BRANCH="v/${FILTERED_TAG#v}"
if ! git ls-remote --exit-code --heads https://github.com/redpanda-data/docs.git refs/heads/"$DOCS_BRANCH"; then
echo "Docs branch $DOCS_BRANCH not found."
exit 0
fi
fi
fi
echo "DOCS_BRANCH=$DOCS_BRANCH" >> $GITHUB_ENV
echo "Using docs branch: $DOCS_BRANCH"
# Checkout the operator repository at the specified tag.
- name: Checkout redpanda operator repository
uses: actions/checkout@v4
with:
repository: redpanda-data/redpanda-operator
ref: ${{ env.OPERATOR_TAG }}
path: redpanda
token: ${{ env.ACTIONS_BOT_TOKEN }}
# Checkout the docs repository using the determined docs branch.
- name: Checkout redpanda-docs repository
uses: actions/checkout@v4
with:
repository: redpanda-data/docs
ref: ${{ env.DOCS_BRANCH }}
path: redpanda-docs
token: ${{ env.ACTIONS_BOT_TOKEN }}
- name: Download crd-ref-docs
run: |
curl -fLO https://github.com/elastic/crd-ref-docs/releases/download/v0.1.0/crd-ref-docs_0.1.0_Linux_x86_64.tar.gz
tar -xzf crd-ref-docs_0.1.0_Linux_x86_64.tar.gz
chmod +x crd-ref-docs
sudo mv crd-ref-docs /usr/local/bin/
- name: Download helm-docs
run: |
curl -sL https://github.com/norwoodj/helm-docs/releases/download/v1.11.0/helm-docs_1.11.0_Linux_x86_64.tar.gz | tar xz
echo "helm-docs" >> $GITHUB_PATH
sudo mv helm-docs /usr/local/bin/
# Install pandoc, a tool to convert between different markup formats.
- name: Install pandoc
run: |
sudo apt-get install pandoc
- name: Generate Operator CRD docs
run: |
crd-ref-docs \
--source-path=./redpanda/operator/api/redpanda/v1alpha2 \
--max-depth=10 \
--templates-dir=./redpanda-docs/.github/crd-config/templates/asciidoctor/operator \
--config=./redpanda/operator/crd-ref-docs-config.yaml \
--renderer=asciidoctor \
--output-path=./redpanda-docs/modules/reference/pages/k-crd.adoc
- name: Generate Helm docs
run: |
helm-docs
working-directory: ./redpanda
# Convert the generated Markdown Helm documentation to AsciiDoc format using pandoc.
- name: Convert Markdown to AsciiDoc
run: |
pandoc ./redpanda/charts/redpanda/chart/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-redpanda-helm-spec.adoc
pandoc ./redpanda/charts/console/chart/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-console-helm-spec.adoc
pandoc ./redpanda/operator/chart/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-operator-helm-spec.adoc
- name: Modify third-level headings format
run: |
sed -i 's/\(\[[0-9]*\)\]\./\1\\]\./g' ./redpanda-docs/modules/reference/pages/k-redpanda-helm-spec.adoc
sed -i 's/\(\[[0-9]*\)\]\./\1\\]\./g' ./redpanda-docs/modules/reference/pages/k-console-helm-spec.adoc
sed -i 's/\(\[[0-9]*\)\]\]/\1\\]\]/g' ./redpanda-docs/modules/reference/pages/k-operator-helm-spec.adoc
sed -i 's/=== \(http\([^[]\|\%5[BbDd]\)*\)\[\([^]]*\)\]/=== link:++\1++\[\3\]/' ./redpanda-docs/modules/reference/pages/k-redpanda-helm-spec.adoc
sed -i 's/=== \(http\([^[]\|\%5[BbDd]\)*\)\[\([^]]*\)\]/=== link:++\1++\[\3\]/' ./redpanda-docs/modules/reference/pages/k-console-helm-spec.adoc
sed -i 's/=== \(http\([^[]\|\%5[BbDd]\)*\)\[\([^]]*\)\]/=== link:++\1++\[\3\]/' ./redpanda-docs/modules/reference/pages/k-operator-helm-spec.adoc
- name: Correct AsciiDoc format
run: |
# Correct the title format
sed -i 's/^== # \(.*\)/= \1/' ./redpanda-docs/modules/reference/pages/k-redpanda-helm-spec.adoc
sed -i 's/^== # \(.*\)/= \1/' ./redpanda-docs/modules/reference/pages/k-console-helm-spec.adoc
sed -i 's/^== # \(.*\)/= \1/' ./redpanda-docs/modules/reference/pages/k-operator-helm-spec.adoc
# Correct the description format
sed -i 's/^== description: \(.*\)/:description: \1/' ./redpanda-docs/modules/reference/pages/k-redpanda-helm-spec.adoc
sed -i 's/^== description: \(.*\)/:description: \1/' ./redpanda-docs/modules/reference/pages/k-console-helm-spec.adoc
sed -i 's/^== description: \(.*\)/:description: \1/' ./redpanda-docs/modules/reference/pages/k-operator-helm-spec.adoc
# If changes were detected, open a pull request against the determined docs branch.
- name: Create pull request
uses: peter-evans/create-pull-request@v6
with:
commit-message: "auto-docs: Update CRD reference doc for release ${{ env.OPERATOR_TAG }}"
token: ${{ env.ACTIONS_BOT_TOKEN }}
path: redpanda-docs
branch: auto-docs/update-${{ env.OPERATOR_TAG }}
base: ${{ env.DOCS_BRANCH }}
title: "auto-docs: Update CRD reference doc for release ${{ env.OPERATOR_TAG }}"
body: |
This PR updates the CRD reference documentation for operator release ${{ env.OPERATOR_TAG }}.
labels: auto-docs