Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions eng/scripts/Generate-Patch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#
# 7. CreateNewBranch - Whether to create a new branch or use an existing branch. You would want to use an existing branch if you are using the same release tag for multiple libraries.
#
# 8. UseCurrentBranch - When set, creates patch branches from the current branch instead of remote main.
# Useful for local testing and dry-runs without requiring changes to be merged first. This is not a required parameter.
#
# Example: .\eng\scripts\Generate-Patch.ps1 -ArtifactName azure-mixedreality-remoterendering -ServiceDirectory remoterendering -ReleaseVersion 1.0.0 -PatchVersion 1.0.1
# This creates a remote branch "release/azure-mixedreality-remoterendering" with all the necessary changes.

Expand All @@ -29,7 +32,9 @@ param(
[Parameter(Mandatory=$false)][string]$PatchVersion,
[Parameter(Mandatory=$false)][string]$BranchName,
[Parameter(Mandatory=$false)][boolean]$PushToRemote,
[Parameter(Mandatory=$false)][boolean]$CreateNewBranch = $true
[Parameter(Mandatory=$false)][boolean]$CreateNewBranch = $true,
# When set, creates patch branches from the current branch instead of remote main.
[Parameter(Mandatory=$false)][switch]$UseCurrentBranch
)
Comment thread
XiaofeiCao marked this conversation as resolved.

