Skip to content

Commit c9d776d

Browse files
author
Jason Zhai
committed
Reverting the changes introduced to the arcade flow
1 parent a1f18d9 commit c9d776d

18 files changed

+292
-46
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
param(
2+
[Parameter(Mandatory=$true)][int] $BuildId,
3+
[Parameter(Mandatory=$true)][int] $ChannelId,
4+
[Parameter(Mandatory=$true)][string] $MaestroApiAccessToken,
5+
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro.dot.net',
6+
[Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2019-01-16'
7+
)
8+
9+
try {
10+
. $PSScriptRoot\post-build-utils.ps1
11+
12+
# Check that the channel we are going to promote the build to exist
13+
$channelInfo = Get-MaestroChannel -ChannelId $ChannelId
14+
15+
if (!$channelInfo) {
16+
Write-PipelineTelemetryCategory -Category 'PromoteBuild' -Message "Channel with BAR ID $ChannelId was not found in BAR!"
17+
ExitWithExitCode 1
18+
}
19+
20+
# Get info about which channel(s) the build has already been promoted to
21+
$buildInfo = Get-MaestroBuild -BuildId $BuildId
22+
23+
if (!$buildInfo) {
24+
Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "Build with BAR ID $BuildId was not found in BAR!"
25+
ExitWithExitCode 1
26+
}
27+
28+
# Find whether the build is already assigned to the channel or not
29+
if ($buildInfo.channels) {
30+
foreach ($channel in $buildInfo.channels) {
31+
if ($channel.Id -eq $ChannelId) {
32+
Write-Host "The build with BAR ID $BuildId is already on channel $ChannelId!"
33+
ExitWithExitCode 0
34+
}
35+
}
36+
}
37+
38+
Write-Host "Promoting build '$BuildId' to channel '$ChannelId'."
39+
40+
Assign-BuildToChannel -BuildId $BuildId -ChannelId $ChannelId
41+
42+
Write-Host 'done.'
43+
}
44+
catch {
45+
Write-Host $_
46+
Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "There was an error while trying to promote build '$BuildId' to channel '$ChannelId'"
47+
ExitWithExitCode 1
48+
}

eng/common/post-build/check-channel-consistency.ps1

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ param(
44
)
55

66
try {
7-
$ErrorActionPreference = 'Stop'
8-
Set-StrictMode -Version 2.0
9-
10-
# `tools.ps1` checks $ci to perform some actions. Since the post-build
11-
# scripts don't necessarily execute in the same agent that run the
12-
# build.ps1/sh script this variable isn't automatically set.
13-
$ci = $true
14-
$disableConfigureToolsetImport = $true
15-
. $PSScriptRoot\..\tools.ps1
7+
. $PSScriptRoot\post-build-utils.ps1
168

179
if ($PromoteToChannels -eq "") {
1810
Write-PipelineTaskError -Type 'warning' -Message "This build won't publish assets as it's not configured to any Maestro channel. If that wasn't intended use Darc to configure a default channel using add-default-channel for this branch or to promote it to a channel using add-build-to-channel. See https://github.com/dotnet/arcade/blob/master/Documentation/Darc.md#assigning-an-individual-build-to-a-channel for more info."

eng/common/post-build/nuget-validation.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
# tool: https://github.com/NuGet/NuGetGallery/tree/jver-verify/src/VerifyMicrosoftPackage
33

44
param(
5-
[Parameter(Mandatory=$true)][string] $PackagesPath # Path to where the packages to be validated are
5+
[Parameter(Mandatory=$true)][string] $PackagesPath, # Path to where the packages to be validated are
6+
[Parameter(Mandatory=$true)][string] $ToolDestinationPath # Where the validation tool should be downloaded to
67
)
78

89
try {
9-
& $PSScriptRoot\nuget-verification.ps1 ${PackagesPath}\*.nupkg
10+
. $PSScriptRoot\post-build-utils.ps1
11+
12+
$url = 'https://raw.githubusercontent.com/NuGet/NuGetGallery/3e25ad135146676bcab0050a516939d9958bfa5d/src/VerifyMicrosoftPackage/verify.ps1'
13+
14+
New-Item -ItemType 'directory' -Path ${ToolDestinationPath} -Force
15+
16+
Invoke-WebRequest $url -OutFile ${ToolDestinationPath}\verify.ps1
17+
18+
& ${ToolDestinationPath}\verify.ps1 ${PackagesPath}\*.nupkg
1019
}
1120
catch {
1221
Write-Host $_.ScriptStackTrace
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Most of the functions in this file require the variables `MaestroApiEndPoint`,
2+
# `MaestroApiVersion` and `MaestroApiAccessToken` to be globally available.
3+
4+
$ErrorActionPreference = 'Stop'
5+
Set-StrictMode -Version 2.0
6+
7+
# `tools.ps1` checks $ci to perform some actions. Since the post-build
8+
# scripts don't necessarily execute in the same agent that run the
9+
# build.ps1/sh script this variable isn't automatically set.
10+
$ci = $true
11+
$disableConfigureToolsetImport = $true
12+
. $PSScriptRoot\..\tools.ps1
13+
14+
function Create-MaestroApiRequestHeaders([string]$ContentType = 'application/json') {
15+
Validate-MaestroVars
16+
17+
$headers = New-Object 'System.Collections.Generic.Dictionary[[String],[String]]'
18+
$headers.Add('Accept', $ContentType)
19+
$headers.Add('Authorization',"Bearer $MaestroApiAccessToken")
20+
return $headers
21+
}
22+
23+
function Get-MaestroChannel([int]$ChannelId) {
24+
Validate-MaestroVars
25+
26+
$apiHeaders = Create-MaestroApiRequestHeaders
27+
$apiEndpoint = "$MaestroApiEndPoint/api/channels/${ChannelId}?api-version=$MaestroApiVersion"
28+
29+
$result = try { Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" }
30+
return $result
31+
}
32+
33+
function Get-MaestroBuild([int]$BuildId) {
34+
Validate-MaestroVars
35+
36+
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken
37+
$apiEndpoint = "$MaestroApiEndPoint/api/builds/${BuildId}?api-version=$MaestroApiVersion"
38+
39+
$result = try { return Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" }
40+
return $result
41+
}
42+
43+
function Get-MaestroSubscriptions([string]$SourceRepository, [int]$ChannelId) {
44+
Validate-MaestroVars
45+
46+
$SourceRepository = [System.Web.HttpUtility]::UrlEncode($SourceRepository)
47+
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken
48+
$apiEndpoint = "$MaestroApiEndPoint/api/subscriptions?sourceRepository=$SourceRepository&channelId=$ChannelId&api-version=$MaestroApiVersion"
49+
50+
$result = try { Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" }
51+
return $result
52+
}
53+
54+
function Assign-BuildToChannel([int]$BuildId, [int]$ChannelId) {
55+
Validate-MaestroVars
56+
57+
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken
58+
$apiEndpoint = "$MaestroApiEndPoint/api/channels/${ChannelId}/builds/${BuildId}?api-version=$MaestroApiVersion"
59+
Invoke-WebRequest -Method Post -Uri $apiEndpoint -Headers $apiHeaders | Out-Null
60+
}
61+
62+
function Trigger-Subscription([string]$SubscriptionId) {
63+
Validate-MaestroVars
64+
65+
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken
66+
$apiEndpoint = "$MaestroApiEndPoint/api/subscriptions/$SubscriptionId/trigger?api-version=$MaestroApiVersion"
67+
Invoke-WebRequest -Uri $apiEndpoint -Headers $apiHeaders -Method Post | Out-Null
68+
}
69+
70+
function Validate-MaestroVars {
71+
try {
72+
Get-Variable MaestroApiEndPoint | Out-Null
73+
Get-Variable MaestroApiVersion | Out-Null
74+
Get-Variable MaestroApiAccessToken | Out-Null
75+
76+
if (!($MaestroApiEndPoint -Match '^http[s]?://maestro-(int|prod).westus2.cloudapp.azure.com$')) {
77+
Write-PipelineTelemetryError -Category 'MaestroVars' -Message "MaestroApiEndPoint is not a valid Maestro URL. '$MaestroApiEndPoint'"
78+
ExitWithExitCode 1
79+
}
80+
81+
if (!($MaestroApiVersion -Match '^[0-9]{4}-[0-9]{2}-[0-9]{2}$')) {
82+
Write-PipelineTelemetryError -Category 'MaestroVars' -Message "MaestroApiVersion does not match a version string in the format yyyy-MM-DD. '$MaestroApiVersion'"
83+
ExitWithExitCode 1
84+
}
85+
}
86+
catch {
87+
Write-PipelineTelemetryError -Category 'MaestroVars' -Message 'Error: Variables `MaestroApiEndPoint`, `MaestroApiVersion` and `MaestroApiAccessToken` are required while using this script.'
88+
Write-Host $_
89+
ExitWithExitCode 1
90+
}
91+
}

eng/common/post-build/publish-using-darc.ps1

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ param(
99
)
1010

1111
try {
12-
# `tools.ps1` checks $ci to perform some actions. Since the post-build
13-
# scripts don't necessarily execute in the same agent that run the
14-
# build.ps1/sh script this variable isn't automatically set.
15-
$ci = $true
16-
$disableConfigureToolsetImport = $true
17-
. $PSScriptRoot\..\tools.ps1
12+
. $PSScriptRoot\post-build-utils.ps1
1813

1914
$darc = Get-Darc
2015

eng/common/post-build/sourcelink-validation.ps1

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@ param(
66
[Parameter(Mandatory=$true)][string] $SourcelinkCliVersion # Version of SourceLink CLI to use
77
)
88

9-
$ErrorActionPreference = 'Stop'
10-
Set-StrictMode -Version 2.0
11-
12-
# `tools.ps1` checks $ci to perform some actions. Since the post-build
13-
# scripts don't necessarily execute in the same agent that run the
14-
# build.ps1/sh script this variable isn't automatically set.
15-
$ci = $true
16-
$disableConfigureToolsetImport = $true
17-
. $PSScriptRoot\..\tools.ps1
9+
. $PSScriptRoot\post-build-utils.ps1
1810

1911
# Cache/HashMap (File -> Exist flag) used to consult whether a file exist
2012
# in the repository at a specific commit point. This is populated by inserting

eng/common/post-build/symbols-validation.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ function InstallDotnetSymbol {
322322
}
323323

324324
try {
325+
. $PSScriptRoot\post-build-utils.ps1
326+
325327
InstallDotnetSymbol
326328

327329
foreach ($Job in @(Get-Job)) {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
param(
2+
[Parameter(Mandatory=$true)][string] $SourceRepo,
3+
[Parameter(Mandatory=$true)][int] $ChannelId,
4+
[Parameter(Mandatory=$true)][string] $MaestroApiAccessToken,
5+
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro.dot.net',
6+
[Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2019-01-16'
7+
)
8+
9+
try {
10+
. $PSScriptRoot\post-build-utils.ps1
11+
12+
# Get all the $SourceRepo subscriptions
13+
$normalizedSourceRepo = $SourceRepo.Replace('dnceng@', '')
14+
$subscriptions = Get-MaestroSubscriptions -SourceRepository $normalizedSourceRepo -ChannelId $ChannelId
15+
16+
if (!$subscriptions) {
17+
Write-PipelineTelemetryError -Category 'TriggerSubscriptions' -Message "No subscriptions found for source repo '$normalizedSourceRepo' in channel '$ChannelId'"
18+
ExitWithExitCode 0
19+
}
20+
21+
$subscriptionsToTrigger = New-Object System.Collections.Generic.List[string]
22+
$failedTriggeredSubscription = $false
23+
24+
# Get all enabled subscriptions that need dependency flow on 'everyBuild'
25+
foreach ($subscription in $subscriptions) {
26+
if ($subscription.enabled -and $subscription.policy.updateFrequency -like 'everyBuild' -and $subscription.channel.id -eq $ChannelId) {
27+
Write-Host "Should trigger this subscription: ${$subscription.id}"
28+
[void]$subscriptionsToTrigger.Add($subscription.id)
29+
}
30+
}
31+
32+
foreach ($subscriptionToTrigger in $subscriptionsToTrigger) {
33+
try {
34+
Write-Host "Triggering subscription '$subscriptionToTrigger'."
35+
36+
Trigger-Subscription -SubscriptionId $subscriptionToTrigger
37+
38+
Write-Host 'done.'
39+
}
40+
catch
41+
{
42+
Write-Host "There was an error while triggering subscription '$subscriptionToTrigger'"
43+
Write-Host $_
44+
Write-Host $_.ScriptStackTrace
45+
$failedTriggeredSubscription = $true
46+
}
47+
}
48+
49+
if ($subscriptionsToTrigger.Count -eq 0) {
50+
Write-Host "No subscription matched source repo '$normalizedSourceRepo' and channel ID '$ChannelId'."
51+
}
52+
elseif ($failedTriggeredSubscription) {
53+
Write-PipelineTelemetryError -Category 'TriggerSubscriptions' -Message 'At least one subscription failed to be triggered...'
54+
ExitWithExitCode 1
55+
}
56+
else {
57+
Write-Host 'All subscriptions were triggered successfully!'
58+
}
59+
}
60+
catch {
61+
Write-Host $_.ScriptStackTrace
62+
Write-PipelineTelemetryError -Category 'TriggerSubscriptions' -Message $_
63+
ExitWithExitCode 1
64+
}

eng/common/templates-official/job/publish-build-assets.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ jobs:
7878

7979
- task: AzureCLI@2
8080
displayName: Publish Build Assets
81-
condition: ${{ parameters.condition }}
82-
continueOnError: ${{ parameters.continueOnError }}
8381
inputs:
8482
azureSubscription: "Darc: Maestro Production"
8583
scriptType: ps

eng/common/templates-official/post-build/setup-maestro-vars.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,35 @@ steps:
1111
artifactName: ReleaseConfigs
1212
checkDownloadedFiles: true
1313

14-
- task: AzureCLI@2
14+
- task: PowerShell@2
1515
name: setReleaseVars
1616
displayName: Set Release Configs Vars
1717
inputs:
18-
azureSubscription: "Darc: Maestro Production"
19-
scriptType: pscore
20-
scriptLocation: inlineScript
21-
inlineScript: |
18+
targetType: inline
19+
pwsh: true
20+
script: |
2221
try {
2322
if (!$Env:PromoteToMaestroChannels -or $Env:PromoteToMaestroChannels.Trim() -eq '') {
2423
$Content = Get-Content $(Build.StagingDirectory)/ReleaseConfigs/ReleaseConfigs.txt
2524
2625
$BarId = $Content | Select -Index 0
27-
$Channels = $Content | Select -Index 1
26+
$Channels = $Content | Select -Index 1
2827
$IsStableBuild = $Content | Select -Index 2
2928
3029
$AzureDevOpsProject = $Env:System_TeamProject
3130
$AzureDevOpsBuildDefinitionId = $Env:System_DefinitionId
3231
$AzureDevOpsBuildId = $Env:Build_BuildId
3332
}
3433
else {
35-
. $(Build.SourcesDirectory)\eng\common\tools.ps1
36-
$darc = Get-Darc
37-
$buildInfo = & $darc get-build `
38-
--id ${{ parameters.BARBuildId }} `
39-
--extended `
40-
--output-format json `
41-
--ci `
42-
| convertFrom-Json
34+
$buildApiEndpoint = "${Env:MaestroApiEndPoint}/api/builds/${Env:BARBuildId}?api-version=${Env:MaestroApiVersion}"
4335
44-
$BarId = ${{ parameters.BARBuildId }}
36+
$apiHeaders = New-Object 'System.Collections.Generic.Dictionary[[String],[String]]'
37+
$apiHeaders.Add('Accept', 'application/json')
38+
$apiHeaders.Add('Authorization',"Bearer ${Env:MAESTRO_API_TOKEN}")
39+
40+
$buildInfo = try { Invoke-WebRequest -Method Get -Uri $buildApiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" }
41+
42+
$BarId = $Env:BARBuildId
4543
$Channels = $Env:PromoteToMaestroChannels -split ","
4644
$Channels = $Channels -join "]["
4745
$Channels = "[$Channels]"
@@ -67,4 +65,6 @@ steps:
6765
exit 1
6866
}
6967
env:
68+
MAESTRO_API_TOKEN: $(MaestroApiAccessToken)
69+
BARBuildId: ${{ parameters.BARBuildId }}
7070
PromoteToMaestroChannels: ${{ parameters.PromoteToChannelIds }}

0 commit comments

Comments
 (0)