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