Skip to content

ci: add workflow to check generated docs are in sync on PRs#2069

Open
armorbreak001 wants to merge 2 commits intoasyncapi:masterfrom
armorbreak001:fix/ci-check-generated-docs
Open

ci: add workflow to check generated docs are in sync on PRs#2069
armorbreak001 wants to merge 2 commits intoasyncapi:masterfrom
armorbreak001:fix/ci-check-generated-docs

Conversation

@armorbreak001
Copy link
Copy Markdown

@armorbreak001 armorbreak001 commented Apr 22, 2026

Summary

Fixes #2038

Problem

Contributors can update JSDoc comments and forget to run npm run generate:assets, causing generated docs (api_components.md, api.md, README TOC, etc.) to silently go out of sync with no CI check to catch them.

We already had this problem with #1922 where docs changes were unexpectedly auto-merged.

Solution

Add a PR workflow () that:

  1. Triggers on all PRs against master (opened, reopened, synchronize)
  2. Installs dependencies via npm ci
  3. Regenerates all documentation assets via npm run generate:assets (runs turbo run generate:assets across all packages + README TOC update)
  4. Checks if any generated .md files have diffs
  5. Fails with a clear error message pointing contributors to run npm run generate:assets locally

Design decisions

  • Skips bot PRs: Docs update PRs, release PRs, CI sync PRs, and allcontributors bot PRs are excluded (they are expected to change generated files)
  • Skips draft PRs: No need to check until the PR is ready for review
  • Uses existing patterns: Follows the same node version detection, setup, and bot-exclusion logic as pr-testing-with-test-project.yml
  • Checks all *.md diffs: Catches not just api_components.md but any generated documentation that may be added in the future

Notes

  • This makes the existing update-docs-on-docs-commits.yml workflow partially redundant for catching stale docs on PRs (that workflow still serves the purpose of auto-creating docs update PRs on docs: commits to master)

Summary by CodeRabbit

  • Chores
    • Added an automated check on pull requests that validates generated documentation is up to date. It runs for active PRs (skipping drafts and known bot PRs) and will flag/fail the PR if documentation artifacts diverge, prompting authors to regenerate docs before merge.

Fixes asyncapi#2038 - Adds a PR workflow that regenerates documentation assets
(npm run generate:assets) and fails if generated MD files are out of sync
with source code, prompting contributors to run the generate command locally.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 22, 2026

⚠️ No Changeset found

Latest commit: ded1173

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@asyncapi-bot
Copy link
Copy Markdown
Contributor

What reviewer looks at during PR review

The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.

  1. PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means spoken or written as if giving a command or instruction, like "add new helper for listing operations")

    Note - In Generator, prepend feat: or fix: in PR title only when PATCH/MINOR release must be triggered.

  2. PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.

    Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes Resolves #<issue-number> or Fixes #<issue-number> this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow.

  3. Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.

  4. Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.

  5. DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.

  6. Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.

  7. Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.

  8. Template Design Principles Alignment: While reviewing template-related changes in the packages/ directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project.

  9. Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.

  10. Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 14963ffd-0114-4c28-b36c-2b36d904fed6

📥 Commits

Reviewing files that changed from the base of the PR and between 0bd46c4 and ded1173.

📒 Files selected for processing (1)
  • .github/workflows/check-generated-docs-sync.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/check-generated-docs-sync.yml

📝 Walkthrough

Walkthrough

Adds a GitHub Actions workflow that regenerates documentation assets on PRs to master and verifies Markdown files are unchanged by running a git diff, skipping execution for draft PRs and certain bot actors. Fails the check if generated docs are out of sync.

Changes

Cohort / File(s) Summary
Documentation Sync Check Workflow
.github/workflows/check-generated-docs-sync.yml
New workflow triggered on PRs to master that checks out the repo, derives NODE_VERSION from package-lock.json, sets up Node, runs npm ci and npm run generate:assets, and validates generated *.md files using git diff --exit-code. Includes conditional skips for draft PRs and known bot actors and prints changed Markdown files when failing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title follows Conventional Commits format with 'ci:' prefix, uses imperative mood ('add workflow'), and clearly summarizes the main change (adding a docs sync check workflow).
Linked Issues check ✅ Passed The implementation fully addresses issue #2038 by adding a PR workflow that regenerates docs, checks for diffs in *.md files, and fails with a clear error message instructing contributors to run generate:assets locally.
Out of Scope Changes check ✅ Passed The PR contains only the new workflow file addition directly scoped to issue #2038 with no unrelated changes; bot-exclusion and node-version logic reuse align with the stated design details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/check-generated-docs-sync.yml (1)

15-29: Avoid job-level if conditionals in workflows that could become required checks.

The check-docs job uses a job-level if condition to skip bot-generated and draft PRs. If this check is added to branch protection rules, skipped PRs won't appear in the GitHub checks list at all, causing the required check to never complete—effectively blocking all matched PRs from merging. Move the skip logic to step-level conditionals instead: the job completes successfully regardless of context, but expensive steps (checkout, install, generate, diff) only run when needed.

A cleaner structure sets the skip condition as a job env variable and guards steps with it:

Refactor pattern
  check-docs:
    name: 'Check generated docs sync'
    runs-on: ubuntu-latest
