Skip to content

Commit 95ecd4c

Browse files
fix: Update submodule, sort permissions deterministically, and stabilize ms.date (#791)
* fix: update submodule, sort permissions, and stabilize ms.date Three improvements to the weekly docs pipeline: 1. Update msgraph-sdk-powershell submodule to latest main (019fb02 -> 2b68bcb). This picks up MgCommandMetadata.json updates from April-June 2026, including new cmdlets and refreshed metadata. 2. Sort permissions alphabetically in GeneratePermissionsTable.ps1. Previously, permissions appeared in whatever order the metadata JSON listed them, causing non-deterministic diffs when the order changed between runs. Alphabetical sorting ensures stable output. 3. Add StabilizeMsDate.ps1 as a pipeline step that runs after all post-processing scripts. It reverts any file where the only change is the ms.date metadata line, preventing date-only churn from inflating PR diffs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: address review comments on permissions sorting and error handling - Sort permissions by privilege level (IsLeastPrivilege=true first), then alphabetically within each group. This preserves the 'from least to most privileged' table header semantics while ensuring deterministic output. Also deduplicates permission entries. - StabilizeMsDate.ps1: Add error handling for git commands, filter out special diff markers ('\ No newline at end of file'), and verify git checkout success before counting reverted files. - Pipeline step: Add errorActionPreference: 'stop' for consistency. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b8f3f36 commit 95ecd4c

4 files changed

Lines changed: 81 additions & 4 deletions

File tree

‎azure-pipelines/powershell-docs.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ extends:
158158
targetType: 'filePath'
159159
pwsh: true
160160
filePath: scripts/CorrectRelatedLinks-AllFiles.ps1
161+
- task: PowerShell@2
162+
displayName: 'Stabilize ms.date values'
163+
continueOnError: false
164+
inputs:
165+
targetType: 'filePath'
166+
pwsh: true
167+
filePath: scripts/StabilizeMsDate.ps1
168+
errorActionPreference: 'stop'
161169
- task: PowerShell@2
162170
displayName: Pushing to github
163171
env:

‎msgraph-sdk-powershell‎

‎scripts/GeneratePermissionsTable.ps1‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,37 @@ function Start-Generator {
1919
$DelegatedPersonalPermissions = @();
2020
#Get Permissions
2121
$Permissions = $_.Permissions;
22+
# Collect permissions with their privilege level for sorting
23+
$DWPermsWithPrivilege = @();
24+
$AppPermsWithPrivilege = @();
25+
$DPPermsWithPrivilege = @();
2226
$Permissions | ForEach-Object {
2327
$Permission = $_;
2428
$PermissionName = $Permission.Name;
2529
$PermissionType = $Permission.PermissionType;
30+
$IsLeast = $Permission.IsLeastPrivilege -eq $true -or $Permission.IsLeastPrivilege -eq "True";
31+
$entry = [PSCustomObject]@{ Name = $PermissionName; IsLeastPrivilege = $IsLeast }
2632
if ($PermissionType -eq "DelegatedWork") {
27-
$DelegatedWorkPermissions += $PermissionName;
33+
$DWPermsWithPrivilege += $entry;
2834
}
2935
elseif ($PermissionType -eq "Application") {
30-
$ApplicationPermissions += $PermissionName;
36+
$AppPermsWithPrivilege += $entry;
3137
}
3238
elseif ($PermissionType -eq "DelegatedPersonal") {
33-
$DelegatedPersonalPermissions += $PermissionName;
39+
$DPPermsWithPrivilege += $entry;
3440
}
3541
}
42+
# Sort: least privileged first, then alphabetically within each group
43+
# Deduplicate by name to avoid repeated entries
44+
$DelegatedWorkPermissions = $DWPermsWithPrivilege |
45+
Sort-Object @{Expression={-not $_.IsLeastPrivilege}}, @{Expression={$_.Name}} |
46+
Select-Object -ExpandProperty Name -Unique;
47+
$ApplicationPermissions = $AppPermsWithPrivilege |
48+
Sort-Object @{Expression={-not $_.IsLeastPrivilege}}, @{Expression={$_.Name}} |
49+
Select-Object -ExpandProperty Name -Unique;
50+
$DelegatedPersonalPermissions = $DPPermsWithPrivilege |
51+
Sort-Object @{Expression={-not $_.IsLeastPrivilege}}, @{Expression={$_.Name}} |
52+
Select-Object -ExpandProperty Name -Unique;
3653
#If its already in the list, skip it
3754
if ($CmdList -notcontains $CommandName) {
3855
#Check if all types of permissions in the their respective arrays are empty. If empty just skip the command

‎scripts/StabilizeMsDate.ps1‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
#
4+
# Reverts files where the only change compared to HEAD is the ms.date
5+
# metadata line. This prevents date-only churn from inflating PR diffs.
6+
7+
$ErrorActionPreference = 'Stop'
8+
9+
Write-Host -ForegroundColor Green "-------------Stabilizing ms.date values-------------"
10+
11+
$modifiedFiles = git diff --name-only -- '*.md'
12+
if ($LASTEXITCODE -ne 0) {
13+
Write-Error "git diff --name-only failed with exit code $LASTEXITCODE"
14+
}
15+
16+
$revertedCount = 0
17+
18+
foreach ($file in $modifiedFiles) {
19+
if ([string]::IsNullOrWhiteSpace($file)) { continue }
20+
if (-not (Test-Path $file)) { continue }
21+
22+
# Get the raw diff with no context, then extract only +/- content lines
23+
$rawDiff = git diff --unified=0 -- $file
24+
# Filter to content change lines only (skip headers, hunk markers, and
25+
# special markers like "\ No newline at end of file")
26+
$diffLines = $rawDiff | Where-Object {
27+
($_ -match '^\+[^+]' -or $_ -match '^\-[^-]') -and $_ -notmatch '^\\ '
28+
}
29+
30+
# Check if all changed lines are ms.date changes
31+
$allMsDate = $true
32+
$hasChanges = $false
33+
foreach ($line in $diffLines) {
34+
$hasChanges = $true
35+
if ($line -notmatch '^[+-]ms\.date: ') {
36+
$allMsDate = $false
37+
break
38+
}
39+
}
40+
41+
if ($hasChanges -and $allMsDate) {
42+
git checkout -- $file
43+
if ($LASTEXITCODE -ne 0) {
44+
Write-Warning "Failed to revert $file (exit code $LASTEXITCODE)"
45+
} else {
46+
$revertedCount++
47+
}
48+
}
49+
}
50+
51+
Write-Host "Reverted $revertedCount file(s) with date-only changes."
52+
Write-Host -ForegroundColor Green "-------------Done stabilizing ms.date-------------"

0 commit comments

Comments
 (0)