π Note: This post is based on the source code used in my previous article
π Simple Email Sending API with .NET
π What is CI/CD?
CI/CD stands for Continuous Integration and Continuous Delivery (or Continuous Deployment). Itβs a set of modern DevOps practices that help teams deliver software faster, safer, and more frequently by automating the build, test, and deployment process.
π§ Continuous Integration (CI)
CI is all about merging code early and often. Developers push changes to the main branch multiple times a day. Each push triggers automated builds and tests, helping catch bugs and integration issues before they grow into bigger problems.
Benefits:
- β Catch errors early
- β Keep the codebase stable
- β Make collaboration easier
π Continuous Delivery (CD)
CD ensures your app is always ready to deploy. Every change that passes CI is automatically pushed to a staging or test environment. Deploying to production is just one manual click away.
Benefits:
- β‘ Faster release cycles
- π Reduced deployment risks
- π§ͺ Quick feedback from stakeholders
β‘ Continuous Deployment
This takes CD to the next level: every passing change goes straight to productionβno manual steps required.
Benefits:
- π Real-time updates
- π€ Maximum automation
- β±οΈ Ultra-fast reaction to bugs or market needs
To pull this off, your test suite needs to be rock solid. Continuous Deployment is the endgame for teams aiming to ship confidently, quickly, and often.
βοΈ What is GitHub Actions?
GitHub Actions is a CI/CD (Continuous Integration and Continuous Delivery) tool built into GitHub. It lets you automate tasks like building, testing, and deploying your code every time you push to a repository.
π§ What Can You Do With GitHub Actions?
- β Run tests automatically on each commit or pull request
- π Deploy your app to cloud platforms (e.g., Azure, AWS, Heroku)
- π¦ Build and publish Docker images
- π§Ή Run code formatters, linters, or cleanup scripts
- π§ͺ Set up custom workflows for any automation
π§ Why Use It?
π Fully integrated with GitHub
π Scales with your project
π Community-driven (tons of reusable actions)
πΈ Free minutes included with GitHub plans
If youβre already using GitHub to manage your code, GitHub Actions is a powerful and easy way to automate your entire dev lifecycle.
π οΈ Real-World CI/CD Example with Azure and GitHub
In the following step-by-step guide, we'll walk through a real-world scenario on how to implement a CI/CD pipeline in Azure for a web application hosted in a GitHub repository. These are the steps:
π Create an Azure Web App
Go to https://portal.azure.com and create a new Azure Web App.
Before that, make sure to:
- β Create a Subscription (if you don't already have one)
- β Set up a Resource Group to organize your resources
Once these are ready, you can proceed with configuring your web app (choose runtime, region, and plan as needed).
βοΈ Enable Continuous Deployment
We chose to Enable Continuous Deployment. This allows us to select the GitHub repository we want to deploy from directly.
During this step:
- π You'll be prompted to authorize GitHub and select your repository and branch.
- π It's important to Enable Basic Authentication to allow Azure to access your GitHub repo securely.
Once completed, Azure will automatically pull and deploy changes from your repository whenever you push new commits.
π Configure Access Settings
For the purposes of this tutorial, I selected Enable Public Access.
This allows anyone to access the web app via its public URL, which is useful for testing and demonstration.
β οΈ Note: In a production environment, you may want to restrict access using authentication, IP restrictions, or a private network setup.
π‘ Extra Tip: Enable Application Insights
As an extra tip, you can enable Application Insights during setup.
Since our code uses the ILogger
interface, this allows us to take full advantage of Azure's built-in monitoring and logging features.
With Application Insights, youβll be able to:
- π Track requests, dependencies, and exceptions
- π Analyze performance and response times
- π Gain insights into user behavior and application usage
Enabling it now saves time later when debugging or optimizing your app.
β Final Step: Review and Create
Click on Review + Create to finalize the app setup.
Once the deployment is complete:
- Go to your newly created Web App in the Azure Portal.
- Add the necessary environment variables for your project.
π These variables might include database connection strings, API keys, or other project-specific settings required at runtime.
π GitHub Actions Workflow File
After completing the deployment setup, a .yml
file is automatically generated in your projectβs GitHub repository.
This file defines your CI/CD pipeline and typically follows a structure like this:
name: Build and deploy ASP.Net Core app to Azure Web App - emailsenderapi
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
permissions:
contents: read #This is required for actions/checkout
steps:
- uses: actions/checkout@v4
- name: Set up .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.x'
- name: Build with dotnet
run: dotnet build --configuration Release
- name: Run tests
run: dotnet test --configuration Release --no-build --verbosity normal
- name: dotnet publish
run: dotnet publish -c Release -o "${{env.DOTNET_ROOT}}/myapp"
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
deploy:
runs-on: windows-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: 'emailsenderapi'
slot-name: 'Production'
package: .
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE }}
π Testing the Deployed App
Now that the deployment is complete, itβs time to test the app and confirm everything is working as expected.
π§ͺ CI/CD Feedback in GitHub Actions
In GitHub Actions, we can visually track each step of the Build and Deploy process.
In our case, we can see that all 7 unit tests were executed successfully β
.
This confirms that the application passed the testing phase before deployment.
β If any test had failed, the workflow would have been interrupted, and GitHub would have automatically notified us. This helps prevent broken code from being deployed to production.
You can view the full logs and outputs by clicking on each step within the GitHub Actions tab.
Happy Coding! π₯³
Top comments (0)