Hi guys, today we will see how we can use GitHub Actions to create a CICD pipeline for Azure functions using VS Code. In simple words, we will automate the deployment of Azure functions to Azure. And the tool that we are going to use for this purpose is GitHub Actions. We will push Azure function code to a GitHub repository and GitHub Actions will automatically push the updated code to Azure. Now that's enough theory, let's see how it actually works. First thing we need to do is create a GitHub repository. Let's go to GitHub, click on new, enter a good name. So let's enter Testing GitHub Actions. All right, that's good. We can keep our repository public. Let me not add a readme file. Let's add a gitignore file and let's keep the language to Python because we'll be creating our Azure function in Python. Choose a license, we don't need a license. Click on create repository. All right, our repository is created. Let's copy the HTTPS code. Let's come here. All right, so I'm in a folder in my system. You can go to any folder in your system. Let's open PowerShell here by typing pwsh, type git clone and the URL. All right, our repository is created and successfully cloned on our system. Now we need to create an Azure function in our repository folder. For that, let's do one thing. Let's change the folder to here and open VS Code in this folder. Now I have opened the VS Code in my repository folder. So VS Code will automatically recognize that, okay, there is a git repository here. Now let's go to our Azure extension and don't worry, I'll give you the links of all these extensions in the description below. And if you want to see how to set this all up, go back to my Azure function setup video. All right, here we need to create an Azure function. We'll click create function. We'll choose this folder in which we are currently in. Select Python, Python interpreter. Let's skip the virtual environment. Let's use HTTP trigger, func name, func hyphen, testing GitHub access, right? Let's keep it. Authorization level, we'll keep it at function. Now it is asking that .gitignore file already exists because we created it during the process of creation of repository. So we need not overwrite it. Let's keep it that way. And our creation of project has started here. All right, our Azure function is created successfully. And if you go to the Explorer window now, you will see that in your repository folder, all these files are created. If I take the file explorer, you will see that in your testing GitHub actions folder. Okay, sorry, let me remove this shortcut. Yeah, you can see that in the repository folder, let me remove this shortcut. Yeah, you will see that in your testing GitHub actions folder, a folder structure has been created for the, not for the GitHub actions, for the Azure function. All right, once the function creation process is completed, let's go ahead and create our function app in Azure. For that, let's go to VS Code. Okay, before that, you will see here that Git in VS Code has recognized that we have made some changes to our repository. Now let me show you how we can push these changes in VS Code. So first of all, we'll need to stage these changes. For that, we need to click on this button, plus button. Now all the changes are staged. You will see here staged changes. And now we can make a commit. Created Azure function and we'll commit. Now these changes won't be visible in your GitHub repository yet because we have not yet synced them. Let's click on sync changes and okay. With this, we have pushed the changes to our GitHub repository. Let's go and check it once. Come here. And voila, you can see that all our files, Azure function files are now on GitHub repository because we have pushed the changes. Now let's come back to the VS Code and create a function app quickly. In Azure subscription, we'll go to function app. Create function app in Azure Advanced. App-. Let's quickly enter a name. Testing of GitHub. Let's see if it is unique. It is unique. Let's select the runtime stack. It is unusually slow today. Not sure why. Okay. It has given us. Let's select Python 3.9. Let's select the same resource group, plan, storage account, application inside CPE source. All right. Now our app deployment process has started. And if you want to see this process in detail, you can again go back to the video in which we did the Azure function deployment step by step. Okay. Our app deployment has successfully completed. Let's go to Azure portal once and see if our deployment is actually there. And I have already logged in to my Azure, but let me show you how you can come to the screen. This is your home screen for Azure, and you can come here by entering this portal.azure.com. Click on. You can search here for function. Function app. And here you will see the list of all your function apps. So this is the function app that we just deployed. App-testing of GitHub actions. And here you can see that app is successfully created. And you can also check your functions here because we have not yet published any function to it. So it is not showing any function. Let's go to our VS code now and deploy the function here. We are in our Azure extension. Click on deploy to function app. And it will show that no matching resources found. It sometimes happens that when you create an Azure function app, it will not immediately show up here. So something which I usually do for this is click control shift p to get this command palette and search for cache and click on this Python clear cache and reload window. It will just reload the VS code and clear all the cache. Sometimes it helps, sometimes it doesn't. Sometimes you have to wait for 10-15 minutes before your app starts showing up. Let's see if it worked in my scenario. Click on this deploy, deploy to function app. And it worked. Cache clearing worked. Now I can see my app. I will click on this. After waiting for a few seconds, I should see a pop-up. Pop-up is here and I'll click on deploy. It will take a few seconds now. The deployment is successfully completed. We can come to our Azure portal once more. And refresh it. And you will see that your function is now visible here. Everything works. Now let's try running our function. Function app. It is not giving us the URL. Sometimes happens. Again, let's click on this function here and get the function URL from here. It is loading right now, so it won't give us. All right. Let's copy it and enter it here. This HTTP triggered function executed successfully. Pass a name in the query string or in the body for a personalized response. This is the same line that is here. So this way, you can see that our function deployment and execution has been completed successfully. Now you can ask me, Mayank, we have done everything. We have successfully deployed the function. Our function is running successfully. And we have not yet talked about GitHub actions. What is the use of it? Now let's imagine that you want to make changes to this function. And instead of this, this HTTP trigger function successfully, let's say you wanted this is a great day. We have made this change. Now, if you want this, this change has been made on our local system. If you want this change to take effect in Azure, what we need to do is we need to again click on deploy, deploy to function app. And again, click on this app, select the app. And click on deploy. And then again, wait for a few seconds for the deployment to be completed. And you will see that we are using source control. We are using Git repository. So we need to push those changes to the GitHub repository also. So again, come here, click on save changes, enter your message, change the trigger line, commit, and sync changes. Okay. So you see how many number of clicks we have had to do. First, we had to deploy the function again, select the app from here, deploy, wait for a few seconds, then go to Git, save the changes, commit and push the changes. A number of things can go wrong in this process. You may select a wrong app name from the dropdown while deploying the changes. You may forget to push the changes to GitHub or you may forget the changes to deploy on the function app. A number of things can go wrong. Or let's say if nothing goes wrong, it is still a very manual process. So what is the solution? The solution is GitHub Actions. GitHub Actions, what it will do, you won't need to explicitly deploy your changes towards your function app by going to here. You don't need to do anything like this deploy to function app part. You will just need to go to source control, that is Git, and push your changes to the GitHub repository. Once you push the changes to the GitHub repository, GitHub Actions will automatically push those changes to the Azure function app. That's how this pipeline will be automated. But first of all, let's see if our change worked or not. We will again open a new tab and enter the same copied URL, press enter, and our change worked. This is a great day, dot. Now let's talk about, not talk about, let's see GitHub Actions in action. I already have this link open. I will obviously give this in the description below. In this link, Microsoft has described the complete process that you need to follow if you want to automate the deployment of your Azure functions. Well, for that, we need to first go to Azure, login, go to function app, app testing, functions. Oh, sorry, my bad. We don't need to go this far. We just need to go to overview and download this, but get published profile. So this published profile will kind of act as credentials to the Azure function. Now we need to go to our GitHub repository that we created, click on settings, go to secrets and variables, actions, and we need to create new repository secret. Let's see which name Microsoft recommends. Okay. So Microsoft recommends this name to create the secret. So we will enter the name here and in the secret value, we need to open that published profile that we just downloaded from Azure functions and copy it, paste it here, add secret. So this part is completed. Now, what is the next part? Let's go here. The next part is creating the YAML file. So GitHub actions works with a YAML file, YAML, YAML format. So this is the complete YAML file with Microsoft has very well created for us. So let's just copy it. Now, what you need to do is go to your Explorer here. You need to create a folder. Let's click here, create a folder dot GitHub in the dot GitHub. You need to again, create a folder of workflows. And in this, you need to create a YAML file. You can name it anything. Let's name it deploy to Azure dot YAML. And let's paste the YAML that we copied. This is the action on which GitHub action will run. So on push, whenever you make any push to your GitHub repository, this GitHub action will run. Here you need to specify your function app name. So what was our app name? Our app name is this. Let's copy it from here and come here. What is the path that we want to deploy? We will want to deploy the root path. So we will keep it dot and Python version. We use Python version 3.9. So let's make it 3.9. These are the only three changes that you need to make here. Obviously, you will have to push those changes to the GitHub repository. So let's stage these changes. Created GitHub action, commit and sync changes. Okay, with this, your GitHub actions deployment part is completed. Now the magic will begin. So let's say you want to again make any change to this line. This is a great day. Let's say no, this is not a great day anymore. This is a very bad day. Okay, and we do not want anything else in this now. We have changed it. Git has already recognized that we have made some changes. We will stage them. Changed the figure line to guard. Commit the changes and we will sync the changes. Click on OK. Okay, the push has completed. The magic should have begun in the background. Now how you can monitor this magic? Go to your repository. Click on this actions button and here you will see that your GitHub action has been created successfully. So this is the first time that our GitHub action ran. This ran when I first pushed the change by after creating the YAML file. So first time also it ran successfully and you can see that it took around 50 seconds and this is the latest push that I made, latest commit that I made. Changed the trigger line to bad and the GitHub action is running right now and it ran successfully. Changed the trigger line to bad. How can you verify that it ran successfully? Like we verified it the last time. Let's go to function. Click on function and let's get the function URL. Let's get the function URL. Load fast, load fast, load fast. Sometimes Azure portal gets really really slow. Okay, it is not giving me here. I need to get the function URL. Let me go here or I have the function URL in my clipboard. Let me press window V. Okay, I have not turned on the clipboard history. We will have to come here to get our function URL or I can get it from VS Code also if that is faster. No, that's also not faster. Okay, it is loading. Functions, copy function URL. I got it. Let's go to the new tab. Copy, press enter and you can see our change that we made on our local in VS Code and we only pushed the repository to GitHub. GitHub automatically pushed that change to Azure. So this is how CI CD pipeline can work in case of Azure functions. Now just some bonus info. Let's go to our YAML pipeline. So this is the on action. It means on what part, on what action you want this GitHub action to run. You can make it a bit more specific. Right now it will run if you make any push. Let's say you want to make it if you make changes to a specific repository or not repository, specific branch. So what you can do is on push. So it tells that GitHub action should run only when a push is made. You can make it further when a push is made to main branch. So this is how you can make it branch specific. Or you can specify a list of branches here also. If you want to specify main, dam, if you have multiple branches. So that's also you can do and you can even use wildcards in it like star, et cetera. I'll stick to main or I'll just go back to our previous one. Now there is a lot more to GitHub actions and I will give the documentation of GitHub actions in the description. I always encourage people to read documentations as much as possible because that gives us very in-depth knowledge. So that's it for this video. Let me know if you have any questions in this and let me know what topic should I cover next. Thank you.