* Add alternate code path for Get-cpp-PackageInfoFromRepo * Use Join-Path rather than slashes * Remove quotes from Join-Path arguments
49 lines
1.3 KiB
PowerShell
49 lines
1.3 KiB
PowerShell
[CmdletBinding()]
|
|
param (
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
[string] $ServiceDirectory,
|
|
[Parameter(Mandatory = $true)]
|
|
[string] $PackageName
|
|
)
|
|
|
|
$repoRoot = Resolve-Path "$PSScriptRoot/../..";
|
|
. (Join-Path ${repoRoot} eng common scripts logging.ps1)
|
|
. (Join-Path ${repoRoot} eng scripts SdkVersion-Common.ps1)
|
|
|
|
$versionFileLocation = Get-VersionHppLocaiton `
|
|
-ServiceDirectory $ServiceDirectory `
|
|
-PackageName $PackageName
|
|
|
|
if (!$versionFileLocation) {
|
|
$fallbackpath = Join-Path $RepoRoot sdk $ServiceDirectory $PackageName version.txt
|
|
if (!(Test-Path $fallbackpath))
|
|
{
|
|
LogWarning "Failed to retrieve package version. No version file found."
|
|
return $null
|
|
}
|
|
|
|
$fallback = Get-Content $fallbackpath
|
|
if ($fallback) {
|
|
return $fallback
|
|
} else {
|
|
LogWarning "Cannot locate package version"
|
|
return $null
|
|
}
|
|
}
|
|
|
|
$versionFileContents = Get-Content $versionFileLocation -Raw
|
|
|
|
if (!($versionFileContents -match $VersionRegex)) {
|
|
LogWarning "does not match version information schema"
|
|
return $null
|
|
}
|
|
|
|
$VersionString = if ($Matches.prerelease) {
|
|
"$($Matches.major).$($Matches.minor).$($Matches.patch)-$($Matches.prerelease)"
|
|
} else {
|
|
"$($Matches.major).$($Matches.minor).$($Matches.patch)"
|
|
}
|
|
|
|
return $VersionString
|