Skip to content

Azure Bicep Provision and Deploy #66

Azure Bicep Provision and Deploy

Azure Bicep Provision and Deploy #66

name: Azure Bicep Provision and Deploy
on: workflow_dispatch
jobs:
#====== Provision and Deploy ======#
provision_and_deploy:
name: "Provision and Deploy"
runs-on: ubuntu-latest
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: 'src/Azure.Functions'
steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
# Login to Azure
- name: Login to Azure
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# Register Resource Providers
- name: Register Resource Providers
run: |
az provider register --namespace Microsoft.SignalRService
az provider register --namespace Microsoft.Storage
az provider register --namespace Microsoft.Web
# Generate a new GUID
- name: Generate New GUID
id: generate-guid
run: echo "guid=$(uuidgen)" >> $GITHUB_ENV
# Deploy Bicep template
- name: Deploy Bicep Template
id: bicep
uses: azure/arm-deploy@v2
with:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
scope: subscription
region: ${{ vars.RESOURCE_LOCATION }}
template: ./infra/bicep/main.bicep
failOnStdErr: true
deploymentName: 'bicep-deployment-${{ env.guid }}'
# Get the output params of the Bicep deployment
- name: Get Output Parameters
id: get-output-params
run: |
echo "STATIC_WEB_APP_NAME=${{ steps.bicep.outputs.staticSiteName }}" >> $GITHUB_ENV
echo "AZURE_FUNCTIONAPP_NAME=${{ steps.bicep.outputs.functionAppName }}" >> $GITHUB_ENV
echo "RESOURCE_GROUP_NAME=${{ steps.bicep.outputs.newResourceGroupName }}" >> $GITHUB_ENV
echo "AZURE_FUNCTIONAPP_ENDPOINT=${{ steps.bicep.outputs.functionAppEndpoint }}" >> $GITHUB_ENV
# Deploy to Azure Functions
- name: Setup DotNet 8.0 Environment
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0
- name: 'Resolve Project Dependencies Using Dotnet'
shell: bash
run: |
dotnet restore ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet build --configuration Release --output ./output
popd
# Get Azure Functions Publish Profile
- name: Get Azure Functions Publish Profile
id: get-publish-profile
run: |
az functionapp deployment list-publishing-profiles --name ${{ env.AZURE_FUNCTIONAPP_NAME }} --resource-group ${{ env.RESOURCE_GROUP_NAME }} --xml > publishProfile.xml
echo "AZURE_FUNCTIONAPP_PUBLISH_PROFILE=$(cat publishProfile.xml)" >> $GITHUB_ENV
- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output'
publish-profile: ${{ env.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
# Get Azure Static Web App deployment token
- name: Get Azure Static Web App deployment token
id: get-token
run: |
TOKEN=$(az staticwebapp secrets list --name ${{ env.STATIC_WEB_APP_NAME }} --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "properties.apiKey" -o tsv)
echo "STATIC_WEB_APP_TOKEN=$TOKEN" >> $GITHUB_ENV
# Update appsettings.json with Function App endpoint
- name: Update appsettings.json
run: |
jq --arg endpoint "https://${{ env.AZURE_FUNCTIONAPP_ENDPOINT }}/api" '.SignalR.Url = $endpoint' src/Blazor.WebAssembly/wwwroot/appsettings.json > tmp.$$.json && mv tmp.$$.json src/Blazor.WebAssembly/wwwroot/appsettings.json
- name: Display updated appsettings.json
run: cat src/Blazor.WebAssembly/wwwroot/appsettings.json
# Deploy to Azure Static Web Apps
- name: Setup DotNet 9.0 Environment
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0
- name: Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ env.STATIC_WEB_APP_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: 'upload'
app_location: '/src/Blazor.WebAssembly'
output_location: 'wwwroot'
app_build_command: 'dotnet publish src/Blazor.WebAssembly -c Release -o src/Blazor.WebAssembly/wwwroot'
# Verify the contents of the publish directory
- name: Verify publish directory contents
run: ls -R src/Blazor.WebAssembly/wwwroot
# Logout of Azure
- name: Logout of Azure
run: |
az logout