Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build.ps1 improvements #15017

Merged
merged 9 commits into from
Jul 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions eng/scripts/build.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#Requires -Version 7.0
param($filter, [switch]$vet, [switch]$generate, [switch]$skipBuild, $parallel = 5)
param($filter, [switch]$clean, [switch]$vet, [switch]$generate, [switch]$skipBuild)

$startingDirectory = Get-Location
$root = Resolve-Path ($PSScriptRoot + "/../..")
Set-Location $root
$sdks = @{};

foreach ($sdk in (./eng/scripts/get_module_dirs.ps1 -serviceDir 'sdk/...')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters much right now, but depending on whether get_module_dirs is also called outside of powershell, it may be a better pattern (for readability, maintenance, etc.) to import functions from this as a module instead of calling out to the scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to this, i just didn't know you could do that.

$name = $sdk | split-path -leaf
$sdks[$name] = @{
'path' = $sdk;
'path' = $sdk;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an intent to eventually have sdk/local config specific values for these instead of using the ones in the global scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally needed to do this when it was parallel because the global scope variables were empty FWICT.

Now that it is not parallel, I guess it is not needed.

'clean' = $clean;
'vet' = $vet;
'generate' = $generate;
'skipBuild' = $skipBuild;
'root' = $root;
}
}

Expand All @@ -16,19 +24,33 @@ if (![string]::IsNullOrWhiteSpace($filter)) {
$keys = $keys.Where( { $_ -match $filter })
}

$keys | ForEach-Object { $sdks[$_] } | ForEach-Object -Parallel {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is no longer parallel, will this fail fast on the first codegen/build failure, or still run through all of them (might be cumbersome to go through new build/codegen failures run by run as opposed to getting them all at once).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will fail on first one I believe.

$keys | ForEach-Object { $sdks[$_] } | ForEach-Object {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my above comment, the script is small right now so I don't think it matters, but I would consider moving all the script logic into various functions before it gets too large. At least on the engsys side we have some really hard to maintain scripts right now that have grown very large without any refactoring.

Push-Location $_.path

if (!$skipBuild) {
if ($_.clean) {
Write-Host "##[command]Executing go clean -v ./... in " $_.path
go clean -v ./...
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the number of newlines between if blocks don't match.

if ($_.generate) {
Write-Host "##[command]Executing autorest.go in " $_.path
$autorestPath = $_.path + "\autorest.md"
$autorestVersion = "@autorest/go@4.0.0-preview.23"
$outputFolder = $_.path
$root = $_.root
autorest --use=$autorestVersion --go --track2 --go-sdk-folder=$root --output-folder=$outputFolder --file-prefix="zz_generated_" --clear-output-folder=false $autorestPath
}
if (!$_.skipBuild) {
Write-Host "##[command]Executing go build -v ./... in " $_.path
go build -v ./...
go build -x -v ./...
Write-Host "##[command]Build Complete!"

}
if ($vet) {
if ($_.vet) {
Write-Host "##[command]Executing go vet ./... in " $_.path
go vet ./...
}
if ($generate) {
Write-Host "##[command]Executing autorest.go in " $_.path
# TODO
}
} -ThrottleLimit $parallel
Pop-Location
}

Set-Location $startingDirectory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my above comment re: fail fast, is the script intended to be run with ErrorAction Continue? If not, it will dump you out into a sub-directory on failure (assuming it's ever intended to be ran locally).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will dump you in a subdirectory on failure, and this is bad.