Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions .github/workflows/rerender-rpk-docs-on-overrides-change.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Re-renders the generated rpk reference pages whenever the overrides file
# changes on a docs branch.
#
# The overrides file (docs-data/rpk-overrides.json) is the curated-content
# store for generated rpk pages: descriptions, flag rewrites, added sections,
# exclusions. Without this workflow, an overrides edit merges but the rendered
# pages keep the old content until the next release-driven regeneration, so
# the repo carries overrides that the published docs do not reflect.
#
# This is a pure re-render from the newest committed rpk snapshot: no rpk
# binary, no diff, no What's new update. The run is idempotent, so a re-render
# that changes nothing exits green without opening a PR. The PR only touches
# generated pages, which cannot re-trigger this workflow (it only watches the
# overrides file and its schema).
name: Re-render rpk docs on overrides change

on:
push:
branches: [main, beta]
paths:
- 'docs-data/rpk-overrides.json'
- 'docs-data/rpk-overrides.schema.json'
workflow_dispatch:

permissions:
contents: write
pull-requests: write
id-token: write

# Only the newest overrides state matters: a superseded run for the same
# branch is cancelled rather than queued.
concurrency:
group: rpk-overrides-rerender-${{ github.ref_name }}
cancel-in-progress: true

jobs:
rerender:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout docs repo
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Resolve newest rpk snapshot
id: snapshot
run: |
# Tilde-normalize prerelease suffixes first: plain sort -V ranks
# 26.2.1-rc2 above 26.2.1, which would re-render GA pages from an
# RC snapshot.
SNAPSHOT=$(ls docs-data/rpk-v*.json 2>/dev/null | grep -v 'rpk-diff' | sed 's/-rc/~rc/' | sort -V | sed 's/~rc/-rc/' | tail -1)
if [ -z "$SNAPSHOT" ]; then
echo "::error::No rpk snapshot found in docs-data/"
exit 1
fi
echo "Using snapshot: $SNAPSHOT"
echo "snapshot=$SNAPSHOT" >> "$GITHUB_OUTPUT"

- name: Re-render rpk docs
run: |
npx --yes -p @redpanda-data/docs-extensions-and-macros@^5.3.0 doc-tools generate rpk-docs \
--from-json "${{ steps.snapshot.outputs.snapshot }}" \
--summary-file /tmp/pr-summary.md
Comment on lines +69 to +70

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Pass expression values through environment variables, not shell templates. GitHub expands expressions before Bash parses the script. This lets repository-derived or dispatch-derived values become shell syntax.

  • .github/workflows/rerender-rpk-docs-on-overrides-change.yml#L69-L70: pass steps.snapshot.outputs.snapshot through env and use "$SNAPSHOT".
  • .github/workflows/rerender-rpk-docs-on-overrides-change.yml#L100-L106: use "$GITHUB_REF_NAME" and "$GITHUB_SHA" with printf.
Proposed fix
       - name: Re-render rpk docs
+        env:
+          SNAPSHOT: ${{ steps.snapshot.outputs.snapshot }}
         run: |
           npx --yes -p `@redpanda-data/docs-extensions-and-macros`@^5.3.0 doc-tools generate rpk-docs \
-            --from-json "${{ steps.snapshot.outputs.snapshot }}" \
+            --from-json "$SNAPSHOT" \
             --summary-file /tmp/pr-summary.md
           {
-            echo "Automated re-render of the generated rpk reference pages after an overrides change on \`${{ github.ref_name }}\` (${{ github.sha }})."
+            printf 'Automated re-render of the generated rpk reference pages after an overrides change on `%s` (%s).\n' \
+              "$GITHUB_REF_NAME" "$GITHUB_SHA"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
--from-json "${{ steps.snapshot.outputs.snapshot }}" \
--summary-file /tmp/pr-summary.md
- name: Re-render rpk docs
env:
SNAPSHOT: ${{ steps.snapshot.outputs.snapshot }}
run: |
npx --yes -p `@redpanda-data/docs-extensions-and-macros`@^5.3.0 doc-tools generate rpk-docs \
--from-json "$SNAPSHOT" \
--summary-file /tmp/pr-summary.md
Suggested change
--from-json "${{ steps.snapshot.outputs.snapshot }}" \
--summary-file /tmp/pr-summary.md
{
printf 'Automated re-render of the generated rpk reference pages after an overrides change on `%s` (%s).\n' \
"$GITHUB_REF_NAME" "$GITHUB_SHA"
echo
echo "Review focus: the changed pages should reflect exactly the merged overrides edit, nothing else. The generator version is pinned to the same range the release regeneration uses, so unrelated churn here means the branch missed a regeneration and this PR is catching it up."
echo
cat /tmp/pr-summary.md 2>/dev/null || true
🧰 Tools
🪛 zizmor (1.28.0)

[info] 69-69: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)

📍 Affects 1 file
  • .github/workflows/rerender-rpk-docs-on-overrides-change.yml#L69-L70 (this comment)
  • .github/workflows/rerender-rpk-docs-on-overrides-change.yml#L100-L106
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/rerender-rpk-docs-on-overrides-change.yml around lines 69
- 70, Update .github/workflows/rerender-rpk-docs-on-overrides-change.yml lines
69-70 to pass steps.snapshot.outputs.snapshot through the step environment and
use the quoted SNAPSHOT variable for --from-json. Also update lines 100-106 to
use the quoted GITHUB_REF_NAME and GITHUB_SHA environment variables with printf
instead of embedding GitHub expressions in the shell script.

Source: Linters/SAST tools


- name: Detect changes
id: changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
git status --short | head -20
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
echo "Overrides change did not alter any rendered page. Nothing to do."
fi

- name: Configure AWS credentials
if: steps.changes.outputs.has_changes == 'true'
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 }}

- name: Fetch actions bot token
if: steps.changes.outputs.has_changes == 'true'
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
,sdlc/prod/github/actions_bot_token
parse-json-secrets: true

- name: Build PR body
if: steps.changes.outputs.has_changes == 'true'
run: |
{
echo "Automated re-render of the generated rpk reference pages after an overrides change on \`${{ github.ref_name }}\` (${{ github.sha }})."
echo
echo "Review focus: the changed pages should reflect exactly the merged overrides edit, nothing else. The generator version is pinned to the same range the release regeneration uses, so unrelated churn here means the branch missed a regeneration and this PR is catching it up."
echo
cat /tmp/pr-summary.md 2>/dev/null || true
} > /tmp/pr-body.md

- name: Create Pull Request
if: steps.changes.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ env.ACTIONS_BOT_TOKEN }}
branch: rpk-docs/overrides-rerender-${{ github.ref_name }}
base: ${{ github.ref_name }}
title: 'docs: re-render rpk docs for overrides change (${{ github.ref_name }})'
body-path: /tmp/pr-body.md
commit-message: 'docs: re-render rpk docs for overrides change'
labels: |
documentation
automated
rpk
delete-branch: true
Loading