DanGough / Nevergreen

This module is an alternative to Evergreen, and allows you to find the latest version and download URL for various Windows apps. Evergreen uses API queries to obtain its data whereas this module is more focussed on web scraping. This is more prone to breaking when websites are changed, hence the name.
The Unlicense
71 stars 16 forks source link

[New App Request] Docker Desktop (On Proposals List) #82

Open AScott-WWF opened 2 days ago

AScott-WWF commented 2 days ago

Script

# Get-DockerDesktop.ps1

# Define AppName
$AppName = "Docker Desktop"

# Main script to fetch and process links
$ReleaseUrl = "https://docs.docker.com/desktop/release-notes/"
$InstallInstructionsUrl = "https://docs.docker.com/desktop/install/windows-install/"

Write-Verbose "Obtaining $($AppName) Release Versions from $($ReleaseUrl)...`n"

$AppVersions = @(
    @{Platform = 'Windows'; Type = 'exe'; Architecture = 'x64'; Pattern = '([^"]*amd64[^"]*\.exe)'; VersionPattern = 'href=#\d{4}>(\d+\.\d+\.\d+)'}
    @{Platform = 'Windows'; Type = 'exe'; Architecture = 'ARM64'; Pattern = '([^"]*arm64[^"]*\.exe)'; VersionPattern = 'href=#\d{4}>(\d+\.\d+\.\d+)'}
)

foreach ($AppVersion in $AppVersions) {
    $SearchCount = 1 # This may need increasing as future versions are released

    #Build each link with File Type specific versions
    $URL = Get-Link -Uri $ReleaseUrl -MatchProperty href -Pattern $($AppVersion.Pattern)
    $Version = Get-Version -Uri $ReleaseUrl -Pattern $($AppVersion.VersionPattern)

    $ReleaseNotesUrl = "https://docs.docker.com/desktop/release-notes/#$(($Version).replace('.',''))"

    do {
        if ($URL) {
            New-NevergreenApp -Name $($AppName) -Platform $($AppVersion.Platform) -Version $Version -Uri $URL -Architecture $($AppVersion.Architecture) -Type $($AppVersion.Type)
            break
        }

        $SearchCount--
    } until ($SearchCount -eq 0)

    if ($SearchCount -eq 0) {
        Write-Warning "Could not find release for $($AppName) $($AppVersion.Type)"
    }
}

Write-Verbose "$($AppName) (Version: $($Version)) Release notes are available here: $($ReleaseNotesUrl)"
Write-Verbose "$($AppName) Install instructions are available here: $($InstallInstructionsUrl)"