Refresh GitHub App installation token before pushing to azure-sdk-for-net#10737
Refresh GitHub App installation token before pushing to azure-sdk-for-net#10737Copilot wants to merge 6 commits into
Conversation
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/976a4f83-a1bd-415f-be94-7cef61cd4f69 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/9410e129-7681-41bf-886a-3d9f44856866 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
commit: |
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/6d407921-0181-48ea-92a4-e092bb0a3e5a Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
| } | ||
|
|
||
| $loginScript = Join-Path $PSScriptRoot "../../../../eng/common/scripts/login-to-github.ps1" | ||
| if (Test-Path $loginScript) { |
There was a problem hiding this comment.
@copilot it looks like this is failing in CI on regeneration:
Refreshing GitHub App installation token before push...
Generating GitHub App JWT by signing via Azure Key Vault (no key export)...
ERROR: Please run 'az login' to setup account.
WARNING: Failed to refresh GitHub App installation token: Failed to sign JWT with Azure Key Vault. Error: . Falling back to existing token.
Pushing branch to remote...
remote: Invalid username or token. Password authentication is not supported for Git operations.
There was a problem hiding this comment.
Good catch — root cause is that az login context from the prior AzureCLI@2 task in login-to-github.yml does not persist into the next PowerShell@2 task. So when Submit-AzureSdkForNetPr.ps1 later invokes login-to-github.ps1 to mint a fresh token, the JWT-signing call to Key Vault fails with Please run 'az login'.
Fixed in 32061c1 by switching the script's task in publish.yml from PowerShell@2 to AzureCLI@2 (with azureSubscription: "AzureSDKEngKeyVault Secrets" — the same subscription login-to-github.yml uses). The script now runs inside an az-authenticated context, so the in-script login-to-github.ps1 call right before git push can sign the JWT and produce a fresh installation token.
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/9c22b003-fc98-43a7-9d71-358418d8c3ed Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/3afb1f37-38bd-4b31-90b1-d527752293ae Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Submit-AzureSdkForNetPr.ps1fails atgit pushwithInvalid username or token. Password authentication is not supported for Git operations.after regenerating Azure data-plane / mgmt libraries.#10710 fixed the URL scheme (
x-access-token:<token>) but didn't address token lifetime: theCreatePRjob mints a GitHub App installation token once up front, thenSubmit-AzureSdkForNetPr.ps1regenerates SDKs (118 files / 6353 insertions in the failing run) before pushing. Installation tokens expire after 1 hour, so the regen routinely outlives the token.Changes
Submit-AzureSdkForNetPr.ps1— Immediately beforegit push, invokeeng/common/scripts/login-to-github.ps1to mint a fresh installation token, then use it for both the push URL and (via$env:GH_TOKEN)gh pr create. The login script is invoked with the same params as thelogin-to-github.ymltemplate atpublish.yml#L221(-InstallationTokenOwners 'Azure' -VariableNamePrefix 'GH_TOKEN'). Existence of the refreshed token is checked viaTest-Path Env:GH_TOKENto avoid dereferencing the value. Falls back to the original$AuthTokenwith a warning when the login script is unavailable or fails (e.g., local/manual runs with a classic PAT).packages/http-client-csharp/eng/pipeline/publish.yml— Switch the step that runsSubmit-AzureSdkForNetPr.ps1fromPowerShell@2toAzureCLI@2(withazureSubscription: "AzureSDKEngKeyVault Secrets", the same subscriptionlogin-to-github.ymluses). TheazCLI auth from the upstreamAzureCLI@2-basedlogin-to-github.ymlstep does not persist into the next task, so the in-script call tologin-to-github.ps1previously failed to sign the JWT with Key Vault (ERROR: Please run 'az login' to setup account.). Running the script underAzureCLI@2gives it theazauth context it needs to mint a fresh installation token mid-run.