Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
name: .NET CI/CD Pipeline

on:
push:
branches: [ main, develop ]
paths:
- 'dotnet/**'
- '.github/workflows/dotnet-ci.yml'
pull_request:
branches: [ main ]
paths:
- 'dotnet/**'

env:
DOTNET_VERSION: '8.0.x'
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true

jobs:
build:
name: Build & Test
runs-on: ubuntu-latest

defaults:
run:
working-directory: dotnet

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json', '**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-

- name: Restore dependencies
run: dotnet restore src/Aegis.sln

- name: Build
run: dotnet build src/Aegis.sln --no-restore --configuration Release

- name: Test
run: |
dotnet test src/Aegis.sln \
--no-build \
--configuration Release \
--verbosity normal \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults
continue-on-error: true

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: dotnet/TestResults

security-scan:
name: Security Scan
runs-on: ubuntu-latest
needs: build

defaults:
run:
working-directory: dotnet

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Restore dependencies
run: dotnet restore src/Aegis.sln

- name: Check for vulnerable packages
run: |
dotnet list src/Aegis.sln package --vulnerable --include-transitive 2>&1 | tee vulnerability-report.txt
if grep -q "has the following vulnerable packages" vulnerability-report.txt; then
echo "::warning::Vulnerable packages detected"
fi

- name: Upload vulnerability report
uses: actions/upload-artifact@v4
with:
name: vulnerability-report
path: dotnet/vulnerability-report.txt

code-quality:
name: Code Quality
runs-on: ubuntu-latest
needs: build

defaults:
run:
working-directory: dotnet

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Install dotnet format
run: dotnet tool install -g dotnet-format

- name: Check code formatting
run: dotnet format src/Aegis.sln --verify-no-changes --verbosity diagnostic
continue-on-error: true

docker-build:
name: Docker Build
runs-on: ubuntu-latest
needs: [build, security-scan]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: ./dotnet
file: ./dotnet/Dockerfile
push: false
tags: aegis-messenger:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max

notify:
name: Notify
runs-on: ubuntu-latest
needs: [build, security-scan, code-quality]
if: always()

steps:
- name: Check build status
run: |
if [ "${{ needs.build.result }}" == "failure" ]; then
echo "Build failed!"
exit 1
fi
if [ "${{ needs.security-scan.result }}" == "failure" ]; then
echo "Security scan failed!"
exit 1
fi
echo "All checks passed!"
Loading
Loading