Skip to content

Commit

Permalink
Get build data using darc instead of maestro web api (#7174)
Browse files Browse the repository at this point in the history
  • Loading branch information
jander-msft authored Aug 23, 2024
1 parent 1311825 commit 71dbd36
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 47 deletions.
14 changes: 8 additions & 6 deletions eng/pipelines/dotnet-monitor-compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,24 @@ extends:
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

- task: PowerShell@2
- task: AzureCLI@2
displayName: 'Get Build Version (Full)'
inputs:
filePath: $(Build.SourcesDirectory)/eng/release/Scripts/GetBuildVersion.ps1
azureSubscription: "Darc: Maestro Production"
scriptType: ps
scriptPath: $(Build.SourcesDirectory)/eng/release/Scripts/GetBuildVersion.ps1
arguments: >-
-BarId $(BuildBarId)
-MaestroToken $(MaestroAccessToken)
-TaskVariableName 'BuildVersion'
- task: PowerShell@2
- task: AzureCLI@2
displayName: 'Get Build Version (Major.Minor)'
inputs:
filePath: $(Build.SourcesDirectory)/eng/release/Scripts/GetBuildVersion.ps1
azureSubscription: "Darc: Maestro Production"
scriptType: ps
scriptPath: $(Build.SourcesDirectory)/eng/release/Scripts/GetBuildVersion.ps1
arguments: >-
-BarId $(BuildBarId)
-MaestroToken $(MaestroAccessToken)
-TaskVariableName 'BuildMajorMinorVersion'
-MajorMinorOnly
Expand Down
28 changes: 16 additions & 12 deletions eng/pipelines/dotnet-monitor-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,24 @@ extends:
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

- task: PowerShell@2
- task: AzureCLI@2
displayName: Get Release Version
inputs:
filePath: $(Build.SourcesDirectory)/eng/release/Scripts/GetReleaseVersion.ps1
azureSubscription: "Darc: Maestro Production"
scriptType: ps
scriptPath: $(Build.SourcesDirectory)/eng/release/Scripts/GetReleaseVersion.ps1
arguments: >-
-BarId $(BarId)
-MaestroToken $(MaestroAccessToken)
-TaskVariableName 'ReleaseVersion'
- task: PowerShell@2
- task: AzureCLI@2
displayName: Get Build Version
inputs:
filePath: $(Build.SourcesDirectory)/eng/release/Scripts/GetBuildVersion.ps1
azureSubscription: "Darc: Maestro Production"
scriptType: ps
scriptPath: $(Build.SourcesDirectory)/eng/release/Scripts/GetBuildVersion.ps1
arguments: >-
-BarId $(BarId)
-MaestroToken $(MaestroAccessToken)
-TaskVariableName 'BuildVersion'
- powershell: |
Expand Down Expand Up @@ -145,22 +147,24 @@ extends:
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

- task: PowerShell@2
- task: AzureCLI@2
displayName: Get Release Version
inputs:
filePath: $(Build.SourcesDirectory)/eng/release/Scripts/GetReleaseVersion.ps1
azureSubscription: "Darc: Maestro Production"
scriptType: ps
scriptPath: $(Build.SourcesDirectory)/eng/release/Scripts/GetReleaseVersion.ps1
arguments: >-
-BarId $(BarId)
-MaestroToken $(MaestroAccessToken)
-TaskVariableName 'ReleaseVersion'
- task: PowerShell@2
- task: AzureCLI@2
displayName: Get Build Version
inputs:
filePath: $(Build.SourcesDirectory)/eng/release/Scripts/GetBuildVersion.ps1
azureSubscription: "Darc: Maestro Production"
scriptType: ps
scriptPath: $(Build.SourcesDirectory)/eng/release/Scripts/GetBuildVersion.ps1
arguments: >-
-BarId $(BarId)
-MaestroToken $(MaestroAccessToken)
-TaskVariableName 'BuildVersion'
- powershell: Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
Expand Down
7 changes: 4 additions & 3 deletions eng/pipelines/stages/preparerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ stages:
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest'), or(startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'), startsWith(variables['Build.SourceBranch'], 'refs/heads/internal/release/'), startsWith(variables['Build.SourceBranch'], 'refs/heads/test/release/'))) }}:
- template: /eng/common/templates-official/post-build/setup-maestro-vars.yml@self

