From 7230f4167ca4dafdb7ee4f812c9660813b897e3e Mon Sep 17 00:00:00 2001 From: Chris Hamons Date: Wed, 21 Jul 2021 13:21:10 -0500 Subject: [PATCH 1/4] [build.ps1] Add support for converting _meta.json to autorest.md during build --- eng/scripts/build.ps1 | 13 ++++++++++++- eng/scripts/meta_generation.ps1 | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 eng/scripts/meta_generation.ps1 diff --git a/eng/scripts/build.ps1 b/eng/scripts/build.ps1 index 6b909c593505..16b661e8100c 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 @@ -35,10 +37,19 @@ $keys | ForEach-Object { $sdks[$_] } | ForEach-Object { if ($_.generate) { Write-Host "##[command]Executing autorest.go in " $_.path $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 @@ -53,4 +64,4 @@ $keys | ForEach-Object { $sdks[$_] } | ForEach-Object { Pop-Location } -Set-Location $startingDirectory +Set-Location $startingDirectory \ No newline at end of file diff --git a/eng/scripts/meta_generation.ps1 b/eng/scripts/meta_generation.ps1 new file mode 100644 index 000000000000..06ecddafc0ef --- /dev/null +++ b/eng/scripts/meta_generation.ps1 @@ -0,0 +1,27 @@ +function ShouldGenerate-AutorestConfig { + Param( + [string] $autorestPath + ) + $metaPath = $autorestPath.Replace("autorest.md", "_meta.json") + return !(Test-Path $autorestPath -PathType Leaf) && (Test-Path $metaPath -PathType Leaf) +} + +function Generate-AutorestConfig { + Param( + [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 From 738d9de8185d34d8eb8ed00f1f40f4eb96717ac8 Mon Sep 17 00:00:00 2001 From: Chris Hamons Date: Wed, 21 Jul 2021 15:54:52 -0500 Subject: [PATCH 2/4] Code review changes --- eng/scripts/build.ps1 | 4 ++-- eng/scripts/meta_generation.ps1 | 12 +++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/eng/scripts/build.ps1 b/eng/scripts/build.ps1 index 16b661e8100c..afb91cb4cd9d 100644 --- a/eng/scripts/build.ps1 +++ b/eng/scripts/build.ps1 @@ -1,7 +1,7 @@ #Requires -Version 7.0 param($filter, [switch]$clean, [switch]$vet, [switch]$generate, [switch]$skipBuild) -. $PSScriptRoot\meta_generation.ps1 +. $PSScriptRoot/meta_generation.ps1 $startingDirectory = Get-Location $root = Resolve-Path ($PSScriptRoot + "/../..") @@ -38,7 +38,7 @@ $keys | ForEach-Object { $sdks[$_] } | ForEach-Object { Write-Host "##[command]Executing autorest.go in " $_.path $autorestPath = $_.path + "\autorest.md" - if (ShouldGenerate-AutorestConfig($autorestPath) ) { + if (ShouldGenerate-AutorestConfig $autorestPath) { Generate-AutorestConfig($autorestPath) $removeAutorestFile = $true } diff --git a/eng/scripts/meta_generation.ps1 b/eng/scripts/meta_generation.ps1 index 06ecddafc0ef..8b9e55753bd7 100644 --- a/eng/scripts/meta_generation.ps1 +++ b/eng/scripts/meta_generation.ps1 @@ -1,15 +1,9 @@ -function ShouldGenerate-AutorestConfig { - Param( - [string] $autorestPath - ) +function ShouldGenerate-AutorestConfig([string]$autorestPath) { $metaPath = $autorestPath.Replace("autorest.md", "_meta.json") - return !(Test-Path $autorestPath -PathType Leaf) && (Test-Path $metaPath -PathType Leaf) + return !(Test-Path $autorestPath -PathType Leaf) -and (Test-Path $metaPath -PathType Leaf) } -function Generate-AutorestConfig { - Param( - [string] $autorestPath - ) +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]; From 738d01ced09b0d4aa310da2c9b8187b18a9275da Mon Sep 17 00:00:00 2001 From: Chris Hamons Date: Wed, 21 Jul 2021 16:10:22 -0500 Subject: [PATCH 3/4] Remove another set of parens --- eng/scripts/build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/build.ps1 b/eng/scripts/build.ps1 index afb91cb4cd9d..6ef3644c8aba 100644 --- a/eng/scripts/build.ps1 +++ b/eng/scripts/build.ps1 @@ -39,7 +39,7 @@ $keys | ForEach-Object { $sdks[$_] } | ForEach-Object { $autorestPath = $_.path + "\autorest.md" if (ShouldGenerate-AutorestConfig $autorestPath) { - Generate-AutorestConfig($autorestPath) + Generate-AutorestConfig $autorestPath $removeAutorestFile = $true } From 6fdff07e70521f66bdba1ff6840ef58acc7a84df Mon Sep 17 00:00:00 2001 From: Chris Hamons Date: Thu, 22 Jul 2021 13:17:54 -0500 Subject: [PATCH 4/4] Update eng/scripts/build.ps1 Co-authored-by: Ben Broderick Phillips --- eng/scripts/build.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/scripts/build.ps1 b/eng/scripts/build.ps1 index 6ef3644c8aba..e6d1daf45967 100644 --- a/eng/scripts/build.ps1 +++ b/eng/scripts/build.ps1 @@ -36,7 +36,7 @@ $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 @@ -64,4 +64,4 @@ $keys | ForEach-Object { $sdks[$_] } | ForEach-Object { Pop-Location } -Set-Location $startingDirectory \ No newline at end of file +Set-Location $startingDirectory