Skip to content

Commit

Permalink
Use powershell script to flatten ESRP release folder (Azure#35093)
Browse files Browse the repository at this point in the history
* Use powershell script to flatten ESRP release folder
* Skip maven-metadata.xml.* files when flattening ESRP package folders
  • Loading branch information
hallipr authored May 24, 2023
1 parent 99613a4 commit e236563
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
9 changes: 9 additions & 0 deletions eng/pipelines/templates/steps/java-publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
45 changes: 45 additions & 0 deletions eng/scripts/Flatten-MavenPackageFolder.ps1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e236563

Please sign in to comment.