From 6a7816e7507a53f89cd2d4dc07b0746d210be8ee Mon Sep 17 00:00:00 2001 From: Pallavi Taneja Date: Thu, 24 Feb 2022 15:48:07 -0800 Subject: [PATCH] Add pipeline information to the patches and fix the update_version script for when the module is not found. (#27295) Enable automatic pipeline triggers and other bugfixes. --- eng/scripts/bomhelpers.ps1 | 449 +++++++++++++++--------------- eng/scripts/generatepatch.ps1 | 12 +- eng/scripts/patchreleases.ps1 | 39 ++- eng/versioning/update_versions.py | 18 +- 4 files changed, 268 insertions(+), 250 deletions(-) diff --git a/eng/scripts/bomhelpers.ps1 b/eng/scripts/bomhelpers.ps1 index 70db6177f1ab7..5fcdbe90da4b2 100644 --- a/eng/scripts/bomhelpers.ps1 +++ b/eng/scripts/bomhelpers.ps1 @@ -2,310 +2,317 @@ # Licensed under the MIT License. class MavenArtifactInfo { - [String] $GroupId - [String] $ArtifactId - [String] $LatestGAOrPatchVersion - [String] $LatestRealeasedVersion + [String] $GroupId + [String] $ArtifactId + [String] $LatestGAOrPatchVersion + [String] $LatestReleasedVersion - MavenArtifactInfo($ArtifactId, $LatestGAOrPatchVersion, $LatestRealeasedVersion) { - $this.ArtifactId = $ArtifactId - $this.LatestGAOrPatchVersion = $LatestGAOrPatchVersion - $this.LatestRealeasedVersion = $LatestRealeasedVersion - $this.GroupId = 'com.azure' - } + MavenArtifactInfo($ArtifactId, $LatestGAOrPatchVersion, $LatestReleasedVersion) { + $this.ArtifactId = $ArtifactId + $this.LatestGAOrPatchVersion = $LatestGAOrPatchVersion + $this.LatestReleasedVersion = $LatestReleasedVersion + $this.GroupId = 'com.azure' + } } -. Join-Path ${PSScriptRoot} "common.ps1" +$RepoRoot = Resolve-Path "${PSScriptRoot}../../.." +$CommonScriptFilePath = Join-Path $RepoRoot "eng" "common" "scripts" "common.ps1" +. $CommonScriptFilePath function SetDependencyVersion($GroupId = "com.azure", $ArtifactId, $Version) { - $repoRoot = Resolve-Path "${PSScriptRoot}..\..\.." - $setVersionFilePath = Join-Path $repoRoot "eng" "versioning" "set_versions.py" - $cmdOutput = python $setVersionFilePath --bt client --new-version $Version --ar $ArtifactId --gi $GroupId - $cmdOutput = python $setVersionFilePath --bt client --ar $ArtifactId --gi $GroupId --increment-version + $repoRoot = Resolve-Path "${PSScriptRoot}../../.." + $setVersionFilePath = Join-Path $repoRoot "eng" "versioning" "set_versions.py" + $cmdOutput = python $setVersionFilePath --bt client --new-version $Version --ar $ArtifactId --gi $GroupId + $cmdOutput = python $setVersionFilePath --bt client --ar $ArtifactId --gi $GroupId --increment-version } function SetCurrentVersion($GroupId, $ArtifactId, $Version) { - $repoRoot = Resolve-Path "${PSScriptRoot}..\..\.." - $setVersionFilePath = Join-Path $repoRoot "eng" "versioning" "set_versions.py" - $cmdOutput = python $setVersionFilePath --bt client --new-version $Version --ar $ArtifactId --gi $GroupId + $repoRoot = Resolve-Path "${PSScriptRoot}../../.." + $setVersionFilePath = Join-Path $repoRoot "eng" "versioning" "set_versions.py" + $cmdOutput = python $setVersionFilePath --bt client --new-version $Version --ar $ArtifactId --gi $GroupId } function UpdateDependencyOfClientSDK() { - $repoRoot = Resolve-Path "${PSScriptRoot}..\..\.." - $updateVersionFilePath = Join-Path $repoRoot "eng" "versioning" "update_versions.py" - $cmdOutput = python $updateVersionFilePath --ut all --bt client --sr + $repoRoot = Resolve-Path "${PSScriptRoot}../../.." + $updateVersionFilePath = Join-Path $repoRoot "eng" "versioning" "update_versions.py" + $cmdOutput = python $updateVersionFilePath --ut all --bt client --sr } function GetAllAzComClientArtifactsFromMaven() { - $webResponseObj = Invoke-WebRequest -Uri "https://repo1.maven.org/maven2/com/azure" - $azureComArtifactIds = $webResponseObj.Links.HRef | Where-Object { ($_ -like 'azure-*') -and ($IgnoreList -notcontains $_) } | ForEach-Object { $_.substring(0, $_.length - 1) } - return $azureComArtifactIds | Where-Object { ($_ -like "azure-*") -and !($_ -like "azure-spring") } + $webResponseObj = Invoke-WebRequest -Uri "https://repo1.maven.org/maven2/com/azure" + $azureComArtifactIds = $webResponseObj.Links.HRef | Where-Object { ($_ -like 'azure-*') -and ($IgnoreList -notcontains $_) } | ForEach-Object { $_.substring(0, $_.length - 1) } + return $azureComArtifactIds | Where-Object { ($_ -like "azure-*") -and !($_ -like "azure-spring") } } function GetVersionInfoForAnArtifactId([String]$ArtifactId) { - $mavenMetadataUrl = "https://repo1.maven.org/maven2/com/azure/$($ArtifactId)/maven-metadata.xml" - $webResponseObj = Invoke-WebRequest -Uri $mavenMetadataUrl - $versions = ([xml]$webResponseObj.Content).metadata.versioning.versions.version - $semVersions = $versions | ForEach-Object { [AzureEngSemanticVersion]::ParseVersionString($_) } - $sortedVersions = [AzureEngSemanticVersion]::SortVersions($semVersions) - $latestReleasedVersion = $sortedVersions[0].RawVersion - $latestPatchOrGAVersion = $sortedVersions | Where-Object { !($_.IsPrerelease) } | ForEach-Object { $_.RawVersion } | Select-Object -First 1 + $mavenMetadataUrl = "https://repo1.maven.org/maven2/com/azure/$($ArtifactId)/maven-metadata.xml" + $webResponseObj = Invoke-WebRequest -Uri $mavenMetadataUrl + $versions = ([xml]$webResponseObj.Content).metadata.versioning.versions.version + $semVersions = $versions | ForEach-Object { [AzureEngSemanticVersion]::ParseVersionString($_) } + $sortedVersions = [AzureEngSemanticVersion]::SortVersions($semVersions) + $latestReleasedVersion = $sortedVersions[0].RawVersion + $latestPatchOrGAVersion = $sortedVersions | Where-Object { !($_.IsPrerelease) } | ForEach-Object { $_.RawVersion } | Select-Object -First 1 - $mavenArtifactInfo = [MavenArtifactInfo]::new($ArtifactId, $latestPatchOrGAVersion, $latestReleasedVersion) + $mavenArtifactInfo = [MavenArtifactInfo]::new($ArtifactId, $latestPatchOrGAVersion, $latestReleasedVersion) - return $mavenArtifactInfo + return $mavenArtifactInfo } function GetPatchVersion([String]$ReleaseVersion) { - $ParsedSemver = [AzureEngSemanticVersion]::new($ReleaseVersion) - if (!$ParsedSemver) { - LogError "Unexpected release version:$($ReleaseVersion).Exiting..." - exit 1 - } + $ParsedSemver = [AzureEngSemanticVersion]::new($ReleaseVersion) + if (!$ParsedSemver) { + LogError "Unexpected release version:$($ReleaseVersion).Exiting..." + exit 1 + } - return "$($ParsedSemver.Major).$($ParsedSemver.Minor).$($ParsedSemver.Patch + 1)" + return "$($ParsedSemver.Major).$($ParsedSemver.Minor).$($ParsedSemver.Patch + 1)" } function GetRemoteName() { - $mainRemoteUrl = 'https://github.com/Azure/azure-sdk-for-java.git' - foreach ($rem in git remote show) { - $remoteUrl = git remote get-url $rem - if ($remoteUrl -eq $mainRemoteUrl) { - return $rem - } + $mainRemoteUrl = 'https://github.com/Azure/azure-sdk-for-java.git' + foreach ($rem in git remote show) { + $remoteUrl = git remote get-url $rem + if ($remoteUrl -eq $mainRemoteUrl) { + return $rem } - LogError "Could not compute the remote name." - return $null + } + LogError "Could not compute the remote name." + return $null } function GetPipelineName([string]$ArtifactId, [string]$ArtifactDirPath) { - $ciYmlFilePath = Join-Path ArtifactDirPath "ci.yml" + $ciYmlFilePath = Join-Path $ArtifactDirPath "ci.yml" if (Test-Path $ciYmlFilePath) { return "java - " + $ArtifactId } else { - $ciDirPath = Split-Path -Path $arInfo.ArtifactDirPath -Parent + $ciDirPath = Split-Path -Path $ArtifactDirPath -Parent $ciYmlFilePath = Join-Path $ciDirPath "ci.yml" if (Test-Path $ciYmlFilePath) { - return "java - " + $arInfo.ServiceDirectoryName + $serviceDirectoryName = [System.IO.Path]::GetFileName($ciDirPath) + return "java - " + $serviceDirectoryName } } } -function TriggerPipeline($PatchInfos) { - $distinctPipelineNames = $PatchInfos | Select-Object {$_.PipelineName} | Get-Unique -AsString +function TriggerPipeline($PatchInfos, $BranchName) { + $distinctPipelineNames = $PatchInfos | ForEach-Object { $_.PipelineName } | Get-Unique $distinctPipelineNames | ForEach-Object { - Write-Output "Triggering pipeline {$_}" - $cmdoutput = az pipeline --name $_} + Write-Output "Triggering pipeline $_" + $cmdOutput = az pipelines run -o json --name ""$_"" --organization "https://dev.azure.com/azure-sdk" --project "internal" --branch ""$BranchName"" + if($LASTEXITCODE) { + LogError "Could not trigger the run for the pipeline $_" + exit $LASTEXITCODE + } + } } function GetBranchName($ArtifactId) { - $artifactNameToLower = $ArtifactId.ToLower() - $guid = [guid]::NewGuid().Guid - return "release/$($artifactNameToLower)_$guid" + $artifactNameToLower = $ArtifactId.ToLower() + $guid = [guid]::NewGuid().Guid + return "release/$($artifactNameToLower)_$guid" } class ArtifactPatchInfo { - [string]$ArtifactId - [string]$ServiceDirectoryName - [string]$ArtifactDirPath - [string]$LatestGAOrPatchVersion - [string]$CurrentPomFileVersion - [string]$ChangeLogPath - [string]$ReadMePath - [string]$PipelineName - } + [string]$ArtifactId + [string]$ServiceDirectoryName + [string]$ArtifactDirPath + [string]$LatestGAOrPatchVersion + [string]$CurrentPomFileVersion + [string]$FutureReleasePatchVersion + [string]$ChangeLogPath + [string]$ReadMePath + [string]$PipelineName +} - function GetDependencyToVersion($PomFilePath) { - $dependencyNameToVersion = @{} - $pomFileContent = [xml](Get-Content -Path $PomFilePath) - foreach ($dependency in $pomFileContent.project.dependencies.dependency) { - $scope = $dependency.scope - if ($scope -ne 'test') { - $dependencyNameToVersion[$dependency.artifactId] = $dependency.version - } +function GetDependencyToVersion($PomFilePath) { + $dependencyNameToVersion = @{} + $pomFileContent = [xml](Get-Content -Path $PomFilePath) + foreach ($dependency in $pomFileContent.project.dependencies.dependency) { + $scope = $dependency.scope + if ($scope -ne 'test') { + $dependencyNameToVersion[$dependency.artifactId] = $dependency.version } - - return $dependencyNameToVersion } - function GetChangeLogContent($NewDependencyNameToVersion, $OldDependencyNameToVersion) { - $content = @() - $content += "" - $content += "### Other Changes" - $content += "" - $content += "#### Dependency Updates" - $content += "" + + return $dependencyNameToVersion +} + +function GetChangeLogContent($NewDependencyNameToVersion, $OldDependencyNameToVersion) { + $content = @() + $content += "" + $content += "### Other Changes" + $content += "" + $content += "#### Dependency Updates" + $content += "" - foreach ($key in $OldDependencyNameToVersion.Keys) { - $oldVersion = $($OldDependencyNameToVersion[$key]).Trim() - $newVersion = $($NewDependencyNameToVersion[$key]).Trim() - if ($oldVersion -ne $newVersion) { - $content += "- Upgraded ``$key`` from ``$oldVersion`` to version ``$newVersion``." - } + foreach ($key in $OldDependencyNameToVersion.Keys) { + $oldVersion = $($OldDependencyNameToVersion[$key]).Trim() + $newVersion = $($NewDependencyNameToVersion[$key]).Trim() + if ($oldVersion -ne $newVersion) { + $content += "- Upgraded ``$key`` from ``$oldVersion`` to version ``$newVersion``." } + } - $content += "" + $content += "" - return $content - } + return $content +} - function GitCommit($Message) { - $cmdOutput = git commit -a -m $Message - if ($LASTEXITCODE -ne 0) { - LogError "Could not commit the changes locally.Exiting..." - exit 1 - } +function GitCommit($Message) { + $cmdOutput = git commit -a -m $Message + if ($LASTEXITCODE -ne 0) { + LogError "Could not commit the changes locally.Exiting..." + exit $LASTEXITCODE } +} - function GeneratePatches($ArtifactPatchInfos, [string]$BranchName, [string]$RemoteName, [string]$GroupId = "com.azure") { - foreach ($patchInfo in $ArtifactPatchInfos) { - GeneratePatch -PatchInfo $patchInfo -BranchName $BranchName -RemoteName $RemoteName -GroupId $GroupId - } - - TriggerPipeline -PatchInfos $ArtifactPatchInfos +function GeneratePatches($ArtifactPatchInfos, [string]$BranchName, [string]$RemoteName, [string]$GroupId = "com.azure") { + foreach ($patchInfo in $ArtifactPatchInfos) { + GeneratePatch -PatchInfo $patchInfo -BranchName $BranchName -RemoteName $RemoteName -GroupId $GroupId } + + TriggerPipeline -PatchInfos $ArtifactPatchInfos -BranchName $BranchName +} - function GeneratePatch($PatchInfo, [string]$BranchName, [string]$RemoteName, [string]$GroupId = "com.azure") { - $artifactId = $PatchInfo.ArtifactId - $releaseVersion = $PatchInfo.LatestGAOrPatchVersion - $serviceDirectoryName = $PatchInfo.ServiceDirectoryName - $currentPomFileVersion = $PatchInfo.CurrentPomFileVersion - $artifactDirPath = $PatchInfo.ArtifactDirPath - $changelogPath = $PatchInfo.ChangeLogPath +function GeneratePatch($PatchInfo, [string]$BranchName, [string]$RemoteName, [string]$GroupId = "com.azure") { + $artifactId = $PatchInfo.ArtifactId + $releaseVersion = $PatchInfo.LatestGAOrPatchVersion + $serviceDirectoryName = $PatchInfo.ServiceDirectoryName + $currentPomFileVersion = $PatchInfo.CurrentPomFileVersion + $artifactDirPath = $PatchInfo.ArtifactDirPath + $changelogPath = $PatchInfo.ChangeLogPath + $patchVersion = $PatchInfo.FutureReleasePatchVersion - if (!$artifactId) { - Write-Output "artifactId can't be null". - exit 1 - } - - if (!$BranchName) { - $BranchName = GetBranchName -ArtifactId $artifactId - } + if (!$artifactId) { + LogError "artifactId can't be null". + exit 1 + } - if(!$BranchName) { - Write-Output "BranchName can't be null". - exit 1 - } + if (!$BranchName) { + Write-Output "BranchName can't be null". + exit 1 + } - if (!$RemoteName) { - Write-Output "RemoteName can't be null". - exit 1 - } + if (!$RemoteName) { + Write-Output "RemoteName can't be null". + exit 1 + } - $cmdOutput = git checkout -b $BranchName $RemoteName/main - if ($LASTEXITCODE -ne 0) { - LogError "Could not checkout branch $BranchName), please check if it already exists and delete as necessary. Exiting..." - exit 1 - } + $cmdOutput = git checkout -b $BranchName $RemoteName/main + if ($LASTEXITCODE -ne 0) { + LogError "Could not checkout branch $BranchName), please check if it already exists and delete as necessary. Exiting..." + exit $LASTEXITCODE + } - if (!$releaseVersion) { - Write-Output "Computing the latest release version for each of the relevant artifacts from maven central." - $mavenArtifactInfo = [MavenArtifactInfo](GetVersionInfoForAnArtifactId -ArtifactId $artifactId) + if (!$releaseVersion) { + Write-Output "Computing the latest release version for each of the relevant artifacts from maven central." + $mavenArtifactInfo = [MavenArtifactInfo](GetVersionInfoForAnArtifactId -ArtifactId $artifactId) - if ($null -eq $mavenArtifactInfo) { - LogError "Could not find $artifactId on maven central." - exit 1 - } + if ($null -eq $mavenArtifactInfo) { + LogError "Could not find $artifactId on maven central." + exit 1 + } - $mavenLatestGAOrPatchVersion = $mavenArtifactInfo.LatestGAOrPatchVersion - if ([String]::IsNullOrWhiteSpace($mavenLatestGAOrPatchVersion)) { - LogError "Could not compute the latest GA\release version for $artifactId from maven central. Exiting." - exit 1 - } - - $releaseVersion = $mavenArtifactInfo.LatestGAOrPatchVersion - Write-Output "Found the latest GA/Patch version $releaseVersion. Using this to prepare the patch." + $mavenLatestGAOrPatchVersion = $mavenArtifactInfo.LatestGAOrPatchVersion + if ([String]::IsNullOrWhiteSpace($mavenLatestGAOrPatchVersion)) { + LogError "Could not compute the latest GA\release version for $artifactId from maven central. Exiting." + exit 1 } + $releaseVersion = $mavenArtifactInfo.LatestGAOrPatchVersion + Write-Output "Found the latest GA/Patch version $releaseVersion. Using this to prepare the patch." + } + + if (!$patchVersion) { $patchVersion = GetPatchVersion -ReleaseVersion $releaseVersion Write-Output "PatchVersion is: $patchVersion" + } - $releaseTag = "$($artifactId)_$($releaseVersion)" - if (!$currentPomFileVersion -or !$artifactDirPath -or !$changelogPath) { - $pkgProperties = [PackageProps](Get-PkgProperties -PackageName $artifactId -ServiceDirectory $serviceDirectoryName) - $artifactDirPath = $pkgProperties.DirectoryPath - $currentPomFileVersion = $pkgProperties.Version - $changelogPath = $pkgProperties.ChangeLogPath - } + $releaseTag = "$($artifactId)_$($releaseVersion)" + if (!$currentPomFileVersion -or !$artifactDirPath -or !$changelogPath) { + $pkgProperties = [PackageProps](Get-PkgProperties -PackageName $artifactId -ServiceDirectory $serviceDirectoryName) + $artifactDirPath = $pkgProperties.DirectoryPath + $currentPomFileVersion = $pkgProperties.Version + $changelogPath = $pkgProperties.ChangeLogPath + } - if (!$artifactDirPath) { - LogError "ArtifactDirPath could not be found. Exiting." - exit 1 - } + if (!$artifactDirPath) { + LogError "ArtifactDirPath could not be found. Exiting." + exit 1 + } - if ($currentPomFileVersion -ne $releaseVersion) { - Write-Output "Hard reseting the sources for $artifactId to version $releaseVersion using release tag: $releaseTag." - Write-Information "Fetching all the tags from $RemoteName" - $cmdOutput = git fetch $RemoteName $releaseTag + if ($currentPomFileVersion -ne $releaseVersion) { + Write-Output "Hard reseting the sources for $artifactId to version $releaseVersion using release tag: $releaseTag." + Write-Output "Fetching all the tags from $RemoteName" + $cmdOutput = git fetch $RemoteName $releaseTag - if ($LASTEXITCODE -ne 0) { - LogError "Could not restore the tags for release tag $releaseTag" - exit 1 - } - - $cmdOutput = git restore --source $releaseTag -W -S $artifactDirPath - if ($LASTEXITCODE -ne 0) { - LogError "Could not reset sources for $artifactId) to the release version $releaseVersion" - exit 1 - } - - ## Commit these changes. - GitCommit -Message "Reset sources for $artifactId to the release version $releaseVersion." - } - - $pomFilePath = Join-Path $artifactDirPath "pom.xml" - $oldDependencyNameToVersion = GetDependencyToVersion -PomFilePath $pomFilePath - $cmdOutput = SetCurrentVersion -GroupId $GroupId -ArtifactId $artifactId -$Version $patchVersion --gi $GroupId if ($LASTEXITCODE -ne 0) { - LogError "Could not set the dependencies for $artifactId" - exit 1 + LogError "Could not restore the tags for release tag $releaseTag" + exit $LASTEXITCODE } - $cmdOutput = UpdateDependencyOfClientSDK + $cmdOutput = git restore --source $releaseTag -W -S $artifactDirPath if ($LASTEXITCODE -ne 0) { - LogError LogError "Could not update all references for for $artifactId" - exit 1 + LogError "Could not reset sources for $artifactId) to the release version $releaseVersion" + exit $LASTEXITCODE } + + ## Commit these changes. + GitCommit -Message "Reset sources for $artifactId to the release version $releaseVersion." + } + + $pomFilePath = Join-Path $artifactDirPath "pom.xml" + $oldDependencyNameToVersion = GetDependencyToVersion -PomFilePath $pomFilePath + $cmdOutput = SetCurrentVersion -GroupId $GroupId -ArtifactId $artifactId -$Version $patchVersion --gi $GroupId + if ($LASTEXITCODE -ne 0) { + LogError "Could not set the dependencies for $artifactId" + exit $LASTEXITCODE + } + + $cmdOutput = UpdateDependencyOfClientSDK + if ($LASTEXITCODE -ne 0) { + LogError LogError "Could not update all references for for $artifactId" + exit $LASTEXITCODE + } - $newDependenciesToVersion = GetDependencyToVersion -PomFilePath $pomFilePath - $releaseStatus = "$(Get-Date -Format $CHANGELOG_DATE_FORMAT)" - $releaseStatus = "($releaseStatus)" - $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $changelogPath + $newDependenciesToVersion = GetDependencyToVersion -PomFilePath $pomFilePath + $releaseStatus = "$(Get-Date -Format $CHANGELOG_DATE_FORMAT)" + $releaseStatus = "($releaseStatus)" + $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $changelogPath - $Content = GetChangeLogContent -NewDependencyNameToVersion $newDependenciesToVersion -OldDependencyNameToVersion $oldDependencyNameToVersion - $newChangeLogEntry = New-ChangeLogEntry -Version $patchVersion -Status $releaseStatus -Content $Content - if ($newChangeLogEntry) { - $changeLogEntries.Insert(0, $patchVersion, $newChangeLogEntry) - } - else { - LogError "Failed to create new changelog entry for $artifactId" - exit 1 - } + $Content = GetChangeLogContent -NewDependencyNameToVersion $newDependenciesToVersion -OldDependencyNameToVersion $oldDependencyNameToVersion + $newChangeLogEntry = New-ChangeLogEntry -Version $patchVersion -Status $releaseStatus -Content $Content + if ($newChangeLogEntry) { + $changeLogEntries.Insert(0, $patchVersion, $newChangeLogEntry) + } + else { + LogError "Failed to create new changelog entry for $artifactId" + exit 1 + } - $cmdOutput = Set-ChangeLogContent -ChangeLogLocation $changelogPath -ChangeLogEntries $changeLogEntries - if ($LASTEXITCODE -ne 0) { - LogError "Could not update the changelog at $changelogPath). Exiting..." - exit 1 - } + $cmdOutput = Set-ChangeLogContent -ChangeLogLocation $changelogPath -ChangeLogEntries $changeLogEntries + if ($LASTEXITCODE -ne 0) { + LogError "Could not update the changelog at $changelogPath). Exiting..." + exit $LASTEXITCODE + } - GitCommit -Message "Prepare $artifactId for $patchVersion patch release." - if ($PushToRemote) { - $cmdOutput = git push $RemoteName $BranchName - if ($LASTEXITCODE -ne 0) { - LogError "Could not push the changes to $RemoteName\$BranchName. Exiting..." - exit 1 - } - Write-Output "Pushed the changes to remote:$RemoteName, Branch:$BranchName" - } + GitCommit -Message "Prepare $artifactId for $patchVersion patch release." + Write-Output "Pushing changes to the upstream branch: $RemoteName/$BranchName" + $cmdOutput = git push $RemoteName $BranchName + if ($LASTEXITCODE -ne 0) { + LogError "Could not push the changes to $RemoteName/$BranchName. Exiting..." + exit $LASTEXITCODE + } + Write-Output "Pushed the changes to remote:$RemoteName, Branch:$BranchName" - if(!$PatchInfo.PipelineName) { - $PatchInfo.PipelineName = GetPipelineName -ArtifactId $artifactId -ArtifactDirPath $artifactDirPath - } + if (!$PatchInfo.PipelineName) { + $PatchInfo.PipelineName = GetPipelineName -ArtifactId $artifactId -ArtifactDirPath $artifactDirPath + } - if(!$PatchInfo.PipelineName) { - LogError "Could not calculate the pipeline Name. Will not trigger a run." - } - - Write-Output "Patching done for $artifactId." + if (!$PatchInfo.PipelineName) { + Write-Output "Could not calculate the pipeline name, will not trigger a run." } - + + Write-Output "Sources prepared for the patch release for $artifactId." +} diff --git a/eng/scripts/generatepatch.ps1 b/eng/scripts/generatepatch.ps1 index cadc2ec5c82df..1b626eaf23dd3 100644 --- a/eng/scripts/generatepatch.ps1 +++ b/eng/scripts/generatepatch.ps1 @@ -40,8 +40,7 @@ You should make any additional changes to the change log to capture the changes param( [string[]]$ArtifactIds, [string]$ServiceDirectoryName, - [string]$BranchName, - [boolean]$PushToRemote = $false + [string]$BranchName ) $RepoRoot = Resolve-Path "${PSScriptRoot}..\..\.." @@ -67,12 +66,19 @@ if (!$RemoteName) { } Write-Output "RemoteName is: $RemoteName" +$BranchName = $BranchName ?? (GetBranchName -ArtifactId "generatepatch") +if(!$BranchName) { + LogError "Could not compute the branch name." + exit 1 +} +Write-Output "BranchName is: $BranchName" + foreach ($artifactId in $ArtifactIds) { $patchInfo = [ArtifactPatchInfo]::new() $patchInfo.ArtifactId = $artifactId $patchInfo.ServiceDirectoryName = $ServiceDirectoryName GeneratePatch -PatchInfo $patchInfo -BranchName $BranchName -RemoteName $RemoteName -GroupId "com.azure" - TriggerPipeline -PatchInfos $patchInfo + TriggerPipeline -PatchInfos $patchInfo -BranchName $BranchName } Write-Output "Patch generation completed successfully." \ No newline at end of file diff --git a/eng/scripts/patchreleases.ps1 b/eng/scripts/patchreleases.ps1 index 8faf3a6150662..70932dac97483 100644 --- a/eng/scripts/patchreleases.ps1 +++ b/eng/scripts/patchreleases.ps1 @@ -6,7 +6,7 @@ param( ) Write-Information "PS Script Root is: $PSScriptRoot" -$RepoRoot = Resolve-Path "${PSScriptRoot}..\..\.." +$RepoRoot = Resolve-Path "${PSScriptRoot}../../.." $CommonScriptFilePath = Join-Path $RepoRoot "eng" "common" "scripts" "common.ps1" $BomHelpersFilePath = Join-Path $PSScriptRoot "bomhelpers.ps1" . $CommonScriptFilePath @@ -19,7 +19,7 @@ class ArtifactInfo { [string]$ServiceDirectoryName [string]$ArtifactDirPath [string]$LatestGAOrPatchVersion - [string]$FutureReleasedPatchVersion + [string]$FutureReleasePatchVersion [string]$CurrentPomFileVersion [string]$ChangeLogPath [string]$ReadMePath @@ -42,6 +42,7 @@ function ConvertToPatchInfo([ArtifactInfo]$ArInfo) { $patchInfo.ChangeLogPath = $ArInfo.ChangeLogPath $patchInfo.ReadMePath = $ArInfo.ReadMePath $patchInfo.PipelineName = $ArInfo.PipelineName + $patchInfo.FutureReleasePatchVersion = $arInfo.FutureReleasePatchVersion return $patchInfo } @@ -147,9 +148,9 @@ function FindAllArtifactsToBePatched([String]$DependencyId, [String]$PatchVersio foreach ($id in $ArtifactInfos.Keys) { $arInfo = $ArtifactInfos[$id] - $futureReleasedPatchVersion = $arInfo.FutureReleasedPatchVersion + $futureReleasePatchVersion = $arInfo.FutureReleasePatchVersion - if($futureReleasedPatchVersion) { + if ($futureReleasePatchVersion) { # This library is already being patched and hence analyzed so we don't need to analyze it again. if ($id -ne 'azure-core' -or $id -ne 'azure-core-http-netty') { continue; @@ -160,7 +161,7 @@ function FindAllArtifactsToBePatched([String]$DependencyId, [String]$PatchVersio if ($depVersion -and $depVersion -ne $PatchVersion) { $currentGAOrPatchVersion = $arInfo.LatestGAOrPatchVersion $newPatchVersion = GetPatchVersion -ReleaseVersion $currentGAOrPatchVersion - $arInfo.FutureReleasedPatchVersion = $newPatchVersion + $arInfo.FutureReleasePatchVersion = $newPatchVersion $artifactsToPatch[$id] = $id $depArtifactsToPatch = FindAllArtifactsToBePatched -DependencyId $id -PatchVersion $newPatchVersion -ArtifactInfos $ArtifactInfos foreach ($recArtifacts in $depArtifactsToPatch.Keys) { @@ -175,10 +176,10 @@ function FindAllArtifactsToBePatched([String]$DependencyId, [String]$PatchVersio function GetPatchSets($artifactsToPatch, [hashtable]$ArtifactInfos) { $patchSets = @() - foreach($artifactToPatch in $artifactsToPatch.Keys) { + foreach ($artifactToPatch in $artifactsToPatch.Keys) { $patchDependencies = @{} $dependencies = $artifactInfos[$artifactToPatch].Dependencies - $dependencies.Keys | Where-Object { $null -ne $artifactsToPatch[$_]} | ForEach-Object {$patchDependencies[$_] = $_} + $dependencies.Keys | Where-Object { $null -ne $artifactsToPatch[$_] } | ForEach-Object { $patchDependencies[$_] = $_ } $patchDependencies[$artifactToPatch] = $artifactToPatch $unionSet = @{} @@ -186,14 +187,15 @@ function GetPatchSets($artifactsToPatch, [hashtable]$ArtifactInfos) { $reducedPatchSets = @() # Add this set to the exiting sets and reduce duplicates. - foreach($patchSet in $patchSets) { - $matches = $patchDependencies.Keys | Where-Object {$patchSet[$_]} | Select-Object $_ -First 1 + foreach ($patchSet in $patchSets) { + $matches = $patchDependencies.Keys | Where-Object { $patchSet[$_] } | Select-Object $_ -First 1 - if($matches) { - $patchSet.Keys | ForEach-Object {$unionSet[$_] = $_ } - } else { + if ($matches) { + $patchSet.Keys | ForEach-Object { $unionSet[$_] = $_ } + } + else { $reducedPatchSets += $patchSet - } + } } $patchSets = $reducedPatchSets @@ -208,7 +210,7 @@ function UpdateDependenciesInVersionClient([string]$ArtifactId, [hashtable]$Arti $dependencies = $arInfo.Dependencies foreach ($depId in $dependencies.Keys) { $depArtifactInfo = $ArtifactInfos[$depId] - $newDependencyVersion = $depArtifactInfo.FutureReleasedPatchVersion + $newDependencyVersion = $depArtifactInfo.FutureReleasePatchVersion if (!$newDependencyVersion) { $newDependencyVersion = $depArtifactInfo.LatestGAOrPatchVersion @@ -220,7 +222,7 @@ function UpdateDependenciesInVersionClient([string]$ArtifactId, [hashtable]$Arti } } function UndoVersionClientFile() { - $repoRoot = Resolve-Path "${PSScriptRoot}..\..\.." + $repoRoot = Resolve-Path "${PSScriptRoot}../../.." $versionClientFile = Join-Path $repoRoot "eng" "versioning" "version_client.txt" $cmdOutput = git checkout $versionClientFile } @@ -250,7 +252,7 @@ $AzCoreVersion = $ArtifactInfos[$AzCoreArtifactId].LatestGAOrPatchVersion # For testing only. # $AzCoreVersion = "1.26.0" -# $ArtifactInfos[$AzCoreArtifactId].FutureReleasedPatchVersion = $AzCoreVersion +# $ArtifactInfos[$AzCoreArtifactId].FutureReleasePatchVersion = $AzCoreVersion # $AzCoreNettyArtifactId = "azure-core-http-netty" # $ArtifactInfos[$AzCoreNettyArtifactId].Dependencies[$AzCoreArtifactId] = $AzCoreVersion @@ -288,7 +290,4 @@ foreach ($patchSet in $ReleaseSets) { } } -New-Item -Path . -Name "ReleasePatchInfo.csv" -ItemType "file" -Value $fileContent.ToString() -Force - - - +New-Item -Path . -Name "ReleasePatchInfo.csv" -ItemType "file" -Value $fileContent.ToString() -Force \ No newline at end of file diff --git a/eng/versioning/update_versions.py b/eng/versioning/update_versions.py index 2a9675daa89c7..fde540d21bf30 100644 --- a/eng/versioning/update_versions.py +++ b/eng/versioning/update_versions.py @@ -110,16 +110,22 @@ def update_versions(update_type, version_map, ext_dep_map, target_file, skip_rea continue if is_include: try: - module = ext_dep_map[module_name] - new_include_version = module.string_for_allowlist_include() - newline = re.sub(external_dependency_include_regex, new_include_version, line) + module = ext_dep_map.get(module_name) + if module: + new_include_version = module.string_for_allowlist_include() + newline = re.sub(external_dependency_include_regex, new_include_version, line) + else: + continue except AttributeError: raise ValueError('Module: {0} does not have an external dependency version.\nFile={1}\nLine={2}'.format(module_name, target_file, line)) else: try: - module = ext_dep_map[module_name] - new_version = module.external_dependency - newline = re.sub(external_dependency_version_regex, new_version, line) + module = ext_dep_map.get(module_name) + if module: + new_version = module.external_dependency + newline = re.sub(external_dependency_version_regex, new_version, line) + else: + continue except AttributeError: raise ValueError('Module: {0} does not have an external dependency version.\nFile={1}\nLine={2}'.format(module_name, target_file, line)) else: