.Platform - Publish [moduleIndex.json] #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This publishes the list of all public bicep modules to an index file that the Bicep vscode extension can read for intellisense using pwsh | |
name: .Platform - Publish [moduleIndex.json] | |
on: | |
schedule: | |
- cron: 45 11 * * * # Run daily at 3:45 AM PST | |
workflow_dispatch: | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
upload-index-data: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 // Needed to fetch all history and tags | |
- name: Log in to Azure | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ secrets.PUBLISH_CLIENT_ID }} | |
tenant-id: ${{ secrets.PUBLISH_TENANT_ID }} | |
subscription-id: ${{ secrets.PUBLISH_SUBSCRIPTION_ID }} | |
enable-AzPSSession: true | |
- name: Install Azure Powershell Modules | |
shell: pwsh | |
run: | | |
if(-not (Get-Module 'Az.Storage' -ListAvailable)) { | |
Install-Module -Name 'Az.Storage' -Force | |
} | |
- name: Generate moduleIndex.json | |
shell: pwsh | |
run: | | |
# Load used functions | |
. (Join-Path $env:GITHUB_WORKSPACE 'avm' 'utilities' 'pipelines' 'platform' 'Invoke-AvmJsonModuleIndexGeneration.ps1') | |
$functionInput = @{ | |
storageAccountName = 'biceplivedatasaprod' | |
storageAccountContainer = 'bicep-cdn-live-data-container' | |
storageBlobName = 'module-index' | |
moduleIndexJsonFilePath = 'moduleIndex.json' | |
prefixForLastModuleIndexJsonFile = 'last-' | |
prefixForCurrentGeneratedModuleIndexJsonFile = 'generated-' | |
ErrorAction = 'Continue' | |
} | |
Write-Verbose "Invoke task with" -Verbose | |
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose | |
if(-not (Invoke-AvmJsonModuleIndexGeneration @functionInput)) { | |
Write-Output ('{0}={1}' -f 'anyErrorsOccurred', $true) >> $env:GITHUB_ENV | |
} | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: publish-module-index-json-artifacts | |
path: | | |
moduleIndex.json | |
last-moduleIndex.json | |
generated-moduleIndex.json | |
- name: Upload to blob storage | |
shell: pwsh | |
run: | | |
$storageAccountInfo = @{ | |
storageAccountName = 'biceplivedatasaprod' | |
storageAccountContainer = 'bicep-cdn-live-data-container' | |
storageBlobName = 'module-index' | |
storageBlobContentType = @{'ContentType' = 'application/json'} | |
} | |
Write-Verbose ('Uploading [moduleIndex.json] to blob storage account [{0}] in container [{1}] as blob [{2}]' -f $storageAccountInfo.storageAccountName, $storageAccountInfo.storageAccountContainer, $storageAccountInfo.storageBlobName) -Verbose | |
$storageContext = New-AzStorageContext -StorageAccountName $storageAccountInfo.storageAccountName -UseConnectedAccount | |
$functionInput = @{ | |
Context = $storageContext | |
Container = $storageAccountInfo.storageAccountContainer | |
Blob = $storageAccountInfo.storageBlobName | |
File = 'moduleIndex.json' | |
Properties = $storageAccountInfo.storageBlobContentType | |
} | |
Set-AzStorageBlobContent @functionInput -Force | |
Write-Verbose ('Upload of [{0}] complete.' -f $storageAccountInfo.storageBlobName) -Verbose | |
- name: Check if any errors occurred during 'Generate moduleIndex.json' | |
if: ${{ env.anyErrorsOccurred == 'true' }} | |
shell: pwsh | |
run: | | |
throw "Errors occurred during 'Generate moduleIndex.json' step. Please check the logs of that step in the workflow." |