diff --git a/.github/scripts/build-recommendation-object.ps1 b/.github/scripts/build-recommendation-object.ps1 new file mode 100644 index 00000000..5f7798de --- /dev/null +++ b/.github/scripts/build-recommendation-object.ps1 @@ -0,0 +1,38 @@ +import-module powershell-yaml -force -scope CurrentUser + +function Build-APRLJsonObject { + param ( + [string]$path + ) + + $kqlfiles = Get-ChildItem -Path $path -Recurse -Filter "*.kql" + $yamlfiles = Get-ChildItem -Path $path -Recurse -Filter "*.yaml" + + $yamlobj = foreach($file in $yamlfiles){ + $content = Get-Content $file.FullName -Raw | ConvertFrom-Yaml + $content | Select-Object publishedToAdvisor,aprlGuid,recommendationTypeId,recommendationMetadataState,learnMoreLink,recommendationControl,longDescription,pgVerified,description,potentialBenefits,publishedToLearn,tags,recommendationResourceType,recommendationImpact,automationAvailable,query + } + + $kqlobj = foreach($file in $kqlfiles){ + $content = Get-Content $file.FullName -Raw + [PSCustomObject]@{ + AprlGUID = $file.Name -replace ".kql","" + Query = $content + } + } + + $aprlobj = foreach($obj in $yamlobj){ + $obj.query = $($kqlobj.Where{$_.AprlGUID -eq $obj.aprlGuid}).Query + $obj + } + return $aprlobj +} + +try{ + Build-APRLJsonObject -path "./azure-resources" | ConvertTo-Json -Depth 10 | Out-File -FilePath "./tools/data/recommendations.json" -Force + exit 0 +} +catch{ + Write-Error $_.Exception.Message + exit 1 +} diff --git a/.github/workflows/build-recommendation-object.yml b/.github/workflows/build-recommendation-object.yml new file mode 100644 index 00000000..aa4a4196 --- /dev/null +++ b/.github/workflows/build-recommendation-object.yml @@ -0,0 +1,19 @@ +name: Nightly Recommendation Object Build + +on: + schedule: + - cron: "0 0 * * *" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + ref: main + + - name: Run Recommendation Object Builder + run: | + pwsh .github/scripts/build-recommendation-object.ps1