Git Actions with Blazor
I have had “Learn Git Actions” on my to-do list for quite some time. I attended some virtual conferences about Git Actions. After the last publishing issue, I had an Azure Publish Error, and I figured it was time to invest the time to learn it. I first looked at Azure Dev-Ops, I have used it for a while. I review the cost and features available. There is a free tier, with limitations but it is very feature-rich. What I was looking for was a quick and effortless way to build a CI/CD, Continuous Integration / Continuous Delivery, system for my Blog projects. Azure Dev Ops seemed overkilled for this since I am already using Jira for project management. Jira has a free trier as well that is more than enough to manage my Blog and side projects.
I did about a 30-minute research on Git Actions, and I was hooked. I was so surprised at how easily Microsoft has made it. I have used Git Actions before, Static Web Site Deployment. It was easy there as well.
This post is going to cover a Server-Side Blazor application or a Web Assembly Application that is hosted in Asp.Net. Both required an Azure App service.
Hooking Up Git Actions
I have created the basic template Server-Side application and will walk you through what it took me to get Git Actions working.
2. Make a GitHub repository and check your code
3. Got to Azure Portal
4. Make a new App Service
a. This works with the free App Service tier as well.
5. Once the App Service is done, click “Go to Resource”
6. Click on the Deployment Center
a. Select the Settings Tab
b. From the “Source” drop-down select “GitHub”
i. You must authorize Azure to access your GitHub account
c. Note they will post of warning that you are on a production slot, not a development slot. That was fine for this demo.
d. Complete the form
e. If you preview the form, you will notice it is a YAML file.
i. If you are not familiar with YAML, I would benefit you to know it.
f. Click “Save Setting”
7. Once the change is saved, Go to your GitHub Repository
8. The first thing you should have noticed is that there is a new folder added to your project “.github/workflows”
a. If you click into the folder, you will see the new YAML file.
9. Select Actions
a. You will see a build has been kicked off
b. If the status is yellow, it is in progress
c. If the status is red, there was an error
d. If the status is green, the build and deployment were successful
That was it. You now have a CI/CD pipeline for your project. I was shocked at how easy that was. Now to really understand the power of Git Action:
2. Check in that change into GitHub.
3. Go to your GitHub repository
4. Click on the “Actions” tab
a. You will see a new build was triggered,
1. Add a new X-Unit test project to our solution
2. Add at least one unit that will pass
3. Execute the test and ensure it does pass.
4. Check your changes
a. Note a build was triggered, but we are not interested in that one since we have not turned testing on.
5. Go to the GitHub repository
6. Go to the .github/workflow folder
a. Open the YAML file for editing
b. Right below the run: dotnet build … line add the following
- name: Run Test
run: dotnet test --configuration Release --no-build
c. Take note of the indention, with YAML files this matters.
d. Save your settings and commit your changes
e. This check will trigger a new build.
7. Go to Actions
8. Once the build finishes, click on the “build” block
9. Click on Run Test
a. From here you can see the status of your test, how many tests passed, how many failed, and how many were skipped.
Summary
Overall, I am incredibly pleased with Git Actions, and I am planning to use them moving forward. I am using only a couple of the build commands, build, test, and publish, but you can use basically all the dotnet CLI commands.
There is even a marketplace where you can get additional templates, free or for purchase to create all kinds of builds, integrations, and deployments. My actions are simple, but you can get extraordinarily complex with additional actions.
Comments
Post a Comment