@@ -105,6 +105,39 @@ function isNewVersion(
105
105
return $true
106
106
}
107
107
108
+ function Get-GitHubApiHeaders {
109
+ # Use GitHub cli to get an auth token if available
110
+ $token = " "
111
+ if (Get-Command gh - ErrorAction SilentlyContinue) {
112
+ try
113
+ {
114
+ $token = gh auth token 2> $null
115
+ }
116
+ catch
117
+ {
118
+ Write-Host " Failed to get GitHub CLI auth token."
119
+ }
120
+ }
121
+
122
+ # Get token from env if not available from gh cli
123
+ if (! $token )
124
+ {
125
+ Write-Host " Checking for GITHUB_TOKEN environment variable."
126
+ $token = $env: GITHUB_TOKEN
127
+ }
128
+
129
+ if ($token )
130
+ {
131
+ Write-Host " Using authenticated GitHub API requests."
132
+ $headers = @ {
133
+ Authorization = " Bearer $token "
134
+ }
135
+ return $headers
136
+ }
137
+ Write-Host " Using unauthenticated GitHub API requests."
138
+ return @ {}
139
+ }
140
+
108
141
<#
109
142
. SYNOPSIS
110
143
Installs a standalone version of an engsys tool.
@@ -135,11 +168,12 @@ function Install-Standalone-Tool (
135
168
}
136
169
137
170
$tag = " ${Package} _${Version} "
171
+ $headers = Get-GitHubApiHeaders
138
172
139
173
if (! $Version -or $Version -eq " *" ) {
140
174
Write-Host " Attempting to find latest version for package '$Package '"
141
175
$releasesUrl = " https://api.github.com/repos/$Repository /releases"
142
- $releases = Invoke-RestMethod - Uri $releasesUrl
176
+ $releases = Invoke-RestMethod - Uri $releasesUrl - Headers $headers
143
177
$found = $false
144
178
foreach ($release in $releases ) {
145
179
if ($release.tag_name -like " $Package *" ) {
@@ -163,7 +197,7 @@ function Install-Standalone-Tool (
163
197
164
198
if (isNewVersion $version $downloadFolder ) {
165
199
Write-Host " Installing '$Package ' '$Version ' to '$downloadFolder ' from $downloadUrl "
166
- Invoke-WebRequest - Uri $downloadUrl - OutFile $downloadLocation
200
+ Invoke-WebRequest - Uri $downloadUrl - OutFile $downloadLocation - Headers $headers
167
201
168
202
if ($downloadFile -like " *.zip" ) {
169
203
Expand-Archive - Path $downloadLocation - DestinationPath $downloadFolder - Force
0 commit comments