Lights — Camera — {Github}Action: Deploy an Azure function using Github actions

Arjit Sharma
FAUN — Developer Community 🐾
5 min readMay 9, 2021

--

A short tutorial on how to deploy an Azure function using GitHub action.
As we know, GitHub Actions help us automate tasks, for example, executing an integration/deployment pipeline as we create a release, or running integration test scripts after pull request event, or maybe just simply an acknowledgment to a user who has created an issue against your repository.

Here, we will create a simple Github action to deploy an HTTP Trigger Azure function to Azure Function App.

Image Credits: WhizzyCrafts

STEP 0: Prerequisite

  1. Azure Cloud Subscription
  2. Github Account and repo (you can use my sample repo as an example).
  3. Azure Functions Core Tools (for creating an HTTP Trigger Azure function)
  4. Node Js (using Typescript as language)
  5. Your Favourite Code Source Editor (optional)
  6. Azure CLI (optional)

STEP 1: Create a function app in Azure

Step 1, is to create a function app in Azure. I am not going into the details of how to create the function app. You can either use an easy self-guided Azure portal or Azure CLI to create a function app.

Once we have created a function app in Azure, one key thing we have to do is download its publish profile, as we will need it to deploy the function to the function app from GitHub.

One key thing to do here is add the below configuration parameter to configuration settings of the function app:
WEBSITE_WEBDEPLOY_USE_SCM : TRUE

STEP 2: Create an Azure function

The next step is to create a Repository in Github and clone it locally and create an HTTP Azure function. Again as this article is on GitHub actions I am not going into details on creating the HTTP trigger function.
You can follow Microsoft Docs; this tutorial for javascript HTTP trigger function in case you have any doubts.

Or for ease, you can download the sample repository I created for this tutorial, from Github.
Once the function is running locally, we will push the code to the main / master branch.

STEP 3: Add the content of Publish profile as Repository Secret

In Github, select your repository then,
go to Settings → Secret → New Repository Secret
And then add a key named PUBLISH_PROFILE (or your fav name) and copy the content of publishing profile in value for that key.

We are now all ready for the interesting part that is creating the Actions, which is coming next.

STEP 4 a: Understand workflow YML file

Next is we have to create an Action file. This is the key step required for deploying the function to Azure is to create the .github/workflows/{your-fav-name}.yml.

However, before creating the file, let's understand the Structure for Action workflow. The workflow is an automated procedure that we add to the repository. Workflows are made up of one or more jobs and can be scheduled or triggered by an event.
In Github actions, we use YML syntax to define events, jobs, and steps in a workflow, and these YML files are stored in our code repository, in a directory called .github/workflows.

In my sample code repository, the file name is .github/workflow/azure.yml, for which I have done the breakdown and explained the use of each section of the file below:

Now, let's do the breakdown of the most critical part of this file which is steps in the jobs.

STEP 4 b: Create the YML file:

There are two options to create the actions file:

  • Either you can create a directory .github/workflows and a {your-fav-name}.yml locally in the root of your Repository, as shown below.
    (if you wish, you can copy the content from my sample repo azure.yml).
  • Or easy and more visual way is we can use the GitHub portal action tab to create the Action file.

Here I have shown the latter way as it's easy to explain and I can give screenshots for the same :-).
Okay, let's go into our repository on GitHub and click on to actions tab.

Then Actions Tab → New Workflow to create a new action file and select a template of your choice. We can either select a blank template or the one chosen below.

And then replace the content of your YML file with my sample repo azure.yml file which is explained in step 4a. Github creates a .github/workflows directory for us.

One of the benefits of creating a workflow file in the portal is that you can search for community build Actions here and can use them in your workflow. Similar to what we have done using azure /functions-actions version 1.3.2 to deploy our function to the Azure function app.

Note: You can download/clone this repo for a simple HTTP trigger function (includes azure.yml file as well for reference)

STEP 5: Finally create the pull request and merge the code

As we push the code, we can see the pipeline running under the actions tab which will deploy our function to Azure Function App.

Now you can go to the Azure portal and validate the function deployment and give a pat on your back for achievement :-)

And while you are giving a pat on your back, don't forget to give a clap or two to me as well, it really feels good :-)

And if you faced any issues while doing it or you think any correction is required in this tutorial please do let me know, I will update the document accordingly.

Join FAUN: Website 💻|Podcast 🎙️|Twitter 🐦|Facebook 👥|Instagram 📷|Facebook Group 🗣️|Linkedin Group 💬| Slack 📱|Cloud Native News 📰|More.

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇

--

--