Skip to content

.Platform - Publish [moduleIndex.json] #145

.Platform - Publish [moduleIndex.json]

.Platform - Publish [moduleIndex.json] #145

# 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:
inputs:
regenIndexFromBRM:
type: boolean
description: "regenIndexFromBRM | Regenerate the moduleIndex.json file from scratch based on what is in BRM at the time of the run, instead of integrating it with its previous version."
required: false
default: false
permissions:
id-token: write
contents: read
env:
workflowPath: ".github/workflows/avm.res.app.job.yml"
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: "Set input parameter``s to output variables"
id: get-workflow-param
uses: ./.github/actions/templates/avm-getWorkflowInput
with:
workflowPath: "${{ env.workflowPath}}"
- 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'
}
if ('${{ (fromJson(steps.get-workflow-param.outputs.workflowInput)).regenIndexFromBRM }}' -eq $true ) {
$functionInput['doNotMergeWithLastModuleIndexJsonFileVersion'] = $true
}
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/[email protected]
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."