Skip to content

Commit 92f322f

Browse files
committed
CI: use GITHUB_TOKEN to access GitHub APIs
1 parent ab5f717 commit 92f322f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.github/workflows/dependencies.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ jobs:
5050
- id: update
5151
name: "Update the dependency versions"
5252
shell: pwsh
53-
run: ./src/scripts/Update-Dependencies.ps1
53+
run: ./src/scripts/Update-Dependencies.ps1 -AuthToken $env:GITHUB_TOKEN
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5456

5557
- if: steps.update.outputs.has-changes == 'true' && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
5658
name: "Create a PR"

src/scripts/Update-Dependencies.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#>
55
param (
66
$SourceRoot = "$PSScriptRoot/../..",
7-
$GradleProperties = "$SourceRoot/gradle.properties"
7+
$GradleProperties = "$SourceRoot/gradle.properties",
8+
[string] $AuthToken = $null
89
)
910

1011
Set-StrictMode -Version Latest
@@ -29,9 +30,18 @@ function ReadCurrentVersions
2930
}
3031
}
3132

33+
$requestHeaders = if ($AuthToken) {
34+
@{ 'Authorization' = "Bearer $AuthToken" }
35+
} else {
36+
$null
37+
}
38+
3239
$psScriptAnalyzer = Invoke-RestMethod `
33-
'https://api.github.com/repos/PowerShell/PSScriptAnalyzer/releases?per_page=1'
34-
$pses = Invoke-RestMethod 'https://api.github.com/repos/PowerShell/PowerShellEditorServices/releases?per_page=1'
40+
-Headers $requestHeaders `
41+
'https://api.github.com/repos/PowerShell/PSScriptAnalyzer/releases?per_page=1'
42+
$pses = Invoke-RestMethod `
43+
-Headers $requestHeaders `
44+
'https://api.github.com/repos/PowerShell/PowerShellEditorServices/releases?per_page=1'
3545

3646
function ReadLatestVersions
3747
{

0 commit comments

Comments
 (0)