Skip to content

Azure Bicep Provision and Deploy #43

Azure Bicep Provision and Deploy

Azure Bicep Provision and Deploy #43

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:
DOTNET_VERSION: '8.0'
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
# 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
# Get the output params of the Bicep deployment
- name: Get Output Parameters
id: get-output-params
run: |
echo "STATIC_WEB_APP_NAME=$(echo '${{ steps.bicep.outputs }}' | jq -r '.staticSiteName')" >> $GITHUB_ENV
echo "AZURE_FUNCTIONAPP_NAME=$(echo '${{ steps.bicep.outputs }}' | jq -r '.functionAppName')" >> $GITHUB_ENV
# Deploy to Azure Functions
- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- 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: |
echo "AZURE_FUNCTIONAPP_PUBLISH_PROFILE=$(az functionapp deployment list-publishing-profiles --name ${{ env.AZURE_FUNCTIONAPP_NAME }} --resource-group ${{ vars.RESOURCE_GROUP_NAME }} --query "[?publishMethod=='MSDeploy'].{publishUrl:publishUrl,userName:userName,userPWD:userPWD}" -o tsv)" >> $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 ${{ vars.STATIC_WEB_APP_NAME }} --resource-group ${{ vars.RESOURCE_GROUP_NAME }} --query "properties.apiKey" -o tsv)
echo "STATIC_WEB_APP_TOKEN=$TOKEN" >> $GITHUB_ENV
# Deploy to Azure Static Web Apps
- 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 -c Release'
# Logout of Azure
- name: Logout of Azure
run: |
az logout