GitHub has opened the doors for meaningful collaboration across the wider software development community. As a GitHub user, you can truly make great use of its diverse ecosystem and leverage the wonderful features that it has to offer, including ‘GitHub Actions’, which is a powerful workflow engine that enables developers to automate repetitive tasks. In this blog, we dive deeper into the ways of configuring an automated GitHub Actions deployment pipeline.
The High-level Approach
There are a few steps involved in this configuration process., they are as follows:
1. First, we create a new ‘Azure AD App Registration’. This will enable GitHub Action deployment pipeline to authenticate with Azure (using App Registration credentials).
2. Then, we create a new ‘Secret’ in GitHub repo containing the ‘Azure AD App Registration’ credentials.
3. Then, create an ‘Azure Function App ARM’ template which will create the ‘Function App’ resource in Azure.
4. And finally, create a ‘GitHub Actions Workflow’ file to execute the ARM template and subsequently deploy the Azure Function code.
Create the Azure Function
We begin by creating a basic HTTP Azure Function (C#) that we’ll be deploying to Azure.
Create the Azure AD App Registration
The GitHub Actions workflow will first need to authenticate with Azure before it can begin deploying our code. Therefore, we must generate a new ‘Azure AD App Registration’ and then fetch the credentials for it.
So, let us head over to the Azure Portal and run the following command in the ‘Azure Bash Cloud Shell’ to register a new Azure AD application. Once completed, your new App Registration will be visible under AZURE ACTIVE DIRECTORY > APP REGISTRATIONS.
.png)
.png)
At this point, we will receive a JSON response containing the secret credentials. Make sure to retain this securely as you won’t be able to retrieve this later. Furthermore, this will be essential for the next step.
.png)
Create GitHub Repo Secret
Now let us store these credentials in the GitHub repo. We do this by heading over to our GitHub repo (i.e., the same repo where your Azure Function code is stored) and creating a ‘Secret’ containing the JSON response from the previous step.
.png)
Generate Azure Function App ARM Template
Now, we generate an ARM template through the Azure Portal. This template will create an empty ‘Azure Function App’ resource in Azure.
In the Azure Portal, we create a new Function App resource. At the ‘Review + create’ screen, click ‘Download a template for automation’. This option will auto-generate the ARM template (including the Template and Parameters file) which needs to be stored in the GitHub code repository. It will be referenced from our GitHub Actions workflow file later.
.png)
.png)
.png)
.png)
GitHub Actions 101
GitHub Actions workflows are defined using YAML files to define triggers, jobs and associated steps that need to be performed. These YAML files must be stored in GitHub repo alongside code in the following directory.
.github/workflows
Here’s a sample of what a YAML file looks like:
.png)
Create the GitHub Actions Workflow File
Now we need to create the Github Actions workflow file. We will create a GitHub Actions *.yml workflow file that will perform the following high-level steps:
1. Create the empty Azure Function App resource using our ARM template that we created before
2. Build and package the C# Azure Function code
3. Deploy your code to the Azure Function App
.png)
This first section of the script specifies the following:
- Defines the triggers that will cause this workflow to fire. This workflow will execute when someone pushes a new commit to the ‘master’ branch of this repository.
- Then define various the environment variables. Note here that we would need to update the following:
- ‘AZURE_RESOURCE_GROUP_NAME’: Specifies the ‘Resource Group’ where the Function App will reside.
- ‘AZURE_FUNCTIONAPP_NAME’: Specifies the name of the ‘Function App Resource’ that will be created. This must match the ARM template.
- ‘AZURE_FUNCTIONAPP_PACKAGE_PATH’: Path to the ‘Azure Function’ code.
- And finally, since GitHub supports numerous command line shells, we will use the ‘bash shell’ as the default choice, unless otherwise specified within a given circumstance.
.png)
In the next section, we create a job named ‘deploy-az-infrastructure' which will execute the ARM template to create the ‘Azure Function App’ resource.
.png)
The ‘build-az-function' job will then build the code, create a zip package, and finally store the zip artefact for later use. This job will only be executed after the ‘deploy-az-infrastructure' job has finished running.
.png)
.png)
The ‘deploy-az-function' workflow job does the following
1. First, we fetch the ‘Publishing Profile’ for the ‘Function App’ created earlier. This will be required later for the code deployment.
2. Then we fetch the ‘zip artefact’ that we had created earlier which contains the published code.
3. And finally, we deploy the code to the Azure Function App.
We have now successfully created our GitHub Actions workflow which will automatically deploy our Azure Function. The workflow will trigger when we push a new commit to our GitHub code repository.
.png)
Once the GitHub Actions deployment workflow finishes running, Azure Function will soon be accessible.
.png)
Conclusion
Following the process described above, it is now easier than ever before to build out an extensive CI/CD pipeline using GitHub actions. Maintaining our Azure Functions in a Git repository brings the fore, the benefits of version control, source code management, and of course the automated build and deployment of our functions into Azure though CI/CD.
Reach out to our expert team for more information and best practices to implement this for your business.
Publications
& Thought Leadership

