Skip to content
Draft
Show file tree
Hide file tree
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
86 changes: 86 additions & 0 deletions .github/workflows/update-mslearn-date.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: 'Update MS Learn documentation dates'

on:
push:
branches:
- dev
- main
paths:
- 'docs-mslearn/**/*.md'
workflow_dispatch: {}

env:
github_user_name: "github-actions"
github_email: "41898282+github-actions[bot]@users.noreply.github.com"
github_commit_message: "Update MS Learn documentation dates"

jobs:
update-mslearn-dates:
name: Update ms.date fields in documentation
if: github.repository == 'microsoft/finops-toolkit' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Configure Local Git
run: |
git config --global user.name $github_user_name
git config --global user.email $github_email

- name: Get changed files
id: changed_files
run: |
# Get the list of changed markdown files in docs-mslearn
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# For manual dispatch, process all files
echo "files=docs-mslearn" >> $GITHUB_OUTPUT
else
# Get files changed in the push
changed_files=$(git diff --name-only ${{ github.event.before }}..${{ github.sha }} -- 'docs-mslearn/**/*.md' || echo "")
if [ -n "$changed_files" ]; then
# Convert to space-separated list
files_list=$(echo "$changed_files" | tr '\n' ' ')
echo "files=$files_list" >> $GITHUB_OUTPUT
else
echo "files=" >> $GITHUB_OUTPUT
fi
fi

- name: Update MS Learn documentation dates
if: steps.changed_files.outputs.files != ''
shell: pwsh
run: |
$VerbosePreference = "Continue"
$changedFiles = "${{ steps.changed_files.outputs.files }}"
if ($changedFiles -eq "docs-mslearn") {
# Process all files in docs-mslearn
./src/scripts/Update-MsLearnDate.ps1
} else {
# Process only the changed files
$files = $changedFiles -split ' ' | Where-Object { $_ -ne '' }
foreach ($file in $files) {
Write-Host "Processing changed file: $file"
./src/scripts/Update-MsLearnDate.ps1 -Path $file
}
}

- name: Check for changes
id: git_status
run: |
mapfile -t CHECK_GIT_STATUS < <(git status -s)
printf "%s\n" "${CHECK_GIT_STATUS[@]}"
echo "changes=${#CHECK_GIT_STATUS[@]}" >> $GITHUB_OUTPUT

- name: Commit and push changes
if: steps.git_status.outputs.changes > 0
run: |
echo "Pushing changes to origin..."
git add .
git commit -m "$github_commit_message [$GITHUB_ACTOR/${GITHUB_SHA::8}]"
git push
2 changes: 2 additions & 0 deletions docs-mslearn/framework/manage/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ Related FinOps capabilities:
- [FinOps education and enablement](./education.md)

<br>

<!-- Test comment to trigger workflow update -->
113 changes: 113 additions & 0 deletions src/scripts/Update-MsLearnDate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

<#
.SYNOPSIS
Updates the ms.date field in Microsoft Learn documentation files.

.DESCRIPTION
The Update-MsLearnDate command updates the ms.date field in markdown files within the docs-mslearn folder.
It searches for lines that match exactly 'ms.date: MM/dd/yyyy' and updates the date to the current date.
Only lines with this exact pattern are updated - no more, no less content on the line.

.PARAMETER Path
Optional. Specifies the path to search for markdown files. Default is 'docs-mslearn' relative to the repository root.

.PARAMETER WhatIf
Optional. Shows what would be updated without making changes.

.EXAMPLE
./Update-MsLearnDate

Updates ms.date fields in all markdown files in the docs-mslearn folder.

.EXAMPLE
./Update-MsLearnDate -Path "docs-mslearn/framework" -WhatIf

Shows what ms.date fields would be updated in the framework subfolder without making changes.
#>
param(
[Parameter()]
[string]
$Path = "docs-mslearn",

[Parameter()]
[switch]
$WhatIf
)

# Get the repository root directory (two levels up from this script)
$repoRoot = "$PSScriptRoot/../.."

# Handle absolute vs relative paths
if ([System.IO.Path]::IsPathRooted($Path)) {
$targetPath = $Path
} else {
$targetPath = "$repoRoot/$Path"
}

if (-not (Test-Path $targetPath)) {
Write-Error "Path not found: $targetPath"
exit 1
}

Write-Host "Searching for markdown files in: $Path"

# Get current date in MM/dd/yyyy format
$currentDate = Get-Date -Format "MM/dd/yyyy"
Write-Host "Current date: $currentDate"

# Pattern to match exactly 'ms.date: MM/dd/yyyy' (no extra content on the line)
$datePattern = "^ms\.date:\s+\d{2}/\d{2}/\d{4}\s*$"
$replacementPattern = "ms.date: $currentDate"

# Find markdown files - handle both files and directories
if (Test-Path $targetPath -PathType Leaf) {
# Single file
if ($targetPath -like "*.md") {
$markdownFiles = @(Get-Item $targetPath)
} else {
Write-Host "Specified file is not a markdown file: $targetPath"
exit 0
}
} else {
# Directory - find all markdown files
$markdownFiles = Get-ChildItem -Path $targetPath -Filter "*.md" -Recurse
}

$updatedFiles = @()
$totalFilesProcessed = 0

foreach ($file in $markdownFiles) {
$totalFilesProcessed++
$relativePath = $file.FullName -replace [regex]::Escape((Resolve-Path $repoRoot).Path + [IO.Path]::DirectorySeparatorChar), ""

$content = Get-Content $file.FullName -Raw

# Replace all lines that match the ms.date pattern (using multiline flag)
$updatedContent = $content -replace "(?m)^ms\.date:\s+\d{2}/\d{2}/\d{4}\s*$", $replacementPattern

if ($content -ne $updatedContent) {
$updatedFiles += $file
Write-Host " Updated ms.date in: $relativePath"

if (-not $WhatIf) {
$updatedContent | Set-Content $file.FullName -Encoding UTF8 -NoNewline
} else {
Write-Host " Would update: $relativePath"
}
}
}

Write-Host ""
Write-Host "Summary:"
Write-Host " Files processed: $totalFilesProcessed"
Write-Host " Files with ms.date updates: $($updatedFiles.Count)"

if ($WhatIf) {
Write-Host " (No changes made - WhatIf mode)"
} elseif ($updatedFiles.Count -gt 0) {
Write-Host " Files updated successfully"
} else {
Write-Host " No files needed updating"
}