Skip to content

Commit cda1a39

Browse files
committed
Add parameter to install preview build
- Replace web client with Invoke-WebRequest. - Add code to process request of preview version. - Minor improvements in code downloading from github release. - Update readme.
1 parent 4fd029f commit cda1a39

File tree

3 files changed

+120
-43
lines changed

3 files changed

+120
-43
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ Request to GitHub API to retrieve the version information can be authenticated b
2828
GITHUB_AUTH_TOKEN: ${{ secrets.githubAuth }}
2929
```
3030

31+
### Installing preview version
32+
33+
An optional parameter `usePreview` (boolean) set through an environment variable sets the usage of preview version of the VS extension downloaded from the Open VSIX gallery.
34+
Like this:
35+
36+
```yaml
37+
- uses: nanoframework/nanobuild@v1
38+
env:
39+
USE_PREVIEW: true
40+
```
41+
42+
43+
3144
## Feedback and documentation
3245

3346
For documentation, providing feedback, issues and finding out how to contribute please refer to the [Home repo](https://github.com/nanoframework/Home).

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ inputs:
1414
required: false
1515
description: 'GitHub Personal Access Token for accessing GitHub API.'
1616
default: ''
17+
usePreview:
18+
required: false
19+
description: 'Use preview version of the VS extension downloaded from the Open VSIX gallery'
20+
default: false

install-nf-build-components.ps1

Lines changed: 103 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,126 @@
33
# See LICENSE file in the project root for full license information.
44
#
55

6-
[System.Net.WebClient]$webClient = New-Object System.Net.WebClient
7-
86
function DownloadVsixFile($fileUrl, $downloadFileName)
97
{
10-
# Write-Host "Download VSIX file from $fileUrl to $downloadFileName"
11-
$webClient.DownloadFile($fileUrl,$downloadFileName)
8+
Write-Debug "Download VSIX file from $fileUrl to $downloadFileName"
9+
Invoke-WebRequest -Uri $fileUrl -OutFile $downloadFileName
1210
}
1311

1412
"INFO: Downloading extension details" | Write-Host
1513

14+
[bool]$isPreview = $env:USE_PREVIEW
1615
$tempDir = $env:RUNNER_TEMP
1716

18-
# Get latest releases of nanoFramework VS extension
19-
[System.Net.WebClient]$webClient = New-Object System.Net.WebClient
20-
$webClient.Headers.Add("User-Agent", "nanobuild")
21-
$webClient.Headers.Add("Accept", "application/vnd.github+json")
22-
$webClient.Headers.Add("X-GitHub-Api-Version", "2022-11-28")
23-
$webClient.Headers.Add("ContentType", "application/json")
24-
25-
if($env:GITHUB_AUTH_TOKEN)
26-
{
27-
Write-Output "INFO: adding authentication header"
28-
29-
# authorization header with github token
30-
$auth = "Bearer $env:GITHUB_AUTH_TOKEN"
31-
32-
$webClient.Headers.Add("Authorization", $auth)
33-
}
34-
35-
$releaseList = $webClient.DownloadString('https://api.github.com/repos/nanoframework/nf-Visual-Studio-extension/releases?per_page=100')
36-
37-
if($releaseList -match '\"(?<VS2022_version>v2022\.\d+\.\d+\.\d+)\"')
38-
{
39-
$vs2022Tag = $Matches.VS2022_version
40-
}
41-
42-
if($releaseList -match '\"(?<VS2019_version>v2019\.\d+\.\d+\.\d+)\"')
43-
{
44-
$vs2019Tag = $Matches.VS2019_version
45-
}
46-
4717
# Find which VS version is installed
4818
$VsWherePath = "${env:PROGRAMFILES(X86)}\Microsoft Visual Studio\Installer\vswhere.exe"
4919

20+
"INFO: VsWherePath is: $VsWherePath" | Write-Host
21+
5022
$VsInstance = $(&$VSWherePath -latest -property displayName)
5123

52-
Write-Output "INFO: Latest VS is: $VsInstance"
24+
"INFO: VS is: $VsInstance" | Write-Host
5325

54-
# Get extension details according to VS version, starting from VS2022 down to VS2019
55-
if($vsInstance.Contains('2022'))
26+
# handle preview version
27+
if($isPreview -eq $true)
5628
{
57-
$extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2022Tag/nanoFramework.Tools.VS2022.Extension.vsix"
58-
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2022.Extension.zip"
59-
$extensionVersion = $vs2022Tag
29+
Write-Host "*** Installing preview version of the extension ***"
30+
31+
# get extension information from Open VSIX Gallery feed
32+
$vsixFeedXml = Join-Path $($tempDir) "vs-extension-feed.xml"
33+
Invoke-WebRequest -Uri "https://www.vsixgallery.com/feed/author/nanoframework" -OutFile $vsixFeedXml
34+
[xml]$feedDetails = Get-Content $vsixFeedXml
35+
36+
# Define the extension IDs
37+
$vs2019Id = "455f2be5-bb07-451e-b351-a9faf3018dc9"
38+
$vs2022Id = "bf694e17-fa5f-4877-9317-6d3664b2689a"
39+
40+
# feed list VS2019 and VS2022 extensions using the extension ID
41+
42+
# VS2022
43+
if($vsInstance.Contains('2022'))
44+
{
45+
$vs2022Entry = $feedDetails.feed.entry | Where-Object { $_.Vsix.Id -eq $vs2022Id }
46+
47+
if($vs2022Entry)
48+
{
49+
$extensionUrl = $vs2022Entry.content.src
50+
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2022.Extension.zip"
51+
$extensionVersion = $vs2022Entry.Vsix.Version
52+
}
53+
else
54+
{
55+
Write-Host "ERROR: VS2022 extension with ID $vs2022Id not found."
56+
}
57+
}
58+
elseif($vsInstance.Contains('2019'))
59+
{
60+
$vs2019Entry = $feedDetails.feed.entry | Where-Object { $_.Vsix.Id -eq $vs2019Id }
61+
62+
if($vs2019Entry)
63+
{
64+
$extensionUrl = $vs2019Entry.content.src
65+
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2019.Extension.zip"
66+
$extensionVersion = $vs2019Entry.Vsix.Version
67+
}
68+
else
69+
{
70+
Write-Host "ERROR: VS2019 extension with ID $vs2019Id not found."
71+
}
72+
}
6073
}
61-
elseif($vsInstance.Contains('2019'))
74+
else
6275
{
63-
$extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2019Tag/nanoFramework.Tools.VS2019.Extension.vsix"
64-
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2019.Extension.zip"
65-
$extensionVersion = $vs2019Tag
76+
# Build headers for the request
77+
$headers = @{
78+
"User-Agent" = "request"
79+
"Accept" = "application/vnd.github.v3+json"
80+
"ContentType" = "application/json"
81+
}
82+
83+
if($gitHubToken)
84+
{
85+
Write-Host "INFO: Adding authentication header"
86+
$headers["Authorization"] = "Bearer $gitHubToken"
87+
}
88+
89+
Write-Host "INFO: Get latest releases of nanoFramework VS extension from GitHub"
90+
91+
# Use Invoke-WebRequest to get the release JSON
92+
$response = Invoke-WebRequest -Uri 'https://api.github.com/repos/nanoframework/nf-Visual-Studio-extension/releases?per_page=10' -Headers $headers
93+
94+
# Convert the response content to JSON objects
95+
$releases = $response.Content | ConvertFrom-Json
96+
97+
# Filter out draft releases
98+
$finalReleases = $releases | Where-Object { -not $_.draft }
99+
100+
# Extract tags using the tag_name property
101+
$vs2022Release = $finalReleases | Where-Object { $_.tag_name -match '^v2022\.\d+\.\d+\.\d+$' } | Select-Object -First 1
102+
if($vs2022Release)
103+
{
104+
$vs2022Tag = $vs2022Release.tag_name
105+
}
106+
107+
$vs2019Release = $finalReleases | Where-Object { $_.tag_name -match '^v2019\.\d+\.\d+\.\d+$' } | Select-Object -First 1
108+
if($vs2019Release)
109+
{
110+
$vs2019Tag = $vs2019Release.tag_name
111+
}
112+
113+
# Get extension details according to VS version, starting from VS2022 down to VS2019
114+
if($vsInstance.Contains('2022'))
115+
{
116+
$extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2022Tag/nanoFramework.Tools.VS2022.Extension.vsix"
117+
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2022.Extension.zip"
118+
$extensionVersion = $vs2022Tag
119+
}
120+
elseif($vsInstance.Contains('2019'))
121+
{
122+
$extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2019Tag/nanoFramework.Tools.VS2019.Extension.vsix"
123+
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2019.Extension.zip"
124+
$extensionVersion = $vs2019Tag
125+
}
66126
}
67127

68128
# Download VS extension

0 commit comments

Comments
 (0)