Functions/Helper/Get-IBHModuleReleaseNote.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<#
    .SYNOPSIS
        Extract all lines for the current version.
 
    .DESCRIPTION
        Prepare a release notes statement with all entries in dhe CHANGELOG.md
        file.
 
    .OUTPUTS
        System.String. Multi-line text release notes.
 
    .EXAMPLE
        PS C:\> Get-IBHModuleReleaseNote -BuildRoot 'C:\GitHub\InvokeBuildHelper' -ModuleVersion '1.0.0'
        Find the release notes for the version 1.0.0.
 
    .LINK
        https://github.com/claudiospizzi/PSInvokeBuildHelper
#>

function Get-IBHModuleReleaseNote
{
    [CmdletBinding()]
    [OutputType([System.String])]
    param
    (
        # Root path of the project.
        [Parameter(Mandatory = $true)]
        [System.String]
        $BuildRoot,

        # The version to check.
        [Parameter(Mandatory = $true)]
        [System.String]
        $ModuleVersion
    )

    $path    = Join-Path -Path $BuildRoot -ChildPath 'CHANGELOG.md'
    $content = Get-Content -Path $path

    $releaseNotes = [System.String[]] 'Release Notes:'

    $isCurrentVersion = $false
    foreach ($line in $content)
    {
        if ($line -like '## *')
        {
            $isCurrentVersion = $line -like "## $ModuleVersion - ????-??-??"
        }
        elseif ($isCurrentVersion)
        {
            if (-not [System.String]::IsNullOrWhiteSpace($line))
            {
                $releaseNotes += $line
            }
        }
    }

    if ($releaseNotes.Count -eq 1)
    {
        throw "Release notes not found in CHANGELOG.md for version $ModuleVersion"
    }

    Write-Output $releaseNotes
}