-
Notifications
You must be signed in to change notification settings - Fork 153
[DevOps] Add GitHub action to update MS Learn doc update date #1666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Co-authored-by: flanakin <399533+flanakin@users.noreply.github.com>
Co-authored-by: flanakin <399533+flanakin@users.noreply.github.com>
shell: pwsh | ||
run: | | ||
$VerbosePreference = "Continue" | ||
./src/scripts/Update-MsLearnDate.ps1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this updating the date on all files? We only want to update the date on files that are touched in the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the workflow to only process files that are changed in the PR. The workflow now detects changed markdown files in docs-mslearn and passes them individually to the script. For manual workflow_dispatch, it still processes all files. Commit: 2226576
src/scripts/Update-MsLearnDate.ps1
Outdated
) | ||
|
||
# Get the repository root directory (two levels up from this script) | ||
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "../..") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "../..") | |
$repoRoot = "$PSScriptRoot/../.." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the path handling as suggested.
src/scripts/Update-MsLearnDate.ps1
Outdated
if ([System.IO.Path]::IsPathRooted($Path)) { | ||
$targetPath = $Path | ||
} else { | ||
$targetPath = Join-Path $repoRoot $Path | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify
if ([System.IO.Path]::IsPathRooted($Path)) { | |
$targetPath = $Path | |
} else { | |
$targetPath = Join-Path $repoRoot $Path | |
} | |
$targetPath = "$repoRoot/$Path" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the target path construction as suggested.
src/scripts/Update-MsLearnDate.ps1
Outdated
exit 1 | ||
} | ||
|
||
Write-Host "Searching for markdown files in: $targetPath" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write-Host "Searching for markdown files in: $targetPath" | |
Write-Host "Searching for markdown files in: $Path" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the log message to use $Path parameter as suggested.
src/scripts/Update-MsLearnDate.ps1
Outdated
$updatedLines = @() | ||
$fileChanged = $false | ||
|
||
for ($i = 0; $i -lt $lines.Count; $i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of looping thru every line, can we just replace all lines that match the ms.date pattern on the full line? Wouldn't that be simpler code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the code by replacing the line-by-line loop with a regex replace operation on the full file content as suggested.
src/scripts/Update-MsLearnDate.ps1
Outdated
if (-not $WhatIf) { | ||
$updatedLines += $newLine | ||
} else { | ||
$updatedLines += $oldLine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should -WhatIf log to the host?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, -WhatIf does log to the host - it shows "Would update: [filename]" messages and the summary indicates "(No changes made - WhatIf mode)" to clearly show the simulation results.
Co-authored-by: flanakin <399533+flanakin@users.noreply.github.com>
Co-authored-by: flanakin <399533+flanakin@users.noreply.github.com>
@copilot-swe-agent Please try again |
Co-authored-by: flanakin <399533+flanakin@users.noreply.github.com>
Fixed the YAML formatting issues in the GitHub Action workflow that were causing validation errors. The main problems were trailing spaces, incorrect indentation in the permissions section, and missing newline at end of file. The workflow and PowerShell script are now working correctly. Commit: 69c9a40 |
This PR implements a GitHub Action workflow and PowerShell script that automatically updates the
ms.date
field in Microsoft Learn documentation files when they are modified.Changes Made
PowerShell Script (
src/scripts/Update-MsLearnDate.ps1
)docs-mslearn
folderms.date: MM/dd/yyyy
format-WhatIf
parameter for testing without making changesGitHub Action Workflow (
.github/workflows/update-mslearn-date.yml
)dev
andmain
branches when*.md
files indocs-mslearn
folder are modifiedKey Features
ms.date: MM/dd/yyyy
(no extra content on the line)Testing
The implementation has been thoroughly tested:
Example of what gets updated:
Lines that are NOT updated:
ms.date: 04/02/2025 # comment
(has extra content)# ms.date: 04/02/2025
(commented out)ms.date:04/02/2025
(missing space)ms.date: 4/2/2025
(single digit format)This ensures MS Learn documentation stays current and avoids flagging for stale content.
Fixes #1665.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.