|
| 1 | +function ValidateMetadata( |
| 2 | + [Parameter(Mandatory=$true)] [string] $ProductVersion, |
| 3 | + [switch] $Release |
| 4 | +) { |
| 5 | + $lastReleasedVersion = XmlPeek src\AmbientTasks\AmbientTasks.csproj '/Project/PropertyGroup/Version/text()' |
| 6 | + |
| 7 | + if ($Release) { |
| 8 | + $productVersionWithoutBuildMetadata = $ProductVersion.Substring(0, $ProductVersion.IndexOf('+')) |
| 9 | + if ($lastReleasedVersion -ne $productVersionWithoutBuildMetadata) { |
| 10 | + throw 'The version must be updated in the .csproj to do a release build.' |
| 11 | + } |
| 12 | + } |
| 13 | + |
| 14 | + $changelogHeaderLines = Select-String -Path CHANGELOG.md -Pattern ('## [' + $lastReleasedVersion + ']') -SimpleMatch |
| 15 | + if ($changelogHeaderLines.Count -ne 1) { |
| 16 | + throw "There must be exactly one entry in CHANGELOG.md for version $lastReleasedVersion." |
| 17 | + } |
| 18 | + |
| 19 | + $urlAnchor = $changelogHeaderLines[0].Line.Substring('## '.Length).Replace(' ', '-') -replace '[^-\w]', '' |
| 20 | + $requiredReleaseNotesLink = "https://github.com/Techsola/AmbientTasks/blob/v$lastReleasedVersion/CHANGELOG.md#$urlAnchor" |
| 21 | + $packageReleaseNotes = XmlPeek src\AmbientTasks\AmbientTasks.csproj '/Project/PropertyGroup/PackageReleaseNotes/text()' |
| 22 | + |
| 23 | + if (-not $packageReleaseNotes.Contains($requiredReleaseNotesLink)) { |
| 24 | + throw 'Package release notes in .csproj must contain this URL: ' + $requiredReleaseNotesLink |
| 25 | + } |
| 26 | + |
| 27 | + if ($packageReleaseNotes.Length -ne $packageReleaseNotes.Trim().Length) { |
| 28 | + throw 'Package release notes must not begin or end with whitespace.' |
| 29 | + } |
| 30 | + |
| 31 | + foreach ($line in $packageReleaseNotes.Split(@("`r`n", "`r", "`n"), [StringSplitOptions]::None)) { |
| 32 | + if ([string]::IsNullOrWhiteSpace($line)) { |
| 33 | + if ($line.Length -ne 0) { |
| 34 | + throw 'Package release notes must not have whitespace-only lines.' |
| 35 | + } |
| 36 | + } elseif ($line.Length -ne $line.TrimEnd().Length -and $line.Length -ne $line.TrimEnd().Length + 2) { |
| 37 | + throw 'Package release notes must not have trailing whitespace.' |
| 38 | + } elseif ($line.Length -ne $line.TrimStart().Length) { |
| 39 | + throw 'Package release notes must not be indented.' |
| 40 | + } |
| 41 | + } |
| 42 | +} |
0 commit comments