tasks/Update_Changelog_Direct.build.ps1

<#
    .SYNOPSIS
        This is a build task that updates CHANGELOG.md with the released version
        and pushes the change directly to the current branch.

    .PARAMETER ProjectPath
        The root path to the project. Defaults to $BuildRoot.

    .PARAMETER OutputDirectory
        The base directory of all output. Defaults to folder 'output' relative to
        the $BuildRoot.

    .PARAMETER ModuleVersion
        The version of the module being released. Resolved via Set-SamplerTaskVariable.

    .PARAMETER BuildInfo
        The build info object from ModuleBuilder. Defaults to an empty hashtable.

    .NOTES
        This is a build task that is primarily meant to be run by Invoke-Build but
        wrapped by the Sampler project's build.ps1 (https://github.com/gaelcolas/Sampler).
#>

param
(
    [Parameter()]
    [System.String]
    $ProjectPath = (property ProjectPath $BuildRoot),

    [Parameter()]
    [System.String]
    $OutputDirectory = (property OutputDirectory (Join-Path $BuildRoot 'output')),

    [Parameter()]
    [System.String]
    $ModuleVersion = (property ModuleVersion ''),

    [Parameter()]
    [System.Collections.Hashtable]
    $BuildInfo = (property BuildInfo @{ })
)

# Synopsis: Update CHANGELOG.md for the released version and push directly to the current branch.
task Update_Changelog_Direct {
    . Set-SamplerTaskVariable

    Update-ChangelogDirect `
        -ModuleVersion $ModuleVersion `
        -ChangelogPath (Get-SamplerAbsolutePath -Path 'CHANGELOG.md' -RelativeTo $ProjectPath) `
        -GitHubToken ($env:GitHubToken ?? $env:GITHUB_TOKEN ?? '') `
        -GitUserName ($BuildInfo.GitHubConfig.GitHubConfigUserName ?? $env:GIT_USER_NAME ?? '') `
        -GitUserEmail ($BuildInfo.GitHubConfig.GitHubConfigUserEmail ?? $env:GIT_USER_EMAIL ?? '') `
        -UpdateChangelogOnPrerelease ([bool] $BuildInfo.GitHubConfig.UpdateChangelogOnPrerelease)
}