azure-sdk-for-cpp/eng/scripts/Get-PkgVersion.ps1
Chidozie Ononiwu 3eab83a635
Add alternate code path for Get-cpp-PackageInfoFromRepo (#1762)
* Add alternate code path for Get-cpp-PackageInfoFromRepo

* Use Join-Path rather than slashes

* Remove quotes from Join-Path arguments
2021-03-03 16:35:24 -08:00

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