diff --git a/eng/scripts/build.ps1 b/eng/scripts/build.ps1 index 6b909c593505..e6d1daf45967 100644 --- a/eng/scripts/build.ps1 +++ b/eng/scripts/build.ps1 @@ -1,6 +1,8 @@ #Requires -Version 7.0 param($filter, [switch]$clean, [switch]$vet, [switch]$generate, [switch]$skipBuild) +. $PSScriptRoot/meta_generation.ps1 + $startingDirectory = Get-Location $root = Resolve-Path ($PSScriptRoot + "/../..") Set-Location $root @@ -34,11 +36,20 @@ $keys | ForEach-Object { $sdks[$_] } | ForEach-Object { if ($_.generate) { Write-Host "##[command]Executing autorest.go in " $_.path - $autorestPath = $_.path + "\autorest.md" + $autorestPath = $_.path + "/autorest.md" + + if (ShouldGenerate-AutorestConfig $autorestPath) { + Generate-AutorestConfig $autorestPath + $removeAutorestFile = $true + } + $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 ($removeAutorestFile) { + Remove-Item $autorestPath + } } if (!$_.skipBuild) { Write-Host "##[command]Executing go build -v ./... in " $_.path diff --git a/eng/scripts/meta_generation.ps1 b/eng/scripts/meta_generation.ps1 new file mode 100644 index 000000000000..8b9e55753bd7 --- /dev/null +++ b/eng/scripts/meta_generation.ps1 @@ -0,0 +1,21 @@ +function ShouldGenerate-AutorestConfig([string]$autorestPath) { + $metaPath = $autorestPath.Replace("autorest.md", "_meta.json") + return !(Test-Path $autorestPath -PathType Leaf) -and (Test-Path $metaPath -PathType Leaf) +} + +function Generate-AutorestConfig([string]$autorestPath) { + $metaPath = $autorestPath.Replace("autorest.md", "_meta.json") + $meta = Get-Content $metaPath | ConvertFrom-Json + $readme = "https://github.com/Azure/azure-rest-api-specs/blob/" + $meta.commit + $meta.readme.Split("/azure-rest-api-specs")[1]; + + $contents = @' +### AutoRest Configuration +> see https://aka.ms/autorest +``` yaml +tag: {0} +require: +- {1} +``` +'@; + $contents -f $meta.tag, $readme | Out-File -FilePath $autorestPath +} \ No newline at end of file