1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#Requires -Version 7.0
param(
[string]$filter,
[switch]$clean,
[switch]$vet,
[switch]$generate,
[switch]$skipBuild,
[switch]$cleanGenerated,
[switch]$format,
[switch]$tidy,
[string]$config = "autorest.md",
[string]$autorestVersion = "3.8.2",
[string]$goExtension = "@autorest/go@4.0.0-preview.41",
[string]$outputFolder
)
. (Join-Path $PSScriptRoot .. common scripts common.ps1)
function Process-Sdk ()
{
$currentDirectory = Get-Location
if ($clean)
{
Write-Host "##[command]Executing go clean -v ./... in " $currentDirectory
go clean -v ./...
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}
if ($cleanGenerated)
{
Write-Host "##[command]Cleaning auto-generated files in" $currentDirectory
Remove-Item "zz_generated_*"
}
if ($generate)
{
Write-Host "##[command]Executing autorest.go in " $currentDirectory
$autorestPath = "./" + $config
if ($outputFolder -eq '')
{
$outputFolder = $currentDirectory
}
autorest --version=$autorestVersion --use=$goExtension --go --track2 --output-folder=$outputFolder --file-prefix="zz_generated_" --clear-output-folder=false --go.clear-output-folder=false $autorestPath
if ($LASTEXITCODE)
{
Write-Host "##[error]Error running autorest.go"
exit $LASTEXITCODE
}
}
if ($format)
{
Write-Host "##[command]Executing gofmt -s -w . in " $currentDirectory
gofmt -s -w .
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}
if ($tidy)
{
Write-Host "##[command]Executing go mod tidy in " $currentDirectory
go mod tidy
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}
if (!$skipBuild)
{
Write-Host "##[command]Executing go build -v ./... in " $currentDirectory
go build -v ./...
Write-Host "##[command]Build Complete!"
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}
if ($vet)
{
Write-Host "##[command]Executing go vet ./... in " $currentDirectory
go vet ./...
}
}
try
{
$startingDirectory = Get-Location
$sdks = Get-AllPackageInfoFromRepo $filter
foreach ($sdk in $sdks)
{
Push-Location $sdk.DirectoryPath
Process-Sdk
Pop-Location
}
if ($sdks.Count -eq 0 -and $filter -and (Test-Path -Path (Join-Path $RepoRoot "sdk" $filter)))
{
Write-Host "Cannot find go module under $filter, try to build in $(Join-Path $RepoRoot "sdk" $filter)"
Push-Location (Join-Path $RepoRoot "sdk" $filter)
Process-Sdk
Pop-Location
}
}
finally
{
Set-Location $startingDirectory
}
|