Skip to content

Commit cedd268

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
default to CFS, add -useCratesIO to override, move into build.ps1
1 parent 897844a commit cedd268

File tree

2 files changed

+23
-89
lines changed

2 files changed

+23
-89
lines changed

.pipelines/DSC-Official.yml

Lines changed: 4 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: DSC-Release-$(Build.BuildId)
22
trigger: none
33

4-
parameters:
5-
- name: token
6-
displayName: Token to use for CFS
7-
type: string
8-
default: 'none'
9-
104
pr:
115
branches:
126
include:
@@ -122,38 +116,9 @@ extends:
122116
displayName: Install Rust
123117
env:
124118
ob_restore_phase: true
125-
- ${{ if eq(parameters.token, 'none') }}:
126-
- task: AzureCLI@2
127-
inputs:
128-
azureSubscription: az-PowerShell-feed-ingestion
129-
scriptType: 'pscore'
130-
scriptLocation: 'inlineScript'
131-
inlineScript: |
132-
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
133-
134-
# Set the access token as a secret, so it doesn't get leaked in the logs
135-
Write-Host "##vso[task.setsecret]$accessToken"
136-
$header = "Bearer $accessToken"
137-
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
138-
displayName: 'Get Azure DevOps Token'
139-
env:
140-
ob_restore_phase: true
141-
- ${{ if ne(parameters.token, 'none') }}:
142-
- task: PowerShell@2
143-
inputs:
144-
targetType: 'inline'
145-
pwsh: true
146-
script: |
147-
$header = "Bearer $($env:TOKEN)"
148-
Write-Host $env:TOKEN.Length
149-
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
150-
displayName: 'Set CARGO_REGISTRIES_POWERSHELL_TOKEN'
151-
env:
152-
TOKEN: ${{ parameters.token }}
153-
ob_restore_phase: true
154119
- pwsh: |
155120
Set-Location "$(Build.SourcesDirectory)/DSC"
156-
./build.ps1 -Release -Architecture $(buildName) -SkipLinkCheck -UseCFS
121+
./build.ps1 -Release -Architecture $(buildName) -SkipLinkCheck
157122
displayName: 'Build $(buildName)'
158123
env:
159124
ob_restore_phase: true
@@ -269,26 +234,8 @@ extends:
269234
displayName: Install Rust
270235
env:
271236
ob_restore_phase: true
272-
- task: AzureCLI@2
273-
inputs:
274-
azureSubscription: az-PowerShell-feed-ingestion
275-
scriptType: 'pscore'
276-
scriptLocation: 'inlineScript'
277-
inlineScript: |
278-
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
279-
280-
# Set the access token as a secret, so it doesn't get leaked in the logs
281-
Write-Host "##vso[task.setsecret]$accessToken"
282-
$header = "Bearer $accessToken"
283-
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
284-
# convert to base64
285-
$base64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($accessToken))
286-
Write-Host "$base64"
287-
displayName: 'Get Azure DevOps Token'
288-
env:
289-
ob_restore_phase: true
290237
- pwsh: |
291-
./build.ps1 -Release -Architecture x86_64-unknown-linux-gnu -UseCFS
238+
./build.ps1 -Release -Architecture x86_64-unknown-linux-gnu
292239
./build.ps1 -PackageType tgz -Architecture x86_64-unknown-linux-gnu -Release
293240
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
294241
displayName: 'Build x86_64-unknown-linux-gnu'
@@ -312,23 +259,8 @@ extends:
312259
displayName: Install Rust
313260
env:
314261
ob_restore_phase: true
315-
- task: AzureCLI@2
316-
inputs:
317-
azureSubscription: az-PowerShell-feed-ingestion
318-
scriptType: 'pscore'
319-
scriptLocation: 'inlineScript'
320-
inlineScript: |
321-
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
322-
323-
# Set the access token as a secret, so it doesn't get leaked in the logs
324-
Write-Host "##vso[task.setsecret]$accessToken"
325-
$header = "Bearer $accessToken"
326-
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
327-
displayName: 'Get Azure DevOps Token'
328-
env:
329-
ob_restore_phase: true
330262
- pwsh: |
331-
./build.ps1 -Release -Architecture aarch64-unknown-linux-gnu -UseCFS
263+
./build.ps1 -Release -Architecture aarch64-unknown-linux-gnu
332264
./build.ps1 -PackageType tgz -Architecture aarch64-unknown-linux-gnu -Release
333265
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
334266
displayName: 'Build aarch64-unknown-linux-gnu'
@@ -360,23 +292,8 @@ extends:
360292
displayName: Install Rust
361293
env:
362294
ob_restore_phase: true
363-
- task: AzureCLI@2
364-
inputs:
365-
azureSubscription: az-PowerShell-feed-ingestion
366-
scriptType: 'pscore'
367-
scriptLocation: 'inlineScript'
368-
inlineScript: |
369-
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
370-
371-
# Set the access token as a secret, so it doesn't get leaked in the logs
372-
Write-Host "##vso[task.setsecret]$accessToken"
373-
$header = "Bearer $accessToken"
374-
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
375-
displayName: 'Get Azure DevOps Token'
376-
env:
377-
ob_restore_phase: true
378295
- pwsh: |
379-
./build.ps1 -Release -Architecture $(buildName) -UseCFS
296+
./build.ps1 -Release -Architecture $(buildName)
380297
./build.ps1 -PackageType tgz -Architecture $(buildName) -Release
381298
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
382299
Write-Host "##vso[artifact.upload containerfolder=release;artifactname=release]$(ob_outputDirectory)/DSC-$(PackageVersion)-$(buildName).tar.gz"

build.ps1

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ param(
1313
[switch]$GetPackageVersion,
1414
[switch]$SkipLinkCheck,
1515
[switch]$UseX64MakeAppx,
16-
[switch]$UseCFS
16+
[switch]$UseCratesIO
1717
)
1818

1919
if ($GetPackageVersion) {
@@ -168,7 +168,7 @@ if (!$SkipBuild) {
168168
}
169169
New-Item -ItemType Directory $target -ErrorAction Ignore > $null
170170

171-
if (!$UseCFS) {
171+
if ($UseCratesIO) {
172172
# this will override the config.toml
173173
Write-Host "Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'"
174174
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'CRATESIO'
@@ -177,6 +177,23 @@ if (!$SkipBuild) {
177177
Write-Host "Using CFS for cargo source replacement"
178178
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null
179179
$env:CARGO_REGISTRIES_CRATESIO_INDEX = $null
180+
181+
if ($null -eq (Get-Command 'az' -ErrorAction Ignore)) {
182+
throw "Azure CLI not found"
183+
}
184+
185+
if ($null -ne $env:CARGO_REGISTRIES_POWERSHELL_TOKEN) {
186+
Write-Host "Using existing token"
187+
} else {
188+
Write-Host "Getting token"
189+
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
190+
if ($LASTEXITCODE -ne 0) {
191+
Write-Warning "Failed to get access token, use 'az login' first, or use '-useCratesIO' to use crates.io. Proceeding with anonymous access."
192+
} else {
193+
$header = "Bearer $accessToken"
194+
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
195+
}
196+
}
180197
}
181198

182199
# make sure dependencies are built first so clippy runs correctly

0 commit comments

Comments
 (0)