From e236563d530df415363b1369720d704795d4883e Mon Sep 17 00:00:00 2001 From: Patrick Hallisey Date: Tue, 23 May 2023 18:32:53 -0700 Subject: [PATCH] Use powershell script to flatten ESRP release folder (#35093) * Use powershell script to flatten ESRP release folder * Skip maven-metadata.xml.* files when flattening ESRP package folders --- .../templates/steps/java-publishing.yml | 9 ++++ eng/scripts/Flatten-MavenPackageFolder.ps1 | 45 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 eng/scripts/Flatten-MavenPackageFolder.ps1 diff --git a/eng/pipelines/templates/steps/java-publishing.yml b/eng/pipelines/templates/steps/java-publishing.yml index 52e1688fc5147..e4e0a9e051e28 100644 --- a/eng/pipelines/templates/steps/java-publishing.yml +++ b/eng/pipelines/templates/steps/java-publishing.yml @@ -97,6 +97,15 @@ steps: -ArtifactIDFilter "${{ parameters.ArtifactID }}" -GPGExecutablePath ${{ parameters.GPGExecutablePath }} -InformationAction Continue + - task: PowerShell@2 + displayName: 'Flatten output folder' + inputs: + pwsh: true + workingDirectory: $(Agent.BuildDirectory) + filePath: ${{ parameters.JavaRepoRoot }}/eng/scripts/Flatten-MavenPackageFolder.ps1 + arguments: > + -Path ${{ parameters.OutputDirectory }} + -InformationAction Continue - ${{if and(eq(parameters.ShouldPublish, 'true'), ne(parameters.StageOnly, 'true'))}}: - task: EsrpRelease@2 displayName: 'Publish to ESRP' diff --git a/eng/scripts/Flatten-MavenPackageFolder.ps1 b/eng/scripts/Flatten-MavenPackageFolder.ps1 new file mode 100644 index 0000000000000..0448171c17380 --- /dev/null +++ b/eng/scripts/Flatten-MavenPackageFolder.ps1 @@ -0,0 +1,45 @@ +#Requires -Version 7 +param( + [Parameter(Mandatory=$true)][string]$Path +) + +Set-StrictMode -Version 2.0 + +$ErrorActionPreference = "Stop" + +$files = Get-ChildItem -Path $Path -Recurse -File -Force -ErrorAction Stop + +$paths = @{} + +foreach($file in $files) { + $name = $file.Name + + # Skip maven-metadata.xml files. These are generated for each package and are not needed by ESRP. + if($name -match "^maven-metadata\.xml(\..*)?$") { + continue + } + + if($paths.Keys -contains $name) { + Write-Error "Duplicate file name: $name`n $($paths[$name]) and $($file.FullName)" + Write-Error "Unable to flatten: $Path" + exit 1 + } + + $paths[$name] = $file.FullName +} + +# Move the files to the root of the directory. +foreach($name in $paths.Keys) { + $oldPath = $paths[$name] + $newPath = Join-Path -Path $Path -ChildPath $name + Move-Item -Path $oldPath -Destination $newPath -Force -ErrorAction Stop +} + +$dirs = Get-ChildItem -Path $Path -Directory -Force -ErrorAction Stop + +# Remove all child directories. +foreach($dir in $dirs) { + Remove-Item $dir.FullName -Force -Recurse -ErrorAction Stop +} + +exit 0