Skip to content

Commit 1b8263e

Browse files
committed
Authenticate copilot-setup-steps too
1 parent b050e25 commit 1b8263e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎.github/workflows/copilot-setup-steps.yml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,44 @@ jobs:
2222
permissions:
2323
# If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete.
2424
contents: read
25+
id-token: write
2526

2627
# You can define any steps you want, and they will run before the agent starts.
2728
# If you do not check out your code, Copilot will do this for you.
2829
steps:
2930
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3031
with:
3132
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
33+
- name: Authenticate to Azure with GitHub OIDC
34+
id: azure-login
35+
# This tenant requires enterprise-issued assertions. Other owners restore anonymously.
36+
# Same-repository dependency update PRs authenticate; fork PRs do not.
37+
if: github.repository_owner == 'microsoft' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
38+
uses: azure/login@a641126d1b8aa4d1fa005f4f92df94a3a4c4c906 # v3.1.0
39+
with:
40+
client-id: 2799af29-63f3-404f-bdcf-67ff9c70abc9
41+
tenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47
42+
allow-no-subscriptions: true
43+
audience: api://AzureADTokenExchange
44+
- name: Configure Azure Artifacts credentials
45+
if: steps.azure-login.outcome == 'success'
46+
shell: pwsh
47+
run: |
48+
$accessToken = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken --output tsv
49+
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($accessToken)) {
50+
throw 'Failed to acquire an Azure DevOps access token.'
51+
}
52+
Write-Output "::add-mask::$accessToken"
53+
$nugetConfig = [xml](Get-Content -LiteralPath nuget.config -Raw)
54+
$sources = @($nugetConfig.configuration.packageSources.add | Where-Object {
55+
$_.value -match '^https://pkgs\.dev\.azure\.com/' -or $_.value -match '^https://[\w-]+\.pkgs\.visualstudio\.com/'
56+
})
57+
if ($sources.Count -eq 0) {
58+
throw 'No Azure Artifacts package sources were found in nuget.config.'
59+
}
60+
foreach ($source in $sources) {
61+
Add-Content -LiteralPath $env:GITHUB_ENV -Encoding utf8 -Value "NuGetPackageSourceCredentials_$($source.key)=Username=ado;Password=$accessToken;ValidAuthenticationTypes=Basic"
62+
}
3263
- name: ⚙ Install prerequisites
3364
run: |
3465
./init.ps1 -UpgradePrerequisites -NoNuGetCredProvider

0 commit comments

Comments
 (0)