|
| 1 | +# Copyright (c) Mixed Reality Toolkit Contributors |
| 2 | +# Licensed under the BSD 3-Clause |
| 3 | + |
| 4 | +<# |
| 5 | +.SYNOPSIS |
| 6 | + Validates that changelogs have been properly updated for changed files. |
| 7 | +.DESCRIPTION |
| 8 | + Validates that changelogs have been properly updated for changed files. |
| 9 | +.EXAMPLE |
| 10 | + .\check-changelogs.ps1 -ChangesFile c:\path\to\changes\file.txt |
| 11 | +#> |
| 12 | +param( |
| 13 | + # The filename containing the list of files to scope the code validation |
| 14 | + # to. This is useful in pull request validation when there isn't a need |
| 15 | + # to check every single file in the repo for changes (i.e. only the list |
| 16 | + # of changed files) |
| 17 | + [Parameter(Mandatory = $true)] |
| 18 | + [string]$ChangesFile |
| 19 | +) |
| 20 | + |
| 21 | +$changelogUpdated = @{ } |
| 22 | + |
| 23 | +# If the file containing the list of changes was provided and actually exists, |
| 24 | +# this validation should scope to only those changed files. |
| 25 | +if ($ChangesFile -and (Test-Path $ChangesFile -PathType leaf)) { |
| 26 | + Get-Content $ChangesFile | ForEach-Object { |
| 27 | + Write-Host "Checking file: $_" |
| 28 | + $packageName = $_ | Select-String -Pattern "org\.mixedrealitytoolkit\.\w+(\.\w+)*" | Select-Object -First 1 |
| 29 | + |
| 30 | + if (-not $packageName) { |
| 31 | + return # this is not an MRTK package, so skip |
| 32 | + } |
| 33 | + |
| 34 | + $packageName = $packageName.Matches[0].Value |
| 35 | + |
| 36 | + $isChangelog = $_ -match "CHANGELOG.md" |
| 37 | + if ($changelogUpdated.ContainsKey($packageName)) { |
| 38 | + if ($isChangelog) { |
| 39 | + $changelogUpdated[$packageName] = $true |
| 40 | + } |
| 41 | + } |
| 42 | + else { |
| 43 | + $changelogUpdated[$packageName] = $isChangelog |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +$containsIssue = $false |
| 49 | +$changelogUpdated.GetEnumerator() | ForEach-Object { |
| 50 | + if (-not $_.Value) { |
| 51 | + Write-Warning "Package '$($_.Key)' has changes, but its CHANGELOG.md was not updated. This is not always an issue but usually is" |
| 52 | + $containsIssue = $true |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +if ($containsIssue) { |
| 57 | + Write-Output "Potential issues found, please see above for details" |
| 58 | + exit 1; |
| 59 | +} |
| 60 | +else { |
| 61 | + Write-Output "No issues found" |
| 62 | + exit 0; |
| 63 | +} |
0 commit comments