Skip to content

fix: Content-based doc regeneration to eliminate empty PRs#790

Merged
ramsessanchez merged 2 commits into
mainfrom
fix/content-based-doc-regeneration
Jun 30, 2026
Merged

fix: Content-based doc regeneration to eliminate empty PRs#790
ramsessanchez merged 2 commits into
mainfrom
fix/content-based-doc-regeneration

Conversation

@ramsessanchez

Copy link
Copy Markdown
Contributor

Problem

The weekly \powershell-docs.yml\ pipeline creates PRs with ~25,000+ changed files every run because \GenerateMarkDown.ps1\ deletes ALL existing docs and regenerates them from scratch. This produces diffs too large for GitHub to render (GitHub reports 0 changed files), making every weekly PR appear empty and unreviable.

Root Causes

  • Bulk delete-and-regenerate: Every file gets deleted and recreated, even when content hasn't changed
  • Random TOC GUIDs: Each run generates new random GUIDs for module TOC files
  • \ms.date\ timestamp churn: PlatyPS sets the current date on every generated file

Solution

Replace the delete-all approach with content-based comparison:

  1. Generate to temp directory first — each command's docs are generated to a temp folder
  2. Compare with existing docs — content is compared after stripping \ms.date\ metadata lines so date-only changes are ignored
  3. Only overwrite on real changes — files are only updated when actual content (parameters, descriptions, examples) has changed
  4. Deterministic TOC GUIDs — module GUIDs are now derived from a SHA-256 hash of the module name, eliminating random GUID churn
  5. Orphan cleanup — docs for commands removed from metadata are automatically cleaned up
  6. TOC comparison — TOC files are built in memory and only written when the command list changes

Impact

  • Weekly PRs will only contain files with meaningful content changes (new cmdlets, updated help, permission changes)
  • PR sizes should drop from ~25K files to a manageable number
  • PRs will be renderable and reviewable in GitHub's UI
  • No behavior change for the actual documentation content

Replace the delete-all-and-regenerate approach with content-based
comparison. For each command, docs are generated to a temp directory
and compared with existing files (ignoring ms.date metadata). Files
are only overwritten when real content changes are detected.

Additional improvements:
- Use deterministic GUIDs for TOC files (based on module name hash)
  instead of random GUIDs that change every run
- Add orphan cleanup for docs whose commands are no longer in metadata
- Build TOC content in memory and only write when changed
- Auth module docs use the same comparison-based approach

This reduces weekly PR diffs from ~25K files (every file touched) to
only files with actual content updates, making PRs reviewable and
staying within GitHub's diff rendering limits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@learn-build-service-prod

Copy link
Copy Markdown
Contributor

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit 7072409:

✅ Validation status: passed

File Status Preview URL Details
scripts/GenerateMarkDown.ps1 ✅Succeeded

For more details, please refer to the build report.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the PowerShell reference-doc generation script to avoid “delete-and-regenerate everything” behavior, aiming to drastically reduce weekly automated PR sizes by only rewriting markdown files when meaningful content changes occur.

Changes:

  • Generates cmdlet docs into temporary directories and only overwrites existing markdown when normalized content differs (ignoring ms.date).
  • Makes module TOC GUIDs deterministic (hash-derived) and only writes TOC files when their content changes.
  • Removes “orphaned” cmdlet markdown files no longer present in metadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/GenerateMarkDown.ps1 Outdated
Comment on lines +93 to +114
# Generate auth docs to temp directory, then compare
Set-Help -ModuleDocsPath $TempAuthDir -Command "Connect-MgGraph" -Module "Microsoft.Graph.Authentication"
$tempAuthFile = Join-Path $TempAuthDir $AuthPath "Connect-MgGraph.md"
$existingAuthFile = Join-Path $AuthDestination "Connect-MgGraph.md"
if ((Test-Path $tempAuthFile)) {
if (Test-Path $existingAuthFile) {
$existingContent = Get-NormalizedContent -FilePath $existingAuthFile
$newContent = Get-NormalizedContent -FilePath $tempAuthFile
if ($existingContent -ne $newContent) {
Copy-Item -Path $tempAuthFile -Destination $existingAuthFile -Force
Write-Host "Updated auth doc: Connect-MgGraph"
} else {
Write-Host "No content changes for auth doc: Connect-MgGraph"
}
} else {
if (-not (Test-Path $AuthDestination)) {
New-Item -Path $AuthDestination -ItemType Directory -Force | Out-Null
}
Copy-Item -Path $tempAuthFile -Destination $existingAuthFile -Force
Write-Host "Added auth doc: Connect-MgGraph"
}
}
Comment thread scripts/GenerateMarkDown.ps1
Comment thread scripts/GenerateMarkDown.ps1
Comment thread scripts/GenerateMarkDown.ps1 Outdated
msewaweru
msewaweru previously approved these changes Jun 18, 2026
1. Auth module: generate and compare ALL auth cmdlet docs (not just
   Connect-MgGraph). Iterates all generated files in the temp auth
   module folder so other auth cmdlets stay current.

2. Get-NormalizedContent: normalize CRLF to LF and trim trailing
   whitespace before comparison, preventing false positives from
   line-ending differences between checkout and generated content.

3. Get-DeterministicGuid: explicitly cast hash slice to [byte[]] for
   unambiguous GUID constructor binding, and dispose SHA256 instance
   via try/finally to avoid resource leaks.

4. TOC comparison: normalize both existing and new TOC text to LF
   before comparing, preventing spurious rewrites from CRLF/LF
   mismatches on Windows checkouts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@learn-build-service-prod

Copy link
Copy Markdown
Contributor

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit 0a0b22d:

✅ Validation status: passed

File Status Preview URL Details
scripts/GenerateMarkDown.ps1 ✅Succeeded

For more details, please refer to the build report.

@ramsessanchez
ramsessanchez enabled auto-merge (squash) June 29, 2026 19:07
@ramsessanchez
ramsessanchez requested a review from msewaweru June 29, 2026 19:07
@ramsessanchez
ramsessanchez merged commit b8f3f36 into main Jun 30, 2026
7 checks passed
@ramsessanchez
ramsessanchez deleted the fix/content-based-doc-regeneration branch June 30, 2026 06:00
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.

3 participants