Skip to content

Commit

Permalink
(ghostscript) Updates Update.ps1 with Get-GitHubRelease
Browse files Browse the repository at this point in the history
Updates to use the GitHub REST API for releases.
This adds to #2007.
  • Loading branch information
JPRuskin committed Dec 16, 2022
1 parent dd36111 commit a8f92bd
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions automatic/ghostscript/update.ps1
@@ -1,7 +1,5 @@
Import-Module AU

$releases = 'https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/latest'

function global:au_SearchReplace {
[version]$version = $Latest.RemoteVersion
$docsUrl = "http://www.ghostscript.com/doc/$($version)/Readme.htm"
Expand All @@ -15,30 +13,25 @@ function global:au_SearchReplace {
}
}
function global:au_GetLatest {
$download_page = Invoke-WebRequest -Uri $releases -UseBasicParsing

# Linux version uses the correct version as we expect, so we use that
# version as the base.

$linuxTarbal = $download_page.Links | ? href -match 'ghostscript-.*.tar.gz' | select -First 1 -ExpandProperty href

$version = $linuxTarbal -split '-|\.tar' | select -Last 1 -Skip 1
$LatestRelease = Get-GitHubRelease ArtifexSoftware ghostpdl-downloads

$re = "gs$($version -replace '\.')w32\.exe$"
$url32 = $download_page.Links | ? href -match $re | % { [uri]::new($download_page.BaseResponse.ResponseUri, $_.href) } | select -first 1
$Url32 = $LatestRelease.assets | Where-Object {$_.name -eq "$($LatestRelease.tag_name)w32.exe"} | Select-Object -ExpandProperty browser_download_url
$Url64 = $LatestRelease.assets | Where-Object {$_.name -eq "$($LatestRelease.tag_name)w64.exe"} | Select-Object -ExpandProperty browser_download_url

$re = "gs$($version -replace '\.')w64\.exe$"
$url64 = $download_page.links | ? href -match $re | % { [uri]::new($download_page.BaseResponse.ResponseUri, $_.href) } | select -first 1
# Linux version easily exposes the correct version as we expect so we use
# that version as the base. Could use release name, but doesn't match pre-release.
$LinuxRelease = $LatestRelease.assets | Where-Object {$_.name -match "ghostscript-.+\.tar\.gz"} | Select-Object -ExpandProperty name
$Version = $LinuxRelease -replace "^ghostscript-(?<Version>.+)\.tar\.gz$", '${Version}'

if (!$url32 -or !$url64) {
if (!$Url32 -or !$Url64) {
throw "Either 32bit or 64bit URL is missing, please verify this is correct!"
}

@{
URL32 = $url32
URL64 = $url64
Version = $version
RemoteVersion = $version
URL32 = $Url32
URL64 = $Url64
Version = $Version
RemoteVersion = $Version
PackageName = 'Ghostscript'
}
}
Expand Down

0 comments on commit a8f92bd

Please sign in to comment.