-
Notifications
You must be signed in to change notification settings - Fork 822
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
Build.ps1 improvements #15017
Changes from all commits
aeba2bc
e30aa13
571016c
be31548
85af8fb
3974e70
acb98d7
475ab48
c1a1822
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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/...')) { | ||
$name = $sdk | split-path -leaf | ||
$sdks[$name] = @{ | ||
'path' = $sdk; | ||
'path' = $sdk; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} | ||
|
||
|
@@ -16,19 +24,33 @@ if (![string]::IsNullOrWhiteSpace($filter)) { | |
$keys = $keys.Where( { $_ -match $filter }) | ||
} | ||
|
||
$keys | ForEach-Object { $sdks[$_] } | ForEach-Object -Parallel { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ./... | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.