Commit 5ee6fff
Refresh GitHub App installation token before pushing to azure-sdk-for-net (#10737)
`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.
```powershell
$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
```
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>1 parent 086b60e commit 5ee6fff
2 files changed
Lines changed: 23 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | | - | |
| 226 | + | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
230 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
231 | 233 | | |
232 | 234 | | |
233 | 235 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
689 | 689 | | |
690 | 690 | | |
691 | 691 | | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
692 | 710 | | |
693 | 711 | | |
694 | 712 | | |
| |||
0 commit comments