function TestPathThrow($Path, $PathName) {
Expand All @@ -44,7 +49,8 @@ Write-Information "ArtifactName is: $ArtifactName"
Write-Information "ReleaseVersion is: $ReleaseVersion"
Write-Information "ServiceDirectoryName is: $ServiceDirectoryName"

$MainRemoteUrl = 'https://github.com/Azure/azure-sdk-for-java.git'
$MainRemoteHttpsUrl = 'https://github.com/Azure/azure-sdk-for-java.git'
$MainRemoteSshUrl = 'git@github.com:Azure/azure-sdk-for-java.git'
$RepoRoot = Resolve-Path "${PSScriptRoot}..\..\.."
$EngDir = Join-Path $RepoRoot "eng"
$EngCommonScriptsDir = Join-Path $EngDir "common" "scripts"
Expand All @@ -57,6 +63,7 @@ $GroupId = "com.azure"
TestPathThrow -Path $RepoRoot -PathName 'RepoRoot'

. (Join-Path $EngCommonScriptsDir common.ps1)
. (Join-Path $PSScriptRoot bomhelpers.ps1)

function GetPatchVersion($ReleaseVersion) {
$parsedSemver = [AzureEngSemanticVersion]::ParseVersionString($ReleaseVersion)
Expand All @@ -72,10 +79,10 @@ function GetPatchVersion($ReleaseVersion) {
return $null
}

function GetRemoteName($MainRemoteUrl) {
function GetRemoteName($MainRemoteHttpsUrl, $MainRemoteSshUrl) {
foreach($Remote in git remote show) {
$RemoteUrl = git remote get-url $Remote
if($RemoteUrl -eq $MainRemoteUrl) {
if(($RemoteUrl -eq $MainRemoteHttpsUrl) -or ($RemoteUrl -eq $MainRemoteSshUrl)) {
return $Remote
}
}
Expand Down Expand Up @@ -171,6 +178,7 @@ function CreatePatchRelease($ArtifactName, $ServiceDirectoryName, $PatchVersion,
$EngVersioningDir = Join-Path $EngDir "versioning"
$SetVersionFilePath = Join-Path $EngVersioningDir "set_versions.py"
$UpdateVersionFilePath = Join-Path $EngVersioningDir "update_versions.py"
$VersionClientPath = Join-Path $EngVersioningDir "version_client.txt"
$pkgProperties = Get-PkgProperties -PackageName $ArtifactName -ServiceDirectory $ServiceDirectoryName -GroupId $GroupId
$ChangelogPath = $pkgProperties.ChangeLogPath
$PomFilePath = Join-Path $pkgProperties.DirectoryPath "pom.xml"
Expand All @@ -196,8 +204,11 @@ function CreatePatchRelease($ArtifactName, $ServiceDirectoryName, $PatchVersion,
exit 1
}

$newDependenciesToVersion = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
parsePomFileDependencies -PomFilePath $PomFilePath -DependencyToVersion $newDependenciesToVersion
# Resolve new dependency versions for the changelog.
# Reuses GetResolvedDependencyVersions from bomhelpers.ps1 which substitutes
# prerelease versions with version_client.txt column 2 (GA/released version)
# to avoid showing beta versions in the changelog.
$newDependenciesToVersion = GetResolvedDependencyVersions -PomFilePath $PomFilePath -VersionClientPath $VersionClientPath


$releaseStatus = "$(Get-Date -Format $CHANGELOG_DATE_FORMAT)"
Expand Down Expand Up @@ -253,9 +264,9 @@ if(!$PatchVersion) {
}
Write-Information "PatchVersion is: $PatchVersion"

$RemoteName = GetRemoteName -MainRemoteUrl $MainRemoteUrl
$RemoteName = GetRemoteName -MainRemoteHttpsUrl $MainRemoteHttpsUrl -MainRemoteSshUrl $MainRemoteSshUrl
if(!$RemoteName) {
LogError "Could not fetch the remote name for the URL $MainRemoteUrl Exiting ..."
LogError "Could not fetch the remote name for the URL $MainRemoteHttpsUrl or $MainRemoteSshUrl. Exiting ..."
exit 1
}
Write-Information "RemoteName is: $RemoteName"
Expand All @@ -268,7 +279,8 @@ if(!$BranchName) {
try {
## Creating a new branch
if($CreateNewBranch) {
$cmdOutput = git checkout -b $BranchName $RemoteName/main
$base = if ($UseCurrentBranch) { "HEAD" } else { "$RemoteName/main" }
$cmdOutput = git checkout -b $BranchName $base
}
else {
$cmdOutput = git checkout $BranchName
Expand Down
40 changes: 35 additions & 5 deletions eng/scripts/Generate-Patches-For-Automatic-Releases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ param(
# $(Build.SourcesDirectory) - root of the repository
[Parameter(Mandatory = $true)][string]$SourcesDirectory,
# The yml file whose artifacts and additionalModules lists will be updated
[Parameter(Mandatory = $true)][string]$PackagesYmlPath
[Parameter(Mandatory = $true)][string]$PackagesYmlPath,
# When set, creates patch branches from the current branch instead of remote main.
[switch]$UseCurrentBranch
)

$StartTime = $( get-date )
Expand All @@ -26,10 +28,11 @@ try {
Write-Host "git fetch --all --prune"
git fetch --all --prune

# Checkout a branch to work on based off of main in upstream.
# Checkout a branch to work on based off of main (or current branch if -UseCurrentBranch).
if ($currentBranchName -ne $branchName) {
Write-Host "git checkout -b $branchName $remoteName/main"
git checkout -b $branchName $remoteName/main
$base = if ($UseCurrentBranch) { "HEAD" } else { "$remoteName/main" }
Write-Host "git checkout -b $branchName $base"
git checkout -b $branchName $base

if ($LASTEXITCODE -ne 0) {
LogError "Could not checkout branch $branchName, please check if it already exists and delete as necessary. Exiting..."
Expand All @@ -52,9 +55,36 @@ try {
$packagesData = $ymlObject["extends"]["parameters"]["artifacts"]
$libraryList = $null

# Build the list of artifacts being patched and normalize version_client.txt
# so non-patched in-group dependencies resolve to GA versions.
$patchedArtifactNames = @()
$patchedPomPaths = @()
foreach ($packageData in $packagesData) {
$patchedArtifactNames += $packageData["groupId"] + ":" + $packageData["name"]
$patchedPomPaths += Join-Path $SourcesDirectory "sdk" $packageData["ServiceDirectory"] $packageData["name"] "pom.xml"
}
NormalizeVersionFileForPatching -PatchedArtifactNames $patchedArtifactNames -PatchedPomFilePaths $patchedPomPaths

# Build PatchVersionOverrides: map of "${groupId}:${artifactId}" → patch version for all
# artifacts being patched. This is passed to generatepatch.ps1 so changelogs show the
# correct version when a sibling dependency is also being patched in the same run.
$PatchVersionOverrides = @{}
foreach ($packageData in $packagesData) {
$pkgArtifactId = $packageData["name"]
$pkgGroupId = $packageData["groupId"]
$pkgKey = "${pkgGroupId}:${pkgArtifactId}"
try {
$mavenInfo = GetVersionInfoForAnArtifactId -GroupId $pkgGroupId -ArtifactId $pkgArtifactId
$patchVersion = GetPatchVersion -ReleaseVersion $mavenInfo.LatestGAOrPatchVersion
$PatchVersionOverrides[$pkgKey] = $patchVersion
} catch {
Write-Warning "Could not determine patch version for ${pkgArtifactId}: $_"
}
}

# Reset each package to the latest stable release and update CHANGELOG, POM and README for patch release.
foreach ($packageData in $packagesData) {
. "${PSScriptRoot}/generatepatch.ps1" -ArtifactIds $packageData["name"] -ServiceDirectoryName $packageData["ServiceDirectory"] -BranchName $branchName -GroupId $packageData["groupId"]
. "${PSScriptRoot}/generatepatch.ps1" -ArtifactIds $packageData["name"] -ServiceDirectoryName $packageData["ServiceDirectory"] -BranchName $branchName -GroupId $packageData["groupId"] -UseCurrentBranch:$UseCurrentBranch -PatchVersionOverrides $PatchVersionOverrides
$libraryList += $packageData["groupId"] + ":" + $packageData["name"] + ","
}

Expand Down
6 changes: 2 additions & 4 deletions eng/scripts/Update-Artifacts-List-For-Patch-Release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ foreach ($ymlFile in $ymlFiles) {
}
}

# Use OrderedDictionary here for later "FindAllArtifactsThatNeedPatching"
# Use OrderedDictionary here for later "FindArtifactsThatNeedPatching"
$ArtifactInfos = New-Object System.Collections.Specialized.OrderedDictionary

Write-Host "Loading libraries from text file."
Expand All @@ -87,9 +87,7 @@ foreach ($line in Get-Content "${PSScriptRoot}/../pipelines/patch_release_client

UpdateDependencies -ArtifactInfos $ArtifactInfos

$AllDependenciesWithVersion = CreateForwardLookingVersions -ArtifactInfos $ArtifactInfos

FindAllArtifactsThatNeedPatching -ArtifactInfos $ArtifactInfos -AllDependenciesWithVersion $AllDependenciesWithVersion
FindArtifactsThatNeedPatching -ArtifactInfos $ArtifactInfos

$ArtifactsToPatch = $ArtifactInfos.Keys | Where-Object { $null -ne $ArtifactInfos[$_].FutureReleasePatchVersion } | ForEach-Object { $ArtifactInfos[$_].ArtifactId }

Expand Down
Loading