-   if: >
-     !github.event.pull_request.draft && !(
+   env:
+     SKIP_CHECK: >-
+       ${{ github.event.pull_request.draft || (
          (github.actor == 'asyncapi-bot' && (
            startsWith(github.event.pull_request.title, 'ci: update of files from global .github repo') ||
            startsWith(github.event.pull_request.title, 'chore(release):') ||
            github.event.pull_request.title == 'chore: update generated docs'
          )) ||
          (github.actor == 'asyncapi-bot-eve' && (
            startsWith(github.event.pull_request.title, 'ci: update of files from global .github repo') ||
            startsWith(github.event.pull_request.title, 'chore(release):')
          )) ||
          (github.actor == 'allcontributors[bot]' &&
            startsWith(github.event.pull_request.title, 'docs: add')
          )
-       )
+       ) }}
    steps:
+     - if: env.SKIP_CHECK != 'true'
+       uses: actions/checkout@v4
-     - uses: actions/checkout@v4

Apply if: env.SKIP_CHECK != 'true' to the remaining expensive steps.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/check-generated-docs-sync.yml around lines 15 - 29, The
job-level conditional on the check-docs job should be removed and replaced by a
job that always runs but sets an env flag (e.g., SKIP_CHECK) based on the
current condition (the draft/bot title/actor checks shown in the if block); then
apply step-level guards (e.g., if: env.SKIP_CHECK != 'true') to the expensive
steps such as the checkout step, install/build/generate steps, and the
diff/compare step so the job completes successfully even when skipped; update
the job named check-docs and the expensive step entries to reference the
SKIP_CHECK env var and ensure any final reporting step runs unconditionally so
the job never disappears from GitHub checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/check-generated-docs-sync.yml:
- Line 7: The workflow's pull_request trigger only lists types [opened,
reopened, synchronize], so the job that is skipped for draft PRs (job
conditioned on draft status) won't run when a draft is marked ready; update the
trigger types array to include "ready_for_review" so the workflow runs when a PR
transitions from draft to ready_for_review; locate the pull_request 'types'
array in the workflow and add "ready_for_review" alongside the existing entries
to ensure the docs sync check executes at that transition.

---

Nitpick comments:
In @.github/workflows/check-generated-docs-sync.yml:
- Around line 15-29: The job-level conditional on the check-docs job should be
removed and replaced by a job that always runs but sets an env flag (e.g.,
SKIP_CHECK) based on the current condition (the draft/bot title/actor checks
shown in the if block); then apply step-level guards (e.g., if: env.SKIP_CHECK
!= 'true') to the expensive steps such as the checkout step,
install/build/generate steps, and the diff/compare step so the job completes
successfully even when skipped; update the job named check-docs and the
expensive step entries to reference the SKIP_CHECK env var and ensure any final
reporting step runs unconditionally so the job never disappears from GitHub
checks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 688d2cdd-2558-41b0-9f8e-a5e3e1d0f661

📥 Commits

Reviewing files that changed from the base of the PR and between 5c4b597 and 0bd46c4.

📒 Files selected for processing (1)
  • .github/workflows/check-generated-docs-sync.yml


on:
pull_request:
types: [opened, reopened, synchronize]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

GitHub Actions pull_request ready_for_review activity type

💡 Result:

In GitHub Actions, the pull_request event supports multiple activity types (also called "types"), including ready_for_review. This type triggers a workflow when a draft pull request is marked as ready for review. To use it in a workflow YAML file: on: pull_request: types: [ready_for_review] By default, pull_request workflows trigger on opened, synchronize, and reopened. To include ready_for_review along with defaults for non-draft PRs and updates, combine them: on: pull_request: types: [opened, synchronize, reopened, ready_for_review] jobs: example: if: github.event.pull_request.draft == false runs-on: ubuntu-latest steps: - run: echo "Ready for review!" This is confirmed in official GitHub documentation on events that trigger workflows, which references webhook payloads, and multiple community examples. The ready_for_review corresponds to the pull_request webhook action when a draft PR is marked ready.

Citations:


🏁 Script executed:

cat -n .github/workflows/check-generated-docs-sync.yml

Repository: asyncapi/generator

Length of output: 2899


Add ready_for_review to trigger the check when draft PRs become ready.

Draft PRs skip this check due to the job-level condition on line 16. When marked ready for review, the ready_for_review event fires, but since it's not in the trigger types (line 7), the workflow won't run until another synchronize or reopened event occurs. Add ready_for_review to ensure the docs sync check runs at the point the PR becomes mergeable.

Proposed fix
-    types: [opened, reopened, synchronize]
+    types: [opened, reopened, synchronize, ready_for_review]
📝 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
types: [opened, reopened, synchronize]
types: [opened, reopened, synchronize, ready_for_review]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/check-generated-docs-sync.yml at line 7, The workflow's
pull_request trigger only lists types [opened, reopened, synchronize], so the
job that is skipped for draft PRs (job conditioned on draft status) won't run
when a draft is marked ready; update the trigger types array to include
"ready_for_review" so the workflow runs when a PR transitions from draft to
ready_for_review; locate the pull_request 'types' array in the workflow and add
"ready_for_review" alongside the existing entries to ensure the docs sync check
executes at that transition.

- Add permissions: contents: read (least privilege)
- Add persist-credentials: false to checkout step

Addresses SonarCloud security hotspot on workflow file.
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CI check to verify generated docs are up to date on PRs

2 participants