generate-crd-docs #37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Generate Kubernetes Reference Docs | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'The Operator release tag for which to generate the docs' | |
| required: true | |
| repository_dispatch: | |
| types: [generate-crd-docs] | |
| jobs: | |
| trigger: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Determine operator tag | |
| id: set_operator_tag | |
| shell: bash | |
| run: | | |
| if [ -n "${{ github.event.inputs.tag }}" ]; then | |
| TAG="${{ github.event.inputs.tag }}" | |
| else | |
| TAG="${{ github.event.release.tag_name }}" | |
| fi | |
| # Check if the tag has the expected prefix. | |
| if [[ "$TAG" =~ ^operator/ ]]; then | |
| echo "OPERATOR_TAG=$TAG" >> $GITHUB_ENV | |
| else | |
| echo "Tag does not have the operator/ prefix. Skipping workflow." | |
| exit 0 | |
| 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 ./helm-charts/charts/redpanda/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-redpanda-helm-spec.adoc | |
| pandoc ./helm-charts/charts/console/README.md -t asciidoc -o ./redpanda-docs/modules/reference/pages/k-console-helm-spec.adoc | |
| pandoc ./helm-charts/charts/operator/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 |