Skip to content

Commit

Permalink
Add package content validation script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndiritu committed Aug 13, 2024
1 parent 42d9a0b commit cec054a
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions scripts/validatePackageContents.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Checks that expected files are present & have contents after the publish process to the local cache
param(
[Parameter(Mandatory=$true)][string] $ArtifactId,
[Parameter(Mandatory=$true)][string] $Version,
[Parameter()][string] $GroupId = "com.microsoft.graph",
[Parameter()][string] $MavenLocalCachePath = "~" + [System.IO.Path]::DirectorySeparatorChar + ".m2" + [System.IO.Path]::DirectorySeparatorChar + "repository"
)

$groupIdPath = $GroupId -replace "\.", [System.IO.Path]::DirectorySeparatorChar
$packagePath = Join-Path -Path $groupIdPath -ChildPath $ArtifactId
$packageFullPath = Join-Path -Path $MavenLocalCachePath -ChildPath $packagePath -AdditionalChildPath $Version

Write-Output "---------------------------------------------------"
Write-Output "Validating package contents at $packageFullPath"

if(-not (Test-Path -Path $packageFullPath)) {
Write-Output "Package not found in local cache."
exit 1
}

Write-Output "Package exists in local cache."

$expectedFiles = @(
"-javadoc.jar",
"-javadoc.jar.asc",
"-sources.jar",
"-sources.jar.asc",
".module",
".module.asc",
".pom",
".pom.asc",
".jar",
".jar.asc"
)

foreach($file in $expectedFiles) {
$file = $ArtifactId + "-" + $Version + $file
$filePath = Join-Path -Path $packageFullPath -ChildPath $file
if(-not (Test-Path -Path $filePath)) {
Write-Output "Expected file $file not found in package."
exit 1
}
$fileSize = (Get-Item -Path $filePath).length
if($fileSize -eq 0) {
Write-Output "File $file is empty."
exit 1
}
}

$mavenMetadataFiles = Get-ChildItem -Path $packageFullPath -Filter "maven-metadata*.xml"
if($mavenMetadataFiles.Count -eq 0) {
Write-Output "No maven-metadata*.xml files found in package."
exit 1
}

Write-Output "Package $ArtifactId is valid."
Write-Output "---------------------------------------------------"
exit 0

0 comments on commit cec054a

Please sign in to comment.