- task: PowerShell@2
- task: AzureCLI@2
displayName: Get Build Version
inputs:
filePath: $(Build.SourcesDirectory)/eng/release/Scripts/GetBuildVersion.ps1
azureSubscription: "Darc: Maestro Production"
scriptType: ps
scriptPath: $(Build.SourcesDirectory)/eng/release/Scripts/GetBuildVersion.ps1
arguments: >-
-BarId $(BARBuildId)
-MaestroToken $(MaestroAccessToken)
-TaskVariableName 'BuildVersion'
# Populate dotnetbuilds-internal-container-read-token
Expand Down
23 changes: 9 additions & 14 deletions eng/release/Scripts/GetBuildVersion.ps1
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string] $BarId,
[Parameter(Mandatory=$true)][string] $MaestroToken,
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro-prod.westus2.cloudapp.azure.com',
[Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2020-02-20',
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro.dot.net',
[Parameter(Mandatory=$false)][string] $TaskVariableName = $null,
[Parameter(Mandatory=$false)][string] $DarcVersion = $null,
[Parameter(Mandatory=$false)][switch] $MajorMinorOnly
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 2.0

[array]$releaseData = Invoke-RestMethod `
-Uri "$MaestroApiEndPoint/api/assets?buildId=$BarId&api-version=$MaestroApiVersion" `
-Method 'GET' `
-Headers @{ 'accept' = 'application/json'; 'Authorization' = "Bearer $MaestroToken" }
$buildData = & $PSScriptRoot\GetDarcBuild.ps1 `
-BarId $BarId `
-MaestroApiEndPoint $MaestroApiEndPoint `
-DarcVersion $DarcVersion

Write-Verbose 'ReleaseData:'
$releaseDataJson = $releaseData | ConvertTo-Json
Write-Verbose $releaseDataJson
[array]$matchingData = $buildData.assets | Where-Object { $_.name -match 'MergedManifest.xml$' -and $_.nonShipping }

[array]$matchingData = $releaseData | Where-Object { $_.name -match 'MergedManifest.xml$' -and $_.nonShipping -ieq 'true' }

if ($matchingData.Length -ne 1) {
if (!$matchingData -or $matchingData.Length -ne 1) {
Write-Error 'Unable to obtain build version.'
}

$version = $matchingData[0].Version
$version = $matchingData[0].version

if ($MajorMinorOnly) {
$version = ($version -split '\.')[0..1] -join '.'
Expand Down
36 changes: 36 additions & 0 deletions eng/release/Scripts/GetDarcBuild.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string] $BarId,
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro.dot.net',
[Parameter(Mandatory=$false)][string] $DarcVersion = $null
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 2.0

$ci = $true
$darc = $null
try {
$darc = (Get-Command darc).Source
}
catch {
. $PSScriptRoot\..\..\common\tools.ps1
$darc = Get-Darc $DarcVersion
}

[string]$buildDataJson = & $darc get-build `
--id "$BarId" `
--extended `
--output-format json `
--bar-uri "$MaestroApiEndPoint" `
--ci

Write-Verbose 'BuildData:'
Write-Verbose $buildDataJson
$buildData = $buildDataJson | ConvertFrom-Json

if (!$buildData -or $buildData.Length -ne 1) {
Write-Error 'Unable to obtain build data.'
}

Write-Output $buildData[0]
21 changes: 9 additions & 12 deletions eng/release/Scripts/GetReleaseVersion.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string] $BarId,
[Parameter(Mandatory=$true)][string] $MaestroToken,
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro-prod.westus2.cloudapp.azure.com',
[Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2020-02-20',
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro.dot.net',
[Parameter(Mandatory=$false)][string] $TaskVariableName = $null,
[Parameter(Mandatory=$false)][string] $DarcVersion = $null,
[Parameter(Mandatory=$false)][switch] $IncludeV
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 2.0

[array]$releaseData = Invoke-RestMethod `
-Uri "$MaestroApiEndPoint/api/assets?buildId=$BarId&name=dotnet-monitor&api-version=$MaestroApiVersion" `
-Method 'GET' `
-Headers @{ 'accept' = 'application/json'; 'Authorization' = "Bearer $MaestroToken" }
$buildData = & $PSScriptRoot\GetDarcBuild.ps1 `
-BarId $BarId `
-MaestroApiEndPoint $MaestroApiEndPoint `
-DarcVersion $DarcVersion

Write-Verbose 'ReleaseData:'
$releaseDataJson = $releaseData | ConvertTo-Json
Write-Verbose $releaseDataJson
[array]$matchingData = $buildData.assets | Where-Object { $_.name -match '^dotnet-monitor$' }

if ($releaseData.Length -ne 1) {
if (!$matchingData -or $matchingData.Length -ne 1) {
Write-Error 'Unable to obtain release version'
}

$version = $releaseData[0].Version
$version = $matchingData[0].version
if ($IncludeV) {
$version = "v$version"
}
Expand Down

0 comments on commit 71dbd36

Please sign in to comment.