Files

64 lines
1.5 KiB
PowerShell
Raw Permalink Normal View History

2020-06-16 11:04:42 +03:00
param (
2021-10-13 15:56:14 +03:00
[Parameter(Mandatory)][string] $ManifestPath
2020-06-16 11:04:42 +03:00
)
2021-09-03 11:55:56 +03:00
$Global:validationFailed = $false
2020-06-16 11:04:42 +03:00
function Publish-Error {
param(
[string] $ErrorDescription,
[object] $Exception
)
2021-10-13 15:56:14 +03:00
Write-Output "::error ::$ErrorDescription"
2021-09-09 18:03:55 +03:00
if (-not [string]::IsNullOrEmpty($Exception))
2021-09-03 11:55:56 +03:00
{
Write-Output "Exception: $Exception"
}
$Global:validationFailed = $true
2020-06-16 11:04:42 +03:00
}
function Test-DownloadUrl {
2021-10-13 15:56:14 +03:00
param(
[string] $DownloadUrl
)
2020-06-16 11:04:42 +03:00
$request = [System.Net.WebRequest]::Create($DownloadUrl)
try {
$response = $request.GetResponse()
return ([int]$response.StatusCode -eq 200)
} catch {
return $false
}
}
if (-not (Test-Path $ManifestPath)) {
Publish-Error "Unable to find manifest json file at '$ManifestPath'"
2020-06-16 11:04:42 +03:00
exit 1
}
Write-Host "Parsing manifest json content from '$ManifestPath'..."
2020-06-16 11:04:42 +03:00
try {
$manifestJson = Get-Content $ManifestPath | ConvertFrom-Json
2020-06-16 11:04:42 +03:00
} catch {
Publish-Error "Unable to parse manifest json content '$ManifestPath'" $_
2020-06-16 11:04:42 +03:00
exit 1
}
$versionsList = $manifestJson.version
Write-Host "Found versions: $($versionsList -join ', ')"
$manifestJson | ForEach-Object {
Write-Host "Validating version '$($_.version)'..."
$_.files | ForEach-Object {
Write-Host " Validating '$($_.download_url)'..."
if (-not (Test-DownloadUrl $_.download_url)) {
Publish-Error "Url '$($_.download_url)' is invalid"
}
}
}
2021-09-03 11:55:56 +03:00
2021-09-09 18:03:55 +03:00
if ($Global:validationFailed) {
2021-09-03 11:55:56 +03:00
exit 1
}