Recently GitHub actions got added to GitHub for adding CI/CD capabilities to both your private and public GitHub repositories. Coming from Azure DevOps myself, I thought this was a nice addition to GitHub to try out. So with this post I’ll give you a run-through of how to set this up and some of my findings.
Enabling GitHub actions for your own GitHub account is as easy as enabling the beta through the signup page and click ‘Sign up for beta’. Once this is done, you will notice all your existing repo’s get an addition ‘actions’ menu item at the top.
To start using these actions, I will create a new project in my GitHub account, you can find my test project here. I added a empty README file and a .gitignore file for node. In this project I will create an Azure function app and try to deploy this to azure through GitHub actions.
After cloning the project to my local system, I create a Function app project in my directory. I use the func command line tools for this. Instructions on how to install these can be found here. The below code shows you how to create and start your function project:
The func host start command will point you to a local URL where you can start testing out your function, to check if everything if running correctly.
We want to now deploy this function app to Azure through GitHub actions. My first thought on this was to leverage an ARM template to create my architecture for this in Azure and run this ARM template through GitHub Actions. However, if you look at the current list of GitHub Actions available for Azure, there is not yet an action available for deploying/running ARM templates.
I could have leveraged the ‘Azure login’ action for this, since this is able to run Azure CLI commands, however, for now I created my function app with local CLI commands:
Once you have your function app in place in Azure, you can create a service principal, which we will use in our deployment action in one of the next steps. The service principal needs to be a contributor to your function app:
The Json output of the above command, should be copy-pasted in a new GitHub Secret, with the name AZURE_CREDENTIALS.
Once this is in place, in our code repo, we can now add a .github/workflows folder. In this folder you can now create your first GitHub actions workflow in a workflow.yml file.
Inside this file I copy pasted directly the sample function action workflow from the GitHub marketplace. Here I also replaced some of the values as indicated on the sample and I altered some of the paths, since I am using a /src subdirectory in my GitHub project.
The above workflow runs on a Windows host, it first checks out my code from GitHub, then it logs into Azure with the secret value I provided, it sets up node, runs a couple of node commands and eventually pushes my code to my Azure function. As a last step in my workflow I have the deployment print out the URL to my function app.
Once I pushed these changes to my repo, I saw my first custom workflow pop up.
Now, unfortunately the URL to my function app, is a bit unusable to test out my function. As you can see in the last picture above, it only has the root URL, but for testing this needs to be appended with the HttpTrigger function name and an API key.
So to test out your function, go to the azure portal, and navigate to your function. Here you have a link for retrieving your function URL.
Add a &name=yourname to the back of this URL to test out your function.
Just to be sure the pipeline was working as expected, I also made a small code change in my index.js file, and pushed that to the repo to see the GitHub actions triggered again.
And sure, that triggered my workflow and got the change deployed to Azure.
That was actually pretty easy to set up and get going with it. Also, if you look at the docs of GitHub actions, there are quite a lot of parallel workflows you can run per GitHub repository (up to 20), that is actually more than what you get by default by Azure Pipelines.
On the other hand, the amount of pre-built actions is still limited, but I have heard (through the grapevine) the community is very involved in adding new actions.
Also interface-wise, getting an overview of all your runs, ie. navigating back from the detail of a run, to the list of runs, isn’t possible in the current UI. You need to navigate back to your full list of workflows. But, hey, if that’s the only flaw, I am very happy to live with that one.
Already nice work from the team! Happy to see this evolve in more!
Also, as an addendum. Once you add GitHub actions to your Github account, you get different proposals of workflows that would make sense to your repository. I clicked open the actions menu for this blog (which lives on GitHub pages and is compiled through Jekyll) and first recomendation for an action workflow was Jekyll docker build. Nice!!!