forked from Azure/azure-sdk-for-go
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync eng/common directory with azure-sdk-tools for PR 6919 (Azure#21611)
* Add autorest-preview pipeline * Add emitternpminstall * Always install * Use shorter leg name * Add short circuiting to emitter install * Use language matrix function * Don't look for subfolders in the matrix package folders * Revert unnecessary eng/common changes * Rewrite GetPullRequestUrl to Get-BuildSourceDescription * Remove alias from Invoke-LoggedCommand * Use invoke-expression instead of shelling out * Add better job splitting * Replace Folder with Directory --------- Co-authored-by: Patrick Hallisey <[email protected]>
- Loading branch information
Showing
7 changed files
with
201 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
param( | ||
[string]$Variable, | ||
[switch]$IsOutput | ||
) | ||
|
||
$repoUrl = $env:BUILD_REPOSITORY_URI | ||
$sourceBranch = $env:BUILD_SOURCEBRANCH | ||
|
||
$description = "[$sourceBranch]($repoUrl/tree/$sourceBranch)" | ||
if ($sourceBranch -match "^refs/heads/(.+)$") { | ||
$description = "Branch: [$($Matches[1])]($repoUrl/tree/$sourceBranch)" | ||
} elseif ($sourceBranch -match "^refs/tags/(.+)$") { | ||
$description = "Tag: [$($Matches[1])]($repoUrl/tree/$sourceBranch)" | ||
} elseif ($sourceBranch -match "^refs/pull/(\d+)/(head|merge)$") { | ||
$description = "Pull request: $repoUrl/pull/$($Matches[1])" | ||
} | ||
|
||
if ($IsOutput) { | ||
Write-Host "Setting output variable '$Variable' to '$description'" | ||
Write-Host "##vso[task.setvariable variable=$Variable;isoutput=true]$description" | ||
} else { | ||
Write-Host "Setting variable '$Variable' to '$description'" | ||
Write-Host "##vso[task.setvariable variable=$Variable]$description" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function Invoke-LoggedCommand($Command, $ExecutePath, [switch]$GroupOutput) | ||
{ | ||
$pipelineBuild = !!$env:TF_BUILD | ||
$startTime = Get-Date | ||
|
||
if($pipelineBuild -and $GroupOutput) { | ||
Write-Host "##[group]$Command" | ||
} else { | ||
Write-Host "> $Command" | ||
} | ||
|
||
if($ExecutePath) { | ||
Push-Location $ExecutePath | ||
} | ||
|
||
try { | ||
Invoke-Expression $Command | ||
|
||
$duration = (Get-Date) - $startTime | ||
|
||
if($pipelineBuild -and $GroupOutput) { | ||
Write-Host "##[endgroup]" | ||
} | ||
|
||
if($LastExitCode -ne 0) | ||
{ | ||
if($pipelineBuild) { | ||
Write-Error "##[error]Command failed to execute ($duration): $Command`n" | ||
} else { | ||
Write-Error "Command failed to execute ($duration): $Command`n" | ||
} | ||
} | ||
else { | ||
Write-Host "Command succeeded ($duration)`n" | ||
} | ||
} | ||
finally { | ||
if($ExecutePath) { | ||
Pop-Location | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
[CmdLetBinding()] | ||
param ( | ||
[Parameter()] | ||
[string]$OutputDirectory, | ||
|
||
[Parameter()] | ||
[string]$OutputVariableName, | ||
|
||
[Parameter()] | ||
[int]$JobCount = 8, | ||
|
||
# The minimum number of items per job. If the number of items is less than this, then the number of jobs will be reduced. | ||
[Parameter()] | ||
[int]$MinimumPerJob = 10, | ||
|
||
[Parameter()] | ||
[string]$OnlyTypespec | ||
) | ||
|
||
. (Join-Path $PSScriptRoot common.ps1) | ||
|
||
[bool]$OnlyTypespec = $OnlyTypespec -in @("true", "t", "1", "yes", "y") | ||
|
||
# Divide the items into groups of approximately equal size. | ||
function Split-Items([array]$Items) { | ||
# given $Items.Length = 22 and $JobCount = 5 | ||
# then $itemsPerGroup = 4 | ||
# and $largeJobCount = 2 | ||
# and $group.Length = 5, 5, 4, 4, 4 | ||
$itemCount = $Items.Length | ||
$jobsForMinimum = $itemCount -lt $MinimumPerJob ? 1 : [math]::Floor($itemCount / $MinimumPerJob) | ||
|
||
if ($JobCount -gt $jobsForMinimum) { | ||
$JobCount = $jobsForMinimum | ||
} | ||
|
||
$itemsPerGroup = [math]::Floor($itemCount / $JobCount) | ||
$largeJobCount = $itemCount % $itemsPerGroup | ||
$groups = [object[]]::new($JobCount) | ||
|
||
$i = 0 | ||
for ($g = 0; $g -lt $JobCount; $g++) { | ||
$groupLength = if ($g -lt $largeJobCount) { $itemsPerGroup + 1 } else { $itemsPerGroup } | ||
$group = [object[]]::new($groupLength) | ||
$groups[$g] = $group | ||
for ($gi = 0; $gi -lt $groupLength; $gi++) { | ||
$group[$gi] = $Items[$i++] | ||
} | ||
} | ||
|
||
Write-Host "$itemCount items split into $JobCount groups of approximately $itemsPerGroup items each." | ||
|
||
return , $groups | ||
} | ||
|
||
# ensure the output directory exists | ||
New-Item -ItemType Directory -Path $OutputDirectory -Force | Out-Null | ||
|
||
if (Test-Path "Function:$GetDirectoriesForGenerationFn") { | ||
$directoriesForGeneration = &$GetDirectoriesForGenerationFn | ||
} | ||
else { | ||
$directoriesForGeneration = Get-ChildItem "$RepoRoot/sdk" -Directory | Get-ChildItem -Directory | ||
} | ||
|
||
if ($OnlyTypespec) { | ||
$directoriesForGeneration = $directoriesForGeneration | Where-Object { Test-Path "$_/tsp-location.yaml" } | ||
} | ||
|
||
[array]$packageDirectories = $directoriesForGeneration | ||
| Sort-Object -Property FullName | ||
| ForEach-Object { | ||
[ordered]@{ | ||
"PackageDirectory" = "$($_.Parent.Name)/$($_.Name)" | ||
"ServiceArea" = $_.Parent.Name | ||
} | ||
} | ||
|
||
$batches = Split-Items -Items $packageDirectories | ||
|
||
$matrix = [ordered]@{} | ||
for ($i = 0; $i -lt $batches.Length; $i++) { | ||
$batch = $batches[$i] | ||
$json = $batch.PackageDirectory | ConvertTo-Json -AsArray | ||
|
||
$firstPrefix = $batch[0].ServiceArea.Substring(0, 2) | ||
$lastPrefix = $batch[-1].ServiceArea.Substring(0, 2) | ||
|
||
$key = "$firstPrefix`_$lastPrefix`_$i" | ||
$fileName = "$key.json" | ||
|
||
Write-Host "`n`n==================================" | ||
Write-Host $fileName | ||
Write-Host "==================================" | ||
$json | Out-Host | ||
$json | Out-File "$OutputDirectory/$fileName" | ||
|
||
$matrix[$key] = [ordered]@{ "JobKey" = $key; "DirectoryList" = $fileName } | ||
} | ||
|
||
$compressed = ConvertTo-Json $matrix -Depth 100 -Compress | ||
Write-Output "##vso[task.setVariable variable=$OutputVariableName;isOutput=true]$compressed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[CmdLetBinding()] | ||
param( | ||
[Parameter(Mandatory)] | ||
[string]$PackageDirectoriesFile | ||
) | ||
|
||
. $PSScriptRoot/common.ps1 | ||
. $PSScriptRoot/Helpers/CommandInvocation-Helpers.ps1 | ||
|
||
$ErrorActionPreference = 'Stop' | ||
|
||
if (Test-Path "Function:$UpdateGeneratedSdksFn") { | ||
&$UpdateGeneratedSdksFn $PackageDirectoriesFile | ||
} else { | ||
Write-Error "Function $UpdateGeneratedSdksFn not implemented in Language-Settings.ps1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters