Skip to content

Commit 7640276

Browse files
authored
Onboard Foundation to use Maestro (#843)
Onboard Foundation to use Maestro (#843)
1 parent b5a0387 commit 7640276

11 files changed

Lines changed: 297 additions & 1 deletion

build/AzurePipelinesTemplates/ProjectReunion-CreateNugetPackage-Job.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ parameters:
88
primaryBuildArch: x86
99
buildFlavor: Release
1010
prereleaseVersionTag: 'prerelease'
11+
publishToMaestro: false
1112
condition: ''
1213

1314
jobs:
@@ -89,7 +90,8 @@ jobs:
8990
targetType: 'inline'
9091
script: |
9192
$packageVersion = '$(version).${{ parameters.prereleaseVersionTag }}'
92-
Write-Host version: $packageVersion
93+
Write-Host "##vso[task.setvariable variable=packageVersion;]$packageVersion"
94+
Write-Host $packageVersion
9395
[xml]$publicNuspec = Get-Content -Path $(Build.SourcesDirectory)\build\NuSpecs\Microsoft.ProjectReunion.Foundation.nuspec
9496
$publicNuspec.package.metadata.version = $packageVersion
9597
Set-Content -Value $publicNuspec.OuterXml $(Build.SourcesDirectory)\build\NuSpecs\Microsoft.ProjectReunion.Foundation.nuspec
@@ -151,6 +153,13 @@ jobs:
151153
#Note: The project qualifier is always required when using a feed name. Also, do not use organization scoped feeds.
152154
publishVstsFeed: 'ProjectReunion/Project.Reunion.nuget.internal'
153155

156+
- ${{ if eq(parameters.publishToMaestro, 'true') }}:
157+
- template: ..\..\eng\common\Maestro-PublishBuildToMaestro.yml
158+
parameters:
159+
IsGitHubRepo: true
160+
AssetName: 'Microsoft.ProjectReunion.Foundation.TransportPackage'
161+
AssetVersion: $(packageVersion)
162+
TriggerSubscrption: true
154163
#UNDONE - EHO we need to seed these guid's properly!
155164
#see, e.g. AzurePipelinesTemplates\ProjectReunion-BuildAndPublishPGONuGet-Job.yml
156165
#

build/ProjectReunion-BuildFoundation.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ parameters:
77
- name: "ReleaseSigning"
88
type: boolean
99
default: False
10+
- name: "PublishToMaestro"
11+
type: boolean
12+
default: False
1013

1114
jobs:
1215
- job: CredScan
@@ -363,6 +366,7 @@ jobs:
363366
signConfigPattern: 'Microsoft.ProjectReunion*.nupkg'
364367
useReleaseTag: '$(ProjectReunionFinalRelease)'
365368
prereleaseVersionTag: nightly
369+
publishToMaestro: ${{ parameters.PublishToMaestro }}
366370

367371
# Build solution that depends on nuget package
368372
#- template: AzurePipelinesTemplates\ProjectReunion-NugetReleaseTest-Job.yml

build/ProjectReunion-CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ jobs:
159159
# Create Nuget Package
160160
- template: AzurePipelinesTemplates\ProjectReunion-CreateNugetPackage-Job.yml
161161
parameters:
162+
publishToMaestro: false
162163
jobName: CreateNugetPackage
163164
dependsOn:
164165
- Build

eng/Version.Details.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Dependencies>
3+
<ProductDependencies>
4+
</ProductDependencies>
5+
<ToolsetDependencies>
6+
</ToolsetDependencies>
7+
</Dependencies>

eng/Versions.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
</PropertyGroup>
5+
</Project>
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
parameters:
2+
AssetName: ''
3+
AssetVersion: ''
4+
TriggerSubscrption: false
5+
IsGitHubRepo: true
6+
7+
steps:
8+
- task: PowerShell@2
9+
displayName: Check prerequisites
10+
inputs:
11+
targetType: 'inline'
12+
script: |
13+
Write-Host "Pipeline Variable 'MaestroToken' and 'MaestroUri' must have a value"
14+
Write-Host "##vso[task.complete result=Failed;]DONE"
15+
condition: or(eq(variables['MaestroUri'], ''), eq(variables['MaestroToken'], ''))
16+
17+
- task: PowerShell@2
18+
displayName: Build JsonBody
19+
inputs:
20+
targetType: 'inline'
21+
script: |
22+
. .\eng\common\MaestroHelpers.ps1
23+
24+
$jsonBase = @{}
25+
26+
$assetList = New-Object System.Collections.ArrayList
27+
$assetList.Add(
28+
@{
29+
"name"="${{ parameters.AssetName }}";
30+
"version"="${{ parameters.AssetVersion }}";
31+
"nonShipping"=$false;
32+
"locations"=$null
33+
}
34+
)
35+
36+
# These fields below are unused but can be enabled in the future
37+
# $locationList = New-Object System.Collections.ArrayList
38+
# $locationList.Add(@{"location"="maestroTestValue";"type"="none"})
39+
40+
# $dependenciesList = New-Object System.Collections.ArrayList
41+
# $dependenciesList.Add(
42+
# @{
43+
# "buildId"=0;
44+
# "isProduct"=$true;
45+
# "timeToInclusionInMinutes"=0;
46+
# }
47+
# )
48+
49+
# $incoherenciesList = New-Object System.Collections.ArrayList
50+
# $incoherenciesList.Add(
51+
# @{
52+
# "name"="maestroTestValue";
53+
# "version"="maestroTestValue";
54+
# "repository"="maestroTestValue";
55+
# "commit"="maestroTestValue";
56+
# }
57+
# )
58+
59+
Write-Host "collectionuri: $(System.CollectionUri)"
60+
$devOpsAccount = ExtractOrgFromAzureDevOpsCollectionUri '$(System.CollectionUri)'
61+
Write-Host "reposiitory: $(Build.Repository.Uri)"
62+
Write-Host "account: " $devOpsAccount
63+
64+
$gitHubRepo = ""
65+
$azureDevOpsRepo = ""
66+
if ('${{ parameters.IsGitHubRepo }}' -eq 'true')
67+
{
68+
$gitHubRepo = "$(Build.Repository.Uri)"
69+
$azureDevOpsRepo = "$(Build.Repository.Uri)" # Maestro expects this to be always set
70+
}
71+
if ('${{ parameters.IsGitHubRepo }}' -ne 'true')
72+
{
73+
$azureDevOpsRepo = "$(Build.Repository.Uri)"
74+
}
75+
76+
$jsonBase =
77+
@{
78+
"commit"="$(Build.SourceVersion)";
79+
"assets"=$assetList;
80+
"dependencies"=$null;
81+
"azureDevOpsBuildId"=$(Build.BuildId);
82+
"azureDevOpsBuildDefinitionId"=$(System.DefinitionId);
83+
"azureDevOpsAccount"=$devOpsAccount;
84+
"azureDevOpsProject"="$(System.TeamProject)";
85+
"azureDevOpsBuildNumber"="$(Build.BuildNumber)";
86+
"azureDevOpsRepository"=$azureDevOpsRepo;
87+
"azureDevOpsBranch"="$(Build.SourceBranch)";
88+
"gitHubRepository"=$gitHubRepo;
89+
"gitHubBranch"="$(Build.SourceBranch)";
90+
"released"=$true;
91+
"stable"=$true
92+
"incoherencies"=$null;
93+
}
94+
95+
$jsonBase | ConvertTo-Json -Depth 10 | Out-File '$(Build.SourcesDirectory)\eng\common\maestro-build.json'
96+
$body = Get-Content -Raw -Path '$(Build.SourcesDirectory)\eng\common\maestro-build.json'
97+
Write-host $body
98+
99+
- task: powershell@2
100+
displayName: 'Post build to Maestro'
101+
inputs:
102+
targetType: filePath
103+
filePath: eng\common\MaestroPostRequest.ps1
104+
arguments: -url '$(MaestroUri)' -Token '$(MaestroToken)' -api '/api/builds' -jsonBodyPath '$(Build.SourcesDirectory)\eng\common\maestro-build.json'
105+
106+
- ${{ if eq(parameters.TriggerSubscrption, 'true') }}:
107+
- task: powershell@2
108+
displayName: 'Publish Build to Default Channel'
109+
inputs:
110+
targetType: 'inline'
111+
script: |
112+
# Get the id of the default channel of this branch
113+
$api = "/api/default-channels"
114+
$response = &".\eng\common\MaestroGetRequest.ps1" -url '$(MaestroUri)' -Token '$(MaestroToken)' -api $api -queryParameters '&repository=$(Build.Repository.Uri)&branch=$(Build.SourceBranch)'
115+
$jsonObj = ConvertFrom-Json $response.Content
116+
$channelId = $jsonObj.channel.id
117+
if ([string]::IsNullOrEmpty($channelId))
118+
{
119+
Write-Host "Error: Default channel not found. Please use darc add-default-channel to add a default channel for this repo and branch"
120+
Write-Host "##vso[task.complete result=SucceededWithIssues;]DONE"
121+
}
122+
else
123+
{
124+
# Get the id of the build posted earlier
125+
$api = "/api/builds"
126+
$response = &".\eng\common\MaestroGetRequest.ps1" -url '$(MaestroUri)' -Token '$(MaestroToken)' -api $api -queryParameters '&repository=$(Build.Repository.Uri)&commit=$(Build.SourceVersion)'
127+
$jsonObj = ConvertFrom-Json $response.Content
128+
$buildId = $jsonObj.id
129+
if ([string]::IsNullOrEmpty($buildId))
130+
{
131+
Write-Host "Error: build not found in Maestro"
132+
Write-Host "##vso[task.complete result=Failed;]DONE"
133+
}
134+
135+
# AddBuildToChannel with the corresponding build id and channel id
136+
$api = "/api/channels/" + $channelId + "/builds/" + $buildId
137+
$response = &".\eng\common\MaestroPostRequest.ps1" -url '$(MaestroUri)' -Token '$(MaestroToken)' -api $api -jsonBodyPath ''
138+
139+
# Get the list of subscriptions on the channel
140+
$api = "/api/subscriptions"
141+
$queryParams = "&channelId=" + $channelId
142+
$response = &".\eng\common\MaestroGetRequest.ps1" -url '$(MaestroUri)' -Token '$(MaestroToken)' -api $api -queryParameters $queryParams
143+
$jsonObj = ConvertFrom-Json $response.Content
144+
foreach ($sub in $jsonObj)
145+
{
146+
# Trigger the subscription
147+
$id = $sub.id
148+
Write-Host "Triggering subscription on " $id
149+
# bar-build-id is always 0
150+
$api = "/api/subscriptions/" + $id + "/trigger"
151+
$response = &".\eng\common\MaestroPostRequest.ps1" -url '$(MaestroUri)' -Token '$(MaestroToken)' -api $api -jsonBodyPath '' -queryParameters '&bar-build-id=0'
152+
}
153+
}
154+

eng/common/MaestroGetRequest.ps1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[CmdLetBinding()]
2+
Param(
3+
[string]$url,
4+
[string]$token,
5+
[string]$api,
6+
[string]$queryParameters
7+
)
8+
9+
$headers = @{
10+
Authorization="Bearer $token"
11+
}
12+
13+
$contentType = 'application/json'
14+
$api = $api + '?api-version=2020-02-20' + $queryParameters
15+
$fullUri = $url + $api
16+
17+
Write-Host $fullUri
18+
19+
$response = Invoke-WebRequest -Method 'GET' -Uri $fullUri -Headers $headers -ContentType $contentType
20+
Write-Host $response
21+
22+
if ($Response.statuscode -lt '200')
23+
{
24+
Write-Host $Response.statuscode
25+
Write-Host "##vso[task.complete result=Failed;]DONE"
26+
}
27+
if ($Response.statuscode -ge '300')
28+
{
29+
Write-Host $Response.statuscode
30+
Write-Host "##vso[task.complete result=Failed;]DONE"
31+
}
32+
33+
34+
return $response

eng/common/MaestroHelpers.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Pram: CollectionUri must be in the form below
2+
# https://microsoft.visualstudio.com/
3+
function ExtractOrgFromAzureDevOpsCollectionUri([string]$CollectionUri)
4+
{
5+
$Split1 = $CollectionUri.Split(".")
6+
$temp1 = $Split1[0]
7+
$Split2 = $temp1.Substring(8)
8+
return $Split2
9+
}

eng/common/MaestroPostRequest.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[CmdLetBinding()]
2+
Param(
3+
[string]$url,
4+
[string]$token,
5+
[string]$api,
6+
[string]$jsonBodyPath,
7+
[string]$queryParameters = ''
8+
)
9+
10+
$headers = @{
11+
Authorization="Bearer $token"
12+
}
13+
14+
$body = ''
15+
if (-not [string]::IsNullOrEmpty($jsonBodyPath))
16+
{
17+
$body = Get-Content -Raw -Path $jsonBodyPath
18+
}
19+
20+
$contentType = 'application/json'
21+
$api = $api + '?api-version=2020-02-20' + $queryParameters
22+
$fullUri = $url + $api
23+
24+
Write-Host $fullUri
25+
26+
$Response = Invoke-WebRequest -Method 'POST' -Uri $fullUri -Headers $headers -Body $body -ContentType $contentType
27+
Write-Host $Response
28+
29+
if ($Response.statuscode -lt '200')
30+
{
31+
Write-Host $Response.statuscode
32+
Write-Host "##vso[task.complete result=Failed;]DONE"
33+
}
34+
if ($Response.statuscode -ge '300')
35+
{
36+
Write-Host $Response.statuscode
37+
Write-Host "##vso[task.complete result=Failed;]DONE"
38+
}
39+
40+
return $Response

eng/common/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Don't touch this folder
2+
3+
uuuuuuuuuuuuuuuuuuuu
4+
u" uuuuuuuuuuuuuuuuuu "u
5+
u" u$$$$$$$$$$$$$$$$$$$$u "u
6+
u" u$$$$$$$$$$$$$$$$$$$$$$$$u "u
7+
u" u$$$$$$$$$$$$$$$$$$$$$$$$$$$$u "u
8+
u" u$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$u "u
9+
u" u$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$u "u
10+
$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $
11+
$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $
12+
$ $$$" ... "$... ...$" ... "$$$ ... "$$$ $
13+
$ $$$u `"$$$$$$$ $$$ $$$$$ $$ $$$ $$$ $
14+
$ $$$$$$uu "$$$$ $$$ $$$$$ $$ """ u$$$ $
15+
$ $$$""$$$ $$$$ $$$u "$$$" u$$ $$$$$$$$ $
16+
$ $$$$....,$$$$$..$$$$$....,$$$$..$$$$$$$$ $
17+
$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $
18+
"u "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" u"
19+
"u "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" u"
20+
"u "$$$$$$$$$$$$$$$$$$$$$$$$$$$$" u"
21+
"u "$$$$$$$$$$$$$$$$$$$$$$$$" u"
22+
"u "$$$$$$$$$$$$$$$$$$$$" u"
23+
"u """""""""""""""""" u"
24+
""""""""""""""""""""
25+
26+
!!! Changes made in this directory are subject to being overwritten by automation !!!
27+
28+
The files in this directory are shared by all Arcade repos and managed by automation.

0 commit comments

Comments
 (0)