mirror of
https://github.com/actions/versions-package-tools.git
synced 2025-12-10 03:13:23 +00:00
Merge pull request #39 from nikolai-frolov/change-manifest-download
Change way for versions-manifest.json gathering for Validate manifest workflow runs
This commit is contained in:
@@ -1,14 +1,9 @@
|
|||||||
param (
|
param (
|
||||||
[Parameter(Mandatory)][string] $ManifestUrl,
|
[Parameter(Mandatory)][string] $ManifestPath,
|
||||||
[string] $AccessToken
|
[string] $AccessToken
|
||||||
)
|
)
|
||||||
|
|
||||||
$Global:validationFailed = $false
|
$Global:validationFailed = $false
|
||||||
$authorizationHeaderValue = "Basic $AccessToken"
|
|
||||||
$webRequestHeaders = @{}
|
|
||||||
if ($AccessToken) {
|
|
||||||
$webRequestHeaders.Add("Authorization", $authorizationHeaderValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Publish-Error {
|
function Publish-Error {
|
||||||
param(
|
param(
|
||||||
@@ -16,7 +11,7 @@ function Publish-Error {
|
|||||||
[object] $Exception
|
[object] $Exception
|
||||||
)
|
)
|
||||||
|
|
||||||
echo "::error ::$ErrorDescription"
|
Write-Output "::error ::$ErrorDescription"
|
||||||
if (-not [string]::IsNullOrEmpty($Exception))
|
if (-not [string]::IsNullOrEmpty($Exception))
|
||||||
{
|
{
|
||||||
Write-Output "Exception: $Exception"
|
Write-Output "Exception: $Exception"
|
||||||
@@ -25,9 +20,10 @@ function Publish-Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Test-DownloadUrl {
|
function Test-DownloadUrl {
|
||||||
param([string] $DownloadUrl)
|
param([string] $DownloadUrl)
|
||||||
$request = [System.Net.WebRequest]::Create($DownloadUrl)
|
$request = [System.Net.WebRequest]::Create($DownloadUrl)
|
||||||
if ($AccessToken) {
|
if ($AccessToken) {
|
||||||
|
$authorizationHeaderValue = "Basic $AccessToken"
|
||||||
$request.Headers.Add("Authorization", $authorizationHeaderValue)
|
$request.Headers.Add("Authorization", $authorizationHeaderValue)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -38,19 +34,16 @@ function Test-DownloadUrl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Downloading manifest json from '$ManifestUrl'..."
|
if (-not (Test-Path $ManifestPath)) {
|
||||||
try {
|
Publish-Error "Unable to find manifest json file at '$ManifestPath'"
|
||||||
$manifestResponse = Invoke-WebRequest -Method Get -Uri $ManifestUrl -Headers $webRequestHeaders -MaximumRetryCount 5 -RetryIntervalSec 10
|
|
||||||
} catch {
|
|
||||||
Publish-Error "Unable to download manifest json from '$ManifestUrl'" $_
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Parsing manifest json content from '$ManifestUrl'..."
|
Write-Host "Parsing manifest json content from '$ManifestPath'..."
|
||||||
try {
|
try {
|
||||||
$manifestJson = $manifestResponse.Content | ConvertFrom-Json
|
$manifestJson = Get-Content $ManifestPath | ConvertFrom-Json
|
||||||
} catch {
|
} catch {
|
||||||
Publish-Error "Unable to parse manifest json content '$ManifestUrl'" $_
|
Publish-Error "Unable to parse manifest json content '$ManifestPath'" $_
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user