Skip to content

Commit

Permalink
[build.ps1] Add support for converting _meta.json to autorest.md duri…
Browse files Browse the repository at this point in the history
…ng build (Azure#15111)
  • Loading branch information
chamons authored and vindicatesociety committed Sep 18, 2021
1 parent c9502ef commit a2f75a9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
13 changes: 12 additions & 1 deletion eng/scripts/build.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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/[email protected]"
$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
Expand Down
21 changes: 21 additions & 0 deletions eng/scripts/meta_generation.ps1
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a2f75a9

Please sign in to comment.