44#
55
66[System.Net.WebClient ]$webClient = New-Object System.Net.WebClient
7- $webClient.UseDefaultCredentials = $true
87
98function DownloadVsixFile ($fileUrl , $downloadFileName )
109{
@@ -19,7 +18,8 @@ $tempDir = $env:RUNNER_TEMP
1918# Get latest releases of nanoFramework VS extension
2019[System.Net.WebClient ]$webClient = New-Object System.Net.WebClient
2120$webClient.Headers.Add (" User-Agent" , " request" )
22- $webClient.Headers.Add (" Accept" , " application/vnd.github.v3+json" )
21+ $webClient.Headers.Add (" Accept" , " application/vnd.github+json" )
22+ $webClient.Headers.Add (" X-GitHub-Api-Version" , " 2022-11-28" )
2323$webClient.Headers.Add (" ContentType" , " application/json" )
2424
2525if ($env: GITHUB_AUTH_TOKEN )
@@ -32,7 +32,38 @@ if($env:GITHUB_AUTH_TOKEN)
3232 $webClient.Headers.Add (" Authorization" , $auth )
3333}
3434
35- $releaseList = $webClient.DownloadString (' https://api.github.com/repos/nanoframework/nf-Visual-Studio-extension/releases?per_page=100' )
35+ try
36+ {
37+ $releaseList = $webClient.DownloadString (' https://api.github.com/repos/nanoframework/nf-Visual-Studio-extension/releases?per_page=100' )
38+ }
39+ catch
40+ {
41+
42+ # assume exception is with try with GITHUB_TOKEN
43+ if ($env: GITHUB_TOKEN )
44+ {
45+ Write-Output " INFO: 2nd try using GITHUB TOKEN"
46+
47+ # authorization header with github token
48+ $auth = " Bearer $env: GITHUB_TOKEN "
49+
50+ $webClient.Headers.Remove (" Authorization" )
51+ $webClient.Headers.Add (" Authorization" , $auth )
52+
53+ $releaseList = $webClient.DownloadString (' https://api.github.com/repos/nanoframework/nf-Visual-Studio-extension/releases?per_page=100' )
54+ }
55+ else
56+ {
57+ $result = $_.Exception.Response.GetResponseStream ()
58+ $reader = New-Object System.IO.StreamReader($result )
59+ $reader.BaseStream.Position = 0
60+ $reader.DiscardBufferedData ()
61+ $responseBody = $reader.ReadToEnd ()
62+
63+ Write-Output " 🛑 performing request: $responseBody "
64+ exit 1
65+ }
66+ }
3667
3768if ($releaseList -match ' \"(?<VS2022_version>v2022\.\d+\.\d+\.\d+)\"' )
3869{
0 commit comments