Introduction
Most development teams already have some form of CI pipeline. A pull request may trigger a build, run unit tests, execute integration tests, and perform security checks before the code can be merged.
But there is another question worth asking:
Can the CI pipeline automatically prevent a pull request from introducing avoidable code-quality problems?
That is where automated quality gates become useful.
Instead of relying only on a developer noticing a maintainability problem during review, a GitHub Actions workflow can run code-quality analysis and report the result as part of the pull request process.
The workflow becomes:
Developer
|
v
Pull Request
|
v
GitHub Actions
|
+--> Build
+--> Tests
+--> Code Quality
+--> Security Analysis
|
v
Quality Gate
|
+---- Fail ----> Fix
|
v
Human Review
|
v
MergeGitHub has introduced a dedicated Code Quality workflow for GitHub Actions, allowing code-quality analysis to become part of CI rather than remaining only a local developer activity. GitHub documents Code Quality as a way to analyze code and surface quality problems during development.
For .NET developers, this creates an interesting opportunity to combine GitHub Actions, compiler analysis, tests, and code-quality checks into a single pull-request workflow.
What Is an Automated Quality Gate?
A quality gate is a rule that determines whether a software change is acceptable for the next stage of the development process.
For example:
Build
|
+--> Passed
|
v
Tests
|
+--> Passed
|
v
Code Quality
|
+--> Passed
|
v
ReviewIf a required quality check fails:
Code Quality
|
+---- Failed
|
v
Pull Request
Cannot MergeThe exact merge behavior depends on repository rules and branch protection configuration.
The important idea is that quality analysis becomes an enforceable part of the development workflow.
Why Quality Gates Matter
Code review is important, but reviewers have limited time.
Consider a pull request that changes 25 files.
A reviewer may focus on:
Business logic
API behavior
Database changes
Security
Tests
They may not notice every maintainability issue.
Automated analysis can provide another layer:
Human Review
+
Automated Analysis
=
Stronger Review ProcessThe goal is not to replace developers.
It is to automate checks that machines are good at performing consistently.
Code Quality vs Build Validation
A build answers:
"Can the code compile?"Tests answer:
"Does the software behave as expected for the scenarios we tested?"Code-quality analysis asks a different question:
"Does the code contain patterns that may make it
harder to maintain, understand, or safely evolve?"These checks complement each other.
For example:
public async Task ProcessAsync(
object data)
{
// Large method containing validation,
// database access, business rules,
// logging, and external API calls.
}The code may compile.
Tests may pass.
But the method can still have maintainability problems.
That is why a quality gate adds another dimension.
A Typical .NET CI Pipeline
A basic ASP.NET Core workflow might look like:
Pull Request
|
v
Restore
|
v
Build
|
v
Unit Tests
|
v
Code Quality
|
v
Security Checks
|
v
Human Review
|
v
MergeA GitHub Actions workflow could begin with:
name: Build and Quality
on:
pull_request:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Test
run: dotnet test --no-build --configuration ReleaseThis is the foundation.
A code-quality stage can then be added to the pipeline using the quality-analysis capability selected by the organization.
Where Should Quality Analysis Run?
There are several possible locations.
During Local Development
Developer
|
v
IDE
|
v
Immediate FeedbackThis is useful because developers can fix issues before opening a pull request.
During Pull Requests
Pull Request
|
v
GitHub Actions
|
v
Quality AnalysisThis provides an independent CI validation layer.
After Merge
main
|
v
Scheduled Analysis
|
v
Repository HealthThis is useful for tracking the overall health of the codebase.
A mature development workflow often uses all three.
The Difference Between Warning and Blocking
Not every quality finding should block a pull request.
For example:
Low-severity maintainability warningmay be worth reporting without stopping development.
A serious problem may deserve a blocking rule.
Conceptually:
Finding
|
+--> Low
| |
| +--> Report
|
+--> Medium
| |
| +--> Review
|
+--> High
|
+--> BlockThe exact severity model depends on the analysis tool and the organization's policy.
The important thing is to avoid creating a pipeline where every minor warning becomes a merge blocker.
Quality Gates Should Focus on New Problems
One of the most practical approaches is to prevent a pull request from making the codebase worse.
Imagine an old repository already has:
2,000 existing findingsIf the quality gate requires:
0 total findingsthe team may never be able to merge another change.
A better strategy is to focus on newly introduced problems.
Conceptually:
Before PR
1,000 findings
After PR
1,000 findings
Result
No new findingsversus:
Before PR
1,000 findings
After PR
1,008 findings
Result
8 new findingsThe second pull request deserves attention.
This approach allows teams to improve legacy code gradually without requiring an immediate rewrite.
Example: A Quality Problem in C#
Consider this method:
public async Task ProcessOrderAsync(Order order)
{
if (order != null)
{
if (order.Items != null)
{
if (order.Items.Count > 0)
{
// Process order
}
}
}
}The code may work.
But it can be simplified:
public async Task ProcessOrderAsync(Order order)
{
if (order?.Items?.Count > 0)
{
// Process order
}
}The second version is easier to read.
Automated quality analysis can identify certain code patterns like unnecessary complexity or maintainability concerns.
The exact findings depend on the configured analyzers and rules.
Compiler Analyzers in .NET
.NET developers already have access to compiler analyzers through the Roslyn ecosystem.
For example, a project can enable analysis:
<PropertyGroup>
<AnalysisLevel>latest</AnalysisLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>This can provide additional compiler and analyzer diagnostics.
The important distinction is:
Compiler
|
+--> Syntax
+--> Type correctness
+--> Compilation diagnostics
Analyzers
|
+--> Code patterns
+--> Maintainability
+--> API usage
+--> Design guidanceThe exact analysis level should be selected deliberately rather than simply choosing the newest possible rules without testing the impact.
When Should Warnings Become Errors?
A common configuration is:
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>This can create a strict quality environment.
But it can also become difficult to adopt in a legacy application.
Suppose the existing project produces:
500 warningsTurning every warning into an error can make normal development painful.
A better rollout may be:
Phase 1
Report warnings
Phase 2
Fix important warnings
Phase 3
Block new important warnings
Phase 4
Increase enforcement graduallyThis makes adoption much more manageable.
GitHub Actions Quality Workflow
GitHub's Code Quality workflow is designed to integrate code-quality analysis into GitHub Actions. The resulting analysis can be surfaced through the repository and pull-request workflow.
A conceptual workflow might look like:
name: Code Quality
on:
pull_request:
jobs:
quality:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --configuration Release
- name: Test
run: dotnet test --configuration Release
- name: Code quality analysis
run: |
echo "Run configured code quality analysis"The final analysis step is intentionally generic because the exact GitHub Code Quality configuration depends on the analysis framework, language, and repository setup.
The important architecture is:
Build
+
Tests
+
Quality Analysisrather than assuming that one analyzer or one command represents all code quality.
Why Quality Gates Should Run on Pull Requests
A pull request is an excellent point to run quality analysis.
At that point:
Code Exists
|
v
Change Is Reviewable
|
v
Quality Can Be Checked
|
v
Problems Can Be Fixed
|
v
MergeThe cost of fixing a quality problem is generally easier to manage before the code becomes part of the main branch.
It also provides immediate feedback to the developer.

Join the conversation! Your thoughts help the community grow.