Deploy All Functions to Azure #7
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
# GitHub action that builds and deploys an Azure Function App | |
# Author: Francisco Leyva | |
name: Deploy All Functions to Azure | |
# Controls when the workflow will run | |
on: | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
# Update API Manager with the function endpoints (OpenAPI) | |
update_api: | |
type: boolean | |
required: true | |
default: false | |
description: Update API Endpoints | |
env: | |
DOTNET_VERSION: '8.0.x' # set this to the dotnet version to use | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This job builds and deploy an azure function to Azure | |
build-and-deploy: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
# Functions configurations | |
strategy: | |
matrix: | |
include: | |
- function_name: 'fn-liquid-dev' | |
package_path: 'LiquidFunctions' | |
- function_name: 'fn-solid-dev' | |
package_path: 'SolidFunctions' | |
- function_name: 'fn-solidus-dev' | |
package_path: 'SolidusFunctions' | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v4 | |
# Login to Azure using secrets credentials | |
- name: 'Login via Azure CLI' | |
uses: Azure/login@v2.1.1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} # Your Azure credentials | |
# Setup dotnet command | |
- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: ${{ env.DOTNET_VERSION }} | |
# Build Azure Function | |
- name: 'Run dotnet' | |
shell: pwsh | |
run: | | |
pushd './${{ matrix.package_path }}' | |
dotnet build --configuration Release --output ./output | |
popd | |
# Deploy build to Azure function app environment | |
- name: 'Run Azure Functions Action' | |
uses: Azure/functions-action@v1.5.2 | |
with: | |
app-name: ${{ matrix.function_name }} | |
package: '${{ matrix.package_path }}/output' | |
# Azure logout | |
- name: logout | |
run: | | |
az logout | |
if: always() | |
# This job updates the Azure (APIM) API with the OpenAPI definition file | |
# coming from the Azure Function | |
update-api: | |
needs: build-and-deploy | |
if: inputs.update_api | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
# API Management configuration for each function (optional) | |
strategy: | |
matrix: | |
include: | |
- azure_api_id: 'liquid-api' | |
azure_api_path: '/liquid' | |
azure_api_name: 'Liquid API' | |
azure_api_spec_url: 'https://fn-liquid-dev.azurewebsites.net/api/openapi/v3.json' | |
- azure_api_id: 'solid-api' | |
azure_api_path: '/solid' | |
azure_api_name: 'Solid API' | |
azure_api_spec_url: 'https://fn-solid-dev.azurewebsites.net/api/openapi/v3.json' | |
- azure_api_id: 'solidus-api' | |
azure_api_path: '/solidus' | |
azure_api_name: 'Solidus API' | |
azure_api_spec_url: 'https://fn-solidus-dev.azurewebsites.net/api/openapi/v3.json' | |
# Azure API Import configuration | |
env: | |
AZURE_RG: ${{ secrets.AZURE_RESOURCE_GROUP }} # Resource group name | |
AZURE_API_SERVICE: ${{ secrets.AZURE_API_MANAGER }} # API Manager ID | |
AZURE_API_ID: ${{ matrix.azure_api_id }} | |
AZURE_API_PATH: ${{ matrix.azure_api_path }} | |
AZURE_API_NAME: ${{ matrix.azure_api_name }} | |
AZURE_API_SPEC_URL: ${{ matrix.azure_api_spec_url }} | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Login to Azure using secrets credentials | |
- name: 'Login via Azure CLI' | |
uses: Azure/login@v2.1.1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
# Run Azure CLI command to import an API definition from an OpenID definition file | |
- name: Run Azure API Import (CLI) | |
run: | | |
az apim api import --path $AZURE_API_PATH --api-id $AZURE_API_ID -g $AZURE_RG -n $AZURE_API_SERVICE --display-name "$AZURE_API_NAME" --specification-url "$AZURE_API_SPEC_URL" --specification-format OpenAPI --protocols https | |
# Azure logout | |
- name: logout | |
run: | | |
az logout | |
if: always() |