build/build.ps1

Start-Transcript -Path "Transcript.log" -Verbose
$moduleFolderPath = (Get-Item $PSScriptRoot).Parent.FullName
Write-Host "PSScriptRoot: $moduleFolderPath"
$modulePath = "$moduleFolderPath"
Push-Location $moduleFolderPath
git add .
git commit -m 'updates'
git push
git push upstream
Pop-Location

function Update-RqtVersion{
    $manifestPath = "$modulePath/RallyQuickToolsCli.psd1"
    Write-Host "Manifext Path: $manifestPath"
    $content = Get-Content $manifestPath -Raw
    $version = (
        $content `
        | Select-String "(?<=ModuleVersion = ').*(?=')"
    ).Matches.Value.Split(".")
    $newVersion = $version
    $newVersion[2] = [int]$version[2] + 1
    $newVersion = $newVersion -join "."
    $newContent = $content `
        -Replace "(?<=ModuleVersion = ').*(?=')", $newVersion
    Set-Content -Path $manifestPath -Value $newContent

    # UPDATE Package.nuspec version number
    $nuspec = [Xml](Get-Content -Raw "$moduleFolderPath/src/RallyQuickToolsCli.nuspec")
    $nuspec.package.metadata.version = "$newVersion"
    $nuspec.Save("$moduleFolderPath/src/RallyQuickToolsCli.nuspec")
}
Update-RqtVersion

# nuget pack -OutputDirectory nupkg/

Push-Location $moduleFolderPath/src/
nuget pack -OutputDirectory ../nupkg/
Pop-Location

Publish-Module -Path "$modulePath" -Repository TestNugetFeed -Verbose -NuGetApiKey "any_random_text"


$nugetKey = Get-Secret -Name ps_key -AsPlainText
Publish-Module -Path "$modulePath" -Verbose -NuGetApiKey "$nugetKey"

$nugetKey = Get-Secret -Name vnuget_token -Vault "Vertafore" -AsPlainText
Publish-Module -Path "$modulePath" -Verbose -NuGetApiKey "$nugetKey" -Repository "$vnuget_sre_name" 

# [Register-PSRepository (PowerShellGet) - PowerShell](https://docs.microsoft.com/en-us/powershell/module/powershellget/register-psrepository?view=powershell-7.2)

# Get-PSRepository
# Update-Module RallyQuickToolsCli
Stop-Transcript