GitHub Actions and CI/CD
1. What is GitHub Actions?
What is GitHub Actions?
GitHub Actions is GitHub's automation platform used to automatically execute workflows when events occur in a GitHub repository.
It is commonly used for:
- Building applications
- Running automated tests
- Code quality/security checks
- Creating packages
- Deploying applications
- Implementing CI/CD pipelines
In simple terms:
GitHub Actions automatically builds, tests, and can deploy your application when something happens in GitHub, such as a push or Pull Request.
For example:
Developer
↓
git push
↓
GitHub Repository
↓
GitHub Actions
↓
Build
↓
Test
↓
Deploy
2. How does GitHub Actions work?
GitHub Actions uses workflow files written in YAML.
They are normally stored under:
.github/
└── workflows/
└── ci.yml
A workflow defines:
Event
↓
Workflow
↓
Job
↓
Steps
↓
Actions / Commands
Important Terms
Workflow — the complete automated process.
Example:
Build → Test → Deploy
Event/Trigger — determines when the workflow starts.
Examples:
push
pull_request
workflow_dispatch
schedule
Job — a group of steps executed on a runner.
Examples:
build
test
deploy
Step — an individual command or action within a job.
Action — a reusable component that performs a task, such as checking out source code.
Runner — the machine that executes the job.
Examples include:
ubuntu-latest
windows-latest
macos-latest
3. Simple GitHub Actions Example for ASP.NET Core
Suppose you have an ASP.NET Core Web API.
Create:
.github/workflows/dotnet-ci.yml
Sample Program
name: ASP.NET Core CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build application
run: dotnet build --no-restore
- name: Run tests
run: dotnet test --no-build
The flow is:
Push / Pull Request
↓
Start GitHub Actions
↓
Create Ubuntu runner
↓
Checkout source code
↓
Install .NET
↓
dotnet restore
↓
dotnet build
↓
dotnet test
↓
Success / Failure
4. Detailed Explanation
name
name: ASP.NET Core CI
This gives the workflow a name.
You will see this name in the GitHub Actions page.
on
on:
push:
branches:
- main
on specifies the trigger.
This means:
Run this workflow whenever code is pushed to
main.
We also configured:
pull_request:
branches:
- main
Therefore, it also runs when a Pull Request targets main.
jobs
jobs:
A workflow contains one or more jobs.
For example:
jobs
├── build
├── test
└── deploy
Our example has one:
build:
runs-on
runs-on: ubuntu-latest
This tells GitHub which runner should execute the job.
Conceptually:
GitHub Actions
↓
Creates/assigns Runner
↓
Ubuntu environment
↓
Execute workflow steps
Checkout Code
- name: Checkout code
uses: actions/checkout@v4
The runner initially needs access to your repository's source code.
actions/checkout checks out the repository onto the runner.
Setup .NET
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
This configures the required .NET SDK.
Restore Packages
- name: Restore dependencies
run: dotnet restore
This restores the application's NuGet dependencies.
Build
- name: Build application
run: dotnet build --no-restore
This compiles the application.
If compilation fails:
Build Failed
↓
Workflow Failed
This prevents broken code from silently passing the automated validation.
Test
- name: Run tests
run: dotnet test --no-build
This runs automated tests.
For example:
100 tests
↓
98 passed
2 failed
↓
Workflow Failed
This is an important part of Continuous Integration.
5. How is GitHub Actions related to CI/CD?
GitHub Actions is a tool that can implement CI/CD pipelines.
CI/CD is the development practice or process.
GitHub Actions is one platform that automates that process.
CI/CD
↓
Can be implemented using
↓
GitHub Actions
Other tools can also implement CI/CD, such as:
Azure Pipelines
Jenkins
GitLab CI/CD
6. Continuous Integration (CI)
Continuous Integration means developers frequently integrate code changes and automated processes validate those changes.
Typical CI flow:
Developer
↓
git push
↓
GitHub
↓
GitHub Actions
↓
Restore
↓
Build
↓
Test
↓
Validation result
For example:
- run: dotnet restore
- run: dotnet build
- run: dotnet test
These steps form a basic CI pipeline.
Why CI?
Without CI:
Developer pushes code
↓
Someone manually builds
↓
Someone manually tests
↓
Problem discovered later
With CI:
Developer pushes code
↓
Automatic build
↓
Automatic tests
↓
Immediate feedback
7. Continuous Delivery / Deployment (CD)
After CI succeeds, the application can be packaged and delivered or deployed.
For example:
Push to main
↓
Build
↓
Test
↓
Publish
↓
Deploy
↓
Azure
A .NET publishing step might be:
- name: Publish
run: dotnet publish -c Release -o ./publish
A deployment workflow could then deploy those published files to an environment such as Azure.
The exact deployment step depends on whether you're using:
Azure App Service
Azure Container Apps
AKS
VM
Docker
and how authentication/secrets are configured.
8. CI vs CD in GitHub Actions
Developer
↓
Push / Pull Request
↓
┌──────────────────────┐
│ CI │
├──────────────────────┤
│ Restore dependencies │
│ Build │
│ Run tests │
│ Code checks │
└──────────────────────┘
↓
Success
↓
┌──────────────────────┐
│ CD │
├──────────────────────┤
│ Publish/package │
│ Deploy to environment│
│ Verify deployment │
└──────────────────────┘
↓
Application
Key Points
- GitHub Actions is GitHub's workflow automation platform.
- Workflows are defined using YAML files.
- Workflow files are stored under:
.github/workflows/
- Workflows can be triggered by events such as:
push
pull_request
workflow_dispatch
schedule
- A workflow contains one or more jobs.
- Jobs run on runners.
- Jobs contain steps.
- GitHub Actions can automate both CI and CD.
- CI commonly includes:
Restore → Build → Test
- CD commonly includes:
Package/Publish → Deploy → Verify
- Secrets such as deployment credentials should not be hard-coded into workflow YAML; use GitHub's secrets/environment mechanisms and preferably short-lived/cloud-native authentication where supported.
Interview Answer
GitHub Actions is GitHub's automation platform for creating workflows directly from a GitHub repository. It is commonly used to implement CI/CD. For example, when a developer pushes code or creates a Pull Request, GitHub Actions can automatically restore dependencies, build the application, run tests, and, after successful validation, deploy the application to an environment such as Azure.