diff --git a/src/private/Commands/Initialize-RunnerEnvironment.ps1 b/src/private/Commands/Initialize-RunnerEnvironment.ps1 index 67e02bae..a384fd55 100644 --- a/src/private/Commands/Initialize-RunnerEnvironment.ps1 +++ b/src/private/Commands/Initialize-RunnerEnvironment.ps1 @@ -19,7 +19,8 @@ Set-GitHubEnv -Name 'GITHUB_REPOSITORY_NAME' -Value $env:GITHUB_REPOSITORY_NAME # Autologon if a token is present in environment variables - $tokenVar = Get-ChildItem -Path 'Env:' | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 + Write-Verbose (Get-ChildItem -Path 'Env:' | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Out-String) + $tokenVar = Get-ChildItem -Path 'Env:' | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 -ExpandProperty Value $tokenVarPresent = $tokenVar.count -gt 0 -and -not [string]::IsNullOrEmpty($tokenVar) if ($tokenVarPresent) { Connect-GitHubAccount -Repo $env:GITHUB_REPOSITORY_NAME -Owner $env:GITHUB_REPOSITORY_OWNER diff --git a/src/public/Auth/Connect-GitHubAccount.ps1 b/src/public/Auth/Connect-GitHubAccount.ps1 index 7a2a3d59..5c448f92 100644 --- a/src/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/public/Auth/Connect-GitHubAccount.ps1 @@ -98,7 +98,7 @@ $envVars = Get-ChildItem -Path 'Env:' Write-Debug 'Environment variables:' Write-Debug ($envVars | Format-Table -AutoSize | Out-String) - $gitHubToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 + $gitHubToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 -ExpandProperty Value Write-Debug "GitHub token: [$gitHubToken]" $gitHubTokenPresent = $gitHubToken.count -gt 0 -and -not [string]::IsNullOrEmpty($gitHubToken) Write-Debug "GitHub token present: [$gitHubTokenPresent]" @@ -202,9 +202,9 @@ 'sPAT' { Write-Verbose 'Logging in using GitHub access token...' Reset-GitHubConfig -Scope 'Auth' - $prefix = $gitHubToken.Value -replace '_.*$', '_*' + $prefix = $gitHubToken -replace '_.*$', '_*' $settings = @{ - AccessToken = ConvertTo-SecureString -AsPlainText $gitHubToken.Value + AccessToken = ConvertTo-SecureString -AsPlainText $gitHubToken AccessTokenType = $prefix ApiBaseUri = 'https://api.github.com' ApiVersion = '2022-11-28'