forked from Azure-Samples/function-app-arm-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkflow.yml
64 lines (53 loc) · 3.02 KB
/
workflow.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: Build and deploy dotnet core app to Azure Function App - cp-win-dotnet
on:
push:
branches:
- main
workflow_dispatch:
env:
AZURE_RESOURCE_GROUP: 'your-resource-group-name' # set this to your Azure Resource group's name
FUNCTION_APP: 'your-function-app-name' # set this to your Azure Function app's name
STORAGE_ACCOUNT: 'new-storage-for-deployment' # storage will be created for deployment if not exists. Requirements: unique name, 3 to 24 characters in length, use numbers and lower-case letters only
CONTAINER: 'temporarydeploymentcontainer' # temporary container needed for deployment, can keep name as it is
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '6.0.x' # set this to the dotnet version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Checkout GitHub Action
uses: actions/checkout@v2
- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Resolve Project Dependencies Using Dotnet
shell: pwsh
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet build --configuration Release --output ./output
popd
- name: Zip Function App Content
shell: pwsh
run: |
Compress-Archive -Path ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output/* -DestinationPath ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/package.zip
- name: Setup Storage, Container & Blob for Deployment
shell: pwsh
run: |
az storage account create -n ${{ env.STORAGE_ACCOUNT }} -g ${{ env.AZURE_RESOURCE_GROUP }}
az storage container create -n ${{ env.CONTAINER }} --account-name ${{ env.STORAGE_ACCOUNT }}
az storage blob upload -f ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/package.zip --account-name ${{ env.STORAGE_ACCOUNT }} -c ${{ env.CONTAINER }} -n package.zip --overwrite true
- name: Zip Deployment using ARM Template
shell: pwsh
run: |
$Env:Expiry=(get-date).AddMinutes(30).ToString("yyyy-MM-ddTHH:mm:ssZ")
$Env:ZIP_URL=$(az storage blob generate-sas --full-uri --permissions r --expiry $Env:Expiry --account-name ${{ env.STORAGE_ACCOUNT }} -c ${{ env.CONTAINER }} -n package.zip)
az deployment group create --name deploy --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --template-file azuredeploy.json --parameters functionAppName='${{ env.FUNCTION_APP }}' packageUri=$Env:ZIP_URL
- name: Delete Temporary Container & Blob
shell: pwsh
run: |
az storage container delete -n ${{ env.CONTAINER }} --account-name ${{ env.STORAGE_ACCOUNT }}