Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 1251 #16290

Merged
merged 10 commits into from
Jan 22, 2021
7 changes: 0 additions & 7 deletions eng/common/docgeneration/Generate-DocIndex.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ Param (
)
. "${PSScriptRoot}\..\scripts\common.ps1"

# Given the metadata url under https://github.com/Azure/azure-sdk/tree/master/_data/releases/latest,
# the function will return the csv metadata back as part of response.
function Get-CSVMetadata ([string]$MetadataUri) {
$metadataResponse = Invoke-RestMethod -Uri $MetadataUri -method "GET" -MaximumRetryCount 3 -RetryIntervalSec 10 | ConvertFrom-Csv
return $metadataResponse
}

# Given the github io blob storage url and language regex,
# the helper function will return a list of artifact names.
function Get-BlobStorage-Artifacts($blobStorageUrl, $blobDirectoryRegex, $blobArtifactsReplacement) {
Expand Down
31 changes: 26 additions & 5 deletions eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function Get-PkgProperties
if (!(Test-Path $serviceDirectoryPath))
{
LogError "Service Directory $ServiceDirectory does not exist"
exit 1
return $null
}

$directoriesPresent = Get-ChildItem $serviceDirectoryPath -Directory
Expand All @@ -109,7 +109,8 @@ function Get-PkgProperties
return $pkgProps
}
}
LogError "Failed to retrive Properties for $PackageName"
LogWarning "Failed to retrive Properties for $PackageName"
return $null
}

# Takes ServiceName and Repo Root Directory
Expand Down Expand Up @@ -152,21 +153,41 @@ function Get-AllPkgProperties ([string]$ServiceDirectory = $null)
return $pkgPropsResult
}

# Given the metadata url under https://github.com/Azure/azure-sdk/tree/master/_data/releases/latest,
# the function will return the csv metadata back as part of response.
function Get-CSVMetadata ([string]$MetadataUri=$MetadataUri)
{
$metadataResponse = Invoke-RestMethod -Uri $MetadataUri -method "GET" -MaximumRetryCount 3 -RetryIntervalSec 10 | ConvertFrom-Csv
return $metadataResponse
}

function Operate-OnPackages ($activePkgList, $ServiceDirectory, [Array]$pkgPropsResult)
{
foreach ($pkg in $activePkgList)
{
LogDebug "Operating on $($pkg["name"])"
$pkgProps = Get-PkgProperties -PackageName $pkg["name"] -ServiceDirectory $ServiceDirectory
$pkgPropsResult += $pkgProps
if ($null -ne $pkgProps)
{
$pkgPropsResult += $pkgProps
}
}
return $pkgPropsResult
}

function Get-PkgListFromYml ($ciYmlPath)
{
$ProgressPreference = "SilentlyContinue"
Register-PSRepository -Default -ErrorAction:SilentlyContinue
Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser
if ((Get-PSRepository | ?{$_.Name -eq "PSGallery"}).Count -eq 0)
{
Register-PSRepository -Default -ErrorAction:SilentlyContinue
}

if ((Get-Module -ListAvailable -Name powershell-yaml | ?{$_.Version -eq "0.4.2"}).Count -eq 0)
{
Install-Module -Name powershell-yaml -RequiredVersion 0.4.2 -Force -Scope CurrentUser
}

$ciYmlContent = Get-Content $ciYmlPath -Raw
$ciYmlObj = ConvertFrom-Yaml $ciYmlContent -Ordered
if ($ciYmlObj.Contains("stages"))
Expand Down
109 changes: 109 additions & 0 deletions eng/common/scripts/Prepare-Release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#Requires -Version 6.0

[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$PackageName,
[string]$ServiceDirectory,
[string]$ReleaseDate, # Pass Date in the form MM/dd/yyyy"
[string]$BuildType # For Java
)

. ${PSScriptRoot}\common.ps1

function Get-ReleaseDay($baseDate)
{
# Find first friday
while ($baseDate.DayOfWeek -ne 5)
{
$baseDate = $baseDate.AddDays(1)
}

# Go to Tuesday
$baseDate = $baseDate.AddDays(4)

return $baseDate;
}

$ErrorPreference = 'Stop'

$packageProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $serviceDirectory

Write-Host "Source directory [ $serviceDirectory ]"

if (!$ReleaseDate)
{
$currentDate = Get-Date
$thisMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1));
$nextMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1).AddMonths(1));

if ($thisMonthReleaseDate -ge $currentDate)
{
# On track for this month release
$ParsedReleaseDate = $thisMonthReleaseDate
}
elseif ($currentDate.Day -lt 15)
{
# Catching up to this month release
$ParsedReleaseDate = $currentDate
}
else
{
# Next month release
$ParsedReleaseDate = $nextMonthReleaseDate
}
}
else
{
$ParsedReleaseDate = ([datetime]$ReleaseDate, 'MM/dd/yyyy', [Globalization.CultureInfo]::InvariantCulture)
}

$releaseDateString = $ParsedReleaseDate.ToString("MM/dd/yyyy")
$month = $ParsedReleaseDate.ToString("MMMM")

Write-Host
Write-Host "Assuming release is in $month with release date $releaseDateString" -ForegroundColor Green

$currentProjectVersion = $packageProperties.Version

$newVersion = Read-Host -Prompt "Input the new version, or press Enter to use use current project version '$currentProjectVersion'"

if (!$newVersion)
{
$newVersion = $currentProjectVersion;
}

$newVersionParsed = [AzureEngSemanticVersion]::ParseVersionString($newVersion)
if ($null -eq $newVersionParsed)
{
Write-Error "Invalid version $newVersion. Version must follow standard SemVer rules, see https://aka.ms/azsdk/engsys/packageversioning"
exit 1
}

if (Test-Path "Function:SetPackageVersion")
{
SetPackageVersion -PackageName $packageProperties.Name -Version $newVersion -ServiceDirectory $serviceDirectory -ReleaseDate $releaseDateString `
-BuildType $BuildType -GroupId $packageProperties.Group
}
else
{
LogError "The function 'SetPackageVersion' was not found.`
Make sure it is present in eng/scripts/Language-Settings.ps1.`
See https://github.com/Azure/azure-sdk-tools/blob/master/doc/common/common_engsys.md#code-structure"
exit 1
}

&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 `
-language $LanguageDisplayName `
-packageName $packageProperties.Name `
-version $newVersion `
-plannedDate $releaseDateString `
-packageRepoPath $packageProperties.serviceDirectory

git diff -s --exit-code $packageProperties.DirectoryPath
if ($LASTEXITCODE -ne 0)
{
git status
Write-Host "Some changes were made to the repo source" -ForegroundColor Green
Write-Host "Submit a pull request with the necessary changes to the repo" -ForegroundColor Green
}
6 changes: 6 additions & 0 deletions eng/common/scripts/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ $EngScriptsLanguageSettings = Join-path $EngScriptsDir "Language-Settings.ps1"
if (Test-Path $EngScriptsLanguageSettings) {
. $EngScriptsLanguageSettings
}

if (-not $LanguageShort)
{
$LangaugeShort = $Language
}

if (-not $LanguageDisplayName)
{
$LanguageDisplayName = $Language
}

# Transformed Functions
$GetPackageInfoFromRepoFn = "Get-${Language}-PackageInfoFromRepo"
$GetPackageInfoFromPackageFileFn = "Get-${Language}-PackageInfoFromPackageFile"
Expand Down