Skip to content

Commit

Permalink
Merge pull request #9 from theohbrothers/enhancement/bump-generate-do…
Browse files Browse the repository at this point in the history
…wnloadbinary-function-to-0.1.0

Enhancement: Bump `Generate-DownloadBinary` function to 0.1.0
  • Loading branch information
leojonathanoh authored Dec 1, 2023
2 parents b654d9e + 22ccdff commit 1834b9b
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions generate/functions/Generate-DownloadBinary.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Version 0.1.0
function Generate-DownloadBinary ($o) {
Set-StrictMode -Version Latest

$checksumsKey = "$( $o['binary'] )-$( $o['version'] )"
$files = [ordered]@{}
if ($o['checksumsUrl']) {
Set-Checksums "$( $o['binary'] )-$( $o['version'] )" $o['checksumsUrl']
Set-Checksums $checksumsKey $o['checksumsUrl']
}else {
$release = Invoke-RestMethod "https://api.github.com/repos/$( $o['repository'] )/releases/tags/$( $o['version'] )"
$releaseAssetsFiles = $release.assets | ? { $_.name -match [regex]::Escape($o['binary']) -and $_.name -notmatch '\.sha\d+$' }
$files = [ordered]@{}
foreach ($f in $releaseAssetsFiles ) {
$sha = & {
$shaF = $release.assets | ? { $_.name -eq "$( $f.name ).sha256" -or $_ -eq "$( $f.name ).sha512" }
Expand Down Expand Up @@ -71,14 +73,21 @@ RUN set -eux; \
}
}

$file = $files.Keys | ? { $_ -match $regex } | Select-Object -First 1
if ($file) {
$url = if ($o['checksumsUrl']) {
Split-Path $o['checksumsUrl'] -Parent
$file = $sha = $url = ''
if ($o['checksumsUrl']) {
$file = Get-ChecksumsFile $checksumsKey $regex
$sha = Get-ChecksumsSha $checksumsKey $regex
$url = Split-Path $o['checksumsUrl'] -Parent
} else {
$file = $files.Keys | ? { $_ -match $regex } | Select-Object -First 1
if ($file) {
$url = "https://github.com/$( $o['repository'] )/releases/download/$( $o['version'] )"
$sha = $files[$file]
}else {
"https://github.com/$( $o['repository'] )/releases/download/$( $o['version'] )"
throw "No file matched regex: $regex"
}
$sha = $files[$file]
}
if ($file -and $sha) {
@"
'$hardware') \
URL="$url/$file"; \
Expand Down

0 comments on commit 1834b9b

Please sign in to comment.