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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

## VERSION

* Adds `Get-AzulZulu` shared function for using `api.azul.com` for downloads

## 2510.2820.0

* A working solution for adding output filters for Get-EvergreenApp. This should simplify returning details for a specific application by not requiring the use of `Where-Object`. The filters can be added to `/Evergreen/Filters`, along side the cached Apps and Manifests. [#871](https://github.com/EUCPilots/evergreen-module/discussions/871)
Expand Down
62 changes: 62 additions & 0 deletions Evergreen/Shared/Get-AzulZulu.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function Get-AzulZulu {
<#
.SYNOPSIS
Retrieves Azul Zulu JDK/JRE release information.

.DESCRIPTION
Queries the Azul API to get the latest Azul Zulu OpenJDK releases.

.PARAMETER res
Resource object containing API configuration.

.EXAMPLE
Get-AzulZulu -res $ResourceObject
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject] $res
)

# Constants for property names
$DISTRO_VERSION = 'distro_version'
$DOWNLOAD_URL = 'download_url'

# Pass the repo releases API URL and return a formatted object
$params = @{
Uri = $res.Get.Update.Uri
ContentType = $res.Get.Update.ContentType
}
$Releases = Invoke-EvergreenRestMethod @params

if ($null -eq $Releases -or $Releases.Count -eq 0) {
Write-Warning -Message "$($MyInvocation.MyCommand): No releases found."
return
}
else {
Write-Verbose -Message "$($MyInvocation.MyCommand): found $($Releases.count) releases."
}

# Find the latest version
$Version = $Releases | `
Where-Object { $null -ne $_.$DISTRO_VERSION } | `
Sort-Object { [System.Version]($_.$DISTRO_VERSION -join ".") } -Descending | `
Select-Object -First 1
$LatestVersion = $Version.$DISTRO_VERSION -join "."
Write-Verbose -Message "$($MyInvocation.MyCommand): found latest version: $LatestVersion"

Write-Verbose -Message "$($MyInvocation.MyCommand): Filter for latest releases."
foreach ($Release in ($Releases | Where-Object { ($_.$DISTRO_VERSION -join ".") -eq ($Version.$DISTRO_VERSION -join ".") })) {
$PSObject = [PSCustomObject]@{
Version = $Release.$DISTRO_VERSION -join "."
JavaVersion = "$($Release.java_version -join ".")+$($Release.openjdk_build_number)"
ImageType = if ($Release.$DOWNLOAD_URL -match "[/\\]jre[/\\-]") { "JRE" } else { "JDK" }
Architecture = Get-Architecture -String $Release.$DOWNLOAD_URL
Type = Get-FileType -File $Release.$DOWNLOAD_URL
URI = $Release.$DOWNLOAD_URL
}
Write-Output -InputObject $PSObject
}
}
119 changes: 119 additions & 0 deletions tests/Shared/Get-AzulZulu.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<#
.SYNOPSIS
Pester tests for Get-AzulZulu.
#>
[OutputType()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This is OK for the test files.")]
param ()

BeforeDiscovery {
}

BeforeAll {
}

InModuleScope -ModuleName "Evergreen" {
Describe -Name "Get-AzulZulu" {
Context "Throw scenarios" {
It "Does not throw when passed correct parameters" {
# Mock resource object
$res = [PSCustomObject]@{
Get = [PSCustomObject]@{
Update = [PSCustomObject]@{
Uri = "https://api.azul.com/metadata/v1/zulu/packages/?java_version=25&os=windows&archive_type=msi&crac_supported=false&latest=true&release_status=ga&availability_types=CA&certifications=tck&page=1&page_size=100"
ContentType = "application/json"
}
}
}
{ Get-AzulZulu -res $res } | Should -Not -Throw
}

It "Should throw when passed an incorrect URL" {
# Mock resource object with invalid URL
$res = [PSCustomObject]@{
Get = [PSCustomObject]@{
Update = [PSCustomObject]@{
Uri = "https://api.example.com/invalid/endpoint"
ContentType = "application/json"
}
}
}
{ Get-AzulZulu -res $res } | Should -Throw
}
}

Context "It returns an object with the expected properties" {
BeforeAll {
# Mock resource object
$res = [PSCustomObject]@{
Get = [PSCustomObject]@{
Update = [PSCustomObject]@{
Uri = "https://api.azul.com/metadata/v1/zulu/packages/?java_version=25&os=windows&archive_type=msi&crac_supported=false&latest=true&release_status=ga&availability_types=CA&certifications=tck&page=1&page_size=100"
ContentType = "application/json"
}
}
}
$result = Get-AzulZulu -res $res
}

It "Returns results" {
$result | Should -Not -BeNullOrEmpty
}

It "Returns a Version property" {
$result[0].Version | Should -Not -BeNullOrEmpty
$result[0].Version.Length | Should -BeGreaterThan 0
}

It "Returns a JavaVersion property" {
$result[0].JavaVersion | Should -Not -BeNullOrEmpty
$result[0].JavaVersion.Length | Should -BeGreaterThan 0
}

It "Returns an ImageType property" {
$result[0].ImageType | Should -Not -BeNullOrEmpty
$result[0].ImageType | Should -BeIn @("JRE", "JDK")
}

It "Returns an Architecture property" {
$result[0].Architecture | Should -Not -BeNullOrEmpty
$result[0].Architecture.Length | Should -BeGreaterThan 0
}

It "Returns a Type property" {
$result[0].Type | Should -Not -BeNullOrEmpty
$result[0].Type.Length | Should -BeGreaterThan 0
}

It "Returns a URI property" {
$result[0].URI | Should -Not -BeNullOrEmpty
$result[0].URI.Length | Should -BeGreaterThan 0
}
}

Context "It filters for the latest version correctly" {
BeforeAll {
# Mock resource object
$res = [PSCustomObject]@{
Get = [PSCustomObject]@{
Update = [PSCustomObject]@{
Uri = "https://api.azul.com/metadata/v1/zulu/packages/?java_version=25&os=windows&archive_type=msi&crac_supported=false&latest=true&release_status=ga&availability_types=CA&certifications=tck&page=1&page_size=100"
ContentType = "application/json"
}
}
}
$result = Get-AzulZulu -res $res
}

It "Returns only the latest version" {
$versions = $result.Version | Select-Object -Unique
$versions.Count | Should -Be 1
}

It "All results have the same version number" {
$uniqueVersions = $result | Select-Object -ExpandProperty Version -Unique
$uniqueVersions.Count | Should -Be 1
}
}
}
}