Skip to content

Commit

Permalink
Add GitHub workflow build artifacts url resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenesvk committed Jan 13, 2023
1 parent f930280 commit b63c9e5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,31 @@ function handle_special_urls($url)
}
}

# Github.com build artifacts
if ($url -match 'api.github.com/repos/(?<owner>[^/]+)/(?<repo>[^/]+)/actions/artifacts/(?<artifact_id>[\d]+)/zip') {
if ($token = Get-GitHubToken) {
$headers = @{
"Accept" = "application/vnd.github+json"
"Authorization" = "Bearer $($token)"
"X-GitHub-Api-Version" = "2022-11-28"
}
$assetUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)/actions/artifacts/$($Matches.artifact_id)/zip"

$response = Invoke-WebRequest -Method 'Get' -Uri $assetUrl -Headers $headers -MaximumRedirection 0 2>$null #-SkipHttpErrorCheck # (since v7)
$status = $response.StatusCode
if ($status -eq 302) {
$url = $response.Headers.Location
}
# switch ↑ to ↓ when min PowerShell is 7
# Invoke-RestMethod -Method 'Get' -Uri $assetUrl -Headers $headers -MaximumRedirection 0 -ResponseHeadersVariable rHeader -SkipHttpErrorCheck -StatusCodeVariable rStatus #2>$null
# if ($rStatus -eq 302) {
# $url = $rHeader.Location
# }
} else {
warn ("↓ url needs GitHub API token to be set via 'scoop config gh_token `"<YOUR_GH_TOKEN>`"`n", $url)
}
}

return $url
}

Expand Down

0 comments on commit b63c9e5

Please sign in to comment.