Generate the graphviz contents on every official build (#834)

This commit is contained in:
JC Aguilera 2019-03-05 13:48:26 -08:00 committed by Nick Guerrera
parent 8ca21c772b
commit 24946df3cb
2 changed files with 92 additions and 0 deletions

View file

@ -276,3 +276,35 @@ jobs:
enablePublishBuildArtifacts: true
pool:
vmImage: vs2017-win2016
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
- job: Create_GraphViz
displayName: Create GraphViz
dependsOn:
- Windows_NT
- Linux
- Darwin
- Asset_Registry_Publish
pool:
name: Hosted VS2017
condition: succeeded()
variables:
# Publish-Build-Assets provides: MaestroAccessToken, BotAccount-dotnet-maestro-bot-PAT
# DotNet-AllOrgs-Darc-Pats provides: dn-bot-devdiv-dnceng-rw-code-pat
- group: Publish-Build-Assets
- group: DotNet-AllOrgs-Darc-Pats
steps:
- task: PowerShell@2
displayName: Generate GraphViz graph
inputs:
filePath: eng/common/generate-graphviz.ps1
arguments: -gitHubPat $(BotAccount-dotnet-maestro-bot-PAT) -azdoPat $(dn-bot-devdiv-dnceng-rw-code-pat) -barToken $(MaestroAccessToken) -outputFolder '$(Build.StagingDirectory)/GraphViz/'
continueOnError: true
- task: PublishBuildArtifacts@1
displayName: Publish Graph to Artifacts
inputs:
PathtoPublish: '$(Build.StagingDirectory)/GraphViz'
PublishLocation: Container
ArtifactName: GraphViz
continueOnError: true
condition: always()

View file

@ -0,0 +1,60 @@
Param(
[Parameter(Mandatory=$true)][string] $barToken, # Token generated at https://maestro-prod.westus2.cloudapp.azure.com/Account/Tokens
[Parameter(Mandatory=$true)][string] $gitHubPat, # GitHub personal access token from https://github.com/settings/tokens (no auth scopes needed)
[Parameter(Mandatory=$true)][string] $azdoPat, # Azure Dev Ops tokens from https://dev.azure.com/dnceng/_details/security/tokens (code read scope needed)
[Parameter(Mandatory=$true)][string] $outputFolder, # Where the graphviz.txt file will be created
[string] $darcVersion = '1.1.0-beta.19154.2', # darc's version
[switch] $includeToolset # Whether the graph should include toolset dependencies or not. i.e. arcade, optimization. For more about
# toolset dependencies see https://github.com/dotnet/arcade/blob/master/Documentation/Darc.md#toolset-vs-product-dependencies
)
$ErrorActionPreference = "Stop"
. $PSScriptRoot\tools.ps1
function CheckExitCode ([string]$stage)
{
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
Write-Host "Something failed in stage: '$stage'. Check for errors above. Exiting now..."
ExitWithExitCode $exitCode
}
}
try {
Push-Location $PSScriptRoot
Write-Host "Installing darc..."
. .\darc-init.ps1 -darcVersion $darcVersion
CheckExitCode "Running darc-init"
$DarcExe = "$env:USERPROFILE\.dotnet\tools"
$DarcExe = Resolve-Path "$DarcExe\darc.exe"
Create-Directory $outputFolder
$graphVizFilePath = "$outputFolder\graphviz.txt"
$options = "get-dependency-graph --graphviz '$graphVizFilePath' --github-pat $gitHubPat --azdev-pat $azdoPat --password $barToken"
if ($includeToolset) {
Write-Host "Toolsets will be included in the graph..."
$options += " --include-toolset"
}
Write-Host "Generating dependency graph..."
$darc = Invoke-Expression "& `"$DarcExe`" $options"
CheckExitCode "Generating dependency graph"
$graph = Get-Content $graphVizFilePath
Set-Content $graphVizFilePath -Value "Paste the following digraph object in http://www.webgraphviz.com `r`n", $graph
Write-Host "'$graphVizFilePath' file created!"
}
catch {
if (!$includeToolset) {
Write-Host "This might be a toolset repo which includes only toolset dependencies. " -NoNewline -ForegroundColor Yellow
Write-Host "Since -includeToolset is not set there is no graph to create. Include -includeToolset and try again..." -ForegroundColor Yellow
}
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
ExitWithExitCode 1
}