Skip to content

Commit c38d3eb

Browse files
authored
Create deploy_solid_functions.yml
1 parent 275123f commit c38d3eb

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# GitHub action that builds and deploys an Azure Function App
2+
# Author: Francisco Leyva
3+
name: Deploy Solid Functions to Azure
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the "main" branch
8+
push:
9+
branches: [ "main" ]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
inputs:
14+
# Update API Manager with the function endpoints (OpenAPI)
15+
update_api:
16+
type: boolean
17+
required: true
18+
default: false
19+
description: Update API Endpoints
20+
21+
env:
22+
# Azure functions configuration
23+
AZURE_FUNCTIONAPP_NAME : 'fn-solid-dev'
24+
AZURE_FUNCTIONAPP_PACKAGE_PATH: 'SolidFunctions' # set this to the path to your web app project, defaults to the repository root
25+
DOTNET_VERSION: '6.0.x' # set this to the dotnet version to use
26+
27+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
28+
jobs:
29+
# This job builds and deploy an azure function to Azure
30+
build-and-deploy:
31+
# The type of runner that the job will run on
32+
runs-on: ubuntu-latest
33+
34+
# Steps represent a sequence of tasks that will be executed as part of the job
35+
steps:
36+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
37+
- uses: actions/checkout@v3
38+
39+
# Login to Azure using secrets credentials
40+
- name: 'Login via Azure CLI'
41+
uses: azure/login@v1
42+
with:
43+
creds: ${{ secrets.AZURE_CREDENTIALS }} # Your Azure credentials
44+
45+
# Setup dotnet command
46+
- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment
47+
uses: actions/setup-dotnet@v3
48+
with:
49+
dotnet-version: ${{ env.DOTNET_VERSION }}
50+
51+
# Build Azure Function
52+
- name: 'Run dotnet'
53+
shell: pwsh
54+
run: |
55+
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
56+
dotnet build --configuration Release --output ./output
57+
popd
58+
# Deploy build to Azure function app environment
59+
- name: 'Run Azure Functions Action'
60+
uses: Azure/functions-action@v1
61+
with:
62+
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
63+
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output'
64+
65+
# Azure logout
66+
- name: logout
67+
run: |
68+
az logout
69+
if: always()
70+
71+
# This job updates the Azure (APIM) API with the OpenAPI definition file
72+
# coming from the Azure Function
73+
update-api:
74+
needs: build-and-deploy
75+
if: inputs.update_api
76+
# The type of runner that the job will run on
77+
runs-on: ubuntu-latest
78+
79+
# Azure API Import configuration (optional)
80+
env:
81+
AZURE_RG: ${{ secrets.AZURE_RESOURCE_GROUP }} # Resource group name
82+
AZURE_API_SERVICE: ${{ secrets.AZURE_API_MANAGER }} # API Manager ID
83+
AZURE_API_ID: 'solid-api'
84+
AZURE_API_PATH: '/solid'
85+
AZURE_API_NAME: 'Solid API'
86+
AZURE_API_SPEC_URL: 'https://fn-solid-dev.azurewebsites.net/api/openapi/v3.json'
87+
88+
# Steps represent a sequence of tasks that will be executed as part of the job
89+
steps:
90+
# Login to Azure using secrets credentials
91+
- name: 'Login via Azure CLI'
92+
uses: azure/login@v1
93+
with:
94+
creds: ${{ secrets.AZURE_CREDENTIALS }}
95+
96+
# Run Azure CLI command to import an API definition from an OpenID definition file
97+
- name: Run Azure API Import (CLI)
98+
run: |
99+
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
100+
101+
# Azure logout
102+
- name: logout
103+
run: |
104+
az logout
105+
if: always()

0 commit comments

Comments
 (0)