Skip to content

Refresh GitHub App installation token before pushing to azure-sdk-for-net#10737

Merged
jorgerangel-msft merged 6 commits into
mainfrom
copilot/fix-auth-issue-for-git-push
May 20, 2026
Merged

Refresh GitHub App installation token before pushing to azure-sdk-for-net#10737
jorgerangel-msft merged 6 commits into
mainfrom
copilot/fix-auth-issue-for-git-push

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

Submit-AzureSdkForNetPr.ps1 fails at git push with Invalid 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: the CreatePR job mints a GitHub App installation token once up front, then Submit-AzureSdkForNetPr.ps1 regenerates 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 before git push, invoke eng/common/scripts/login-to-github.ps1 to 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 the login-to-github.yml template at publish.yml#L221 (-InstallationTokenOwners 'Azure' -VariableNamePrefix 'GH_TOKEN'). Existence of the refreshed token is checked via Test-Path Env:GH_TOKEN to avoid dereferencing the value. Falls back to the original $AuthToken with 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 runs Submit-AzureSdkForNetPr.ps1 from PowerShell@2 to AzureCLI@2 (with azureSubscription: "AzureSDKEngKeyVault Secrets", the same subscription login-to-github.yml uses). The az CLI auth from the upstream AzureCLI@2-based login-to-github.yml step does not persist into the next task, so the in-script call to login-to-github.ps1 previously failed to sign the JWT with Key Vault (ERROR: Please run 'az login' to setup account.). Running the script under AzureCLI@2 gives it the az auth context it needs to mint a fresh installation token mid-run.

$loginScript = Join-Path $PSScriptRoot "../../../../eng/common/scripts/login-to-github.ps1"
if (Test-Path $loginScript) {
    try {
        & $loginScript -InstallationTokenOwners 'Azure' -VariableNamePrefix 'GH_TOKEN'
        if ($LASTEXITCODE -eq 0 -and (Test-Path Env:GH_TOKEN)) {
            $AuthToken = $env:GH_TOKEN
        }
    } catch {
        Write-Warning "Failed to refresh token: $($_.Exception.Message). Falling back."
    }
}

$remoteUrl = "******github.com/$RepoOwner/$RepoName.git"
git push $remoteUrl $PRBranch

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>
Copilot AI changed the title [WIP] Fix authentication issue causing git push failure Refresh GitHub App installation token before pushing to azure-sdk-for-net May 19, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp labels May 19, 2026
Copilot AI requested a review from jorgerangel-msft May 19, 2026 20:03
Comment thread packages/http-client-csharp/eng/scripts/Submit-AzureSdkForNetPr.ps1 Outdated
Comment thread packages/http-client-csharp/eng/scripts/Submit-AzureSdkForNetPr.ps1
Comment thread packages/http-client-csharp/eng/scripts/Submit-AzureSdkForNetPr.ps1 Outdated
Comment thread packages/http-client-csharp/eng/scripts/Submit-AzureSdkForNetPr.ps1
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>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10737

commit: c233721

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>
Comment thread packages/http-client-csharp/eng/scripts/Submit-AzureSdkForNetPr.ps1
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>
Comment thread packages/http-client-csharp/eng/pipeline/publish.yml Outdated
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>
Comment thread packages/http-client-csharp/eng/scripts/Submit-AzureSdkForNetPr.ps1
Copy link
Copy Markdown
Member

@jsquire jsquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per offline conversation, this runs in a trusted DevOps environment and only on merge commits to main - which would have already passed team review and been evaluated for malicious intent. No concerns.

@jorgerangel-msft jorgerangel-msft added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit 5ee6fff May 20, 2026
29 checks passed
@jorgerangel-msft jorgerangel-msft deleted the copilot/fix-auth-issue-for-git-push branch May 20, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regen Preview Pipeline is Failing To Create PR in the .NET Repo

4 participants