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
22 changes: 22 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## 📝 Description
<!-- Mô tả ngắn gọn về thay đổi -->

## 🔗 Related Issue
<!-- Link đến issue liên quan (nếu có) -->
Closes #

## 🎯 Type of Change
- [ ] 🐛 Bug fix
- [ ] ✨ New feature
- [ ] 🔨 Refactoring
- [ ] 📦 library update
- [ ] 📝 Documentation
- [ ] 🎨 UI/UX

## ✅ Checklist
- [ ] Code đã được test locally
- [ ] Không có lỗi lint
- [ ] Đã cập nhật documentation (nếu cần)

## 📸 Screenshots (nếu có)
<!-- Thêm screenshots nếu có thay đổi UI -->
214 changes: 214 additions & 0 deletions .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
name: .NET CI

on:
pull_request:
branches: [ dev ]
workflow_dispatch:

jobs:
code-quality:
name: Code Quality Check
runs-on: ubuntu-latest

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

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

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

- name: Restore dependencies
run: dotnet restore Project-sem3-backend.sln

- name: Check code format
run: |
dotnet format Project-sem3-backend.sln --verify-no-changes --verbosity diagnostic
continue-on-error: true
id: format-check

- name: Format check result
if: steps.format-check.outcome == 'failure'
run: |
echo "::warning::Code formatting issues detected. Run 'dotnet format' locally to fix."
exit 1

build:
name: Build & Analyze
runs-on: ubuntu-latest
needs: code-quality

strategy:
matrix:
configuration: [Debug, Release]

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

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

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

- name: Restore dependencies
run: dotnet restore Project-sem3-backend.sln

- name: Build solution (${{ matrix.configuration }})
run: |
dotnet build Project-sem3-backend.sln \
--configuration ${{ matrix.configuration }} \
--no-restore \
--verbosity normal \
/p:TreatWarningsAsErrors=true

- name: Upload build artifacts (${{ matrix.configuration }})
if: matrix.configuration == 'Release'
uses: actions/upload-artifact@v4
with:
name: build-artifacts-${{ matrix.configuration }}
path: |
**/bin/${{ matrix.configuration }}/**
**/obj/${{ matrix.configuration }}/**
retention-days: 7

test:
name: Run Tests
runs-on: ubuntu-latest
needs: build

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

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

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

- name: Restore dependencies
run: dotnet restore Project-sem3-backend.sln

- name: Build for testing
run: dotnet build Project-sem3-backend.sln --configuration Release --no-restore

- name: Run tests with coverage
run: |
dotnet test Project-sem3-backend.sln \
--configuration Release \
--no-build \
--verbosity normal \
--logger "trx;LogFileName=test-results.trx" \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults
continue-on-error: true

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: TestResults/**/*.trx
retention-days: 30
if-no-files-found: ignore

- name: Upload coverage reports
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: TestResults/**/coverage.cobertura.xml
retention-days: 30
if-no-files-found: ignore

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

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 Project-sem3-backend.sln

- name: Check for vulnerable packages
run: |
dotnet list package --vulnerable --include-transitive 2>&1 | tee vulnerable-packages.txt
if grep -q "has the following vulnerable packages" vulnerable-packages.txt; then
echo "::error::Vulnerable packages detected!"
cat vulnerable-packages.txt
exit 1
fi

- name: Check for deprecated packages
run: |
dotnet list package --deprecated 2>&1 | tee deprecated-packages.txt
if grep -q "has the following deprecated packages" deprecated-packages.txt; then
echo "::warning::Deprecated packages detected!"
cat deprecated-packages.txt
fi
continue-on-error: true

summary:
name: CI Summary
runs-on: ubuntu-latest
needs: [code-quality, build, test, security-scan]
if: always()

steps:
- name: Check job results
run: |
echo "## CI Pipeline Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Code Quality | ${{ needs.code-quality.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Build | ${{ needs.build.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Test | ${{ needs.test.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Security Scan | ${{ needs.security-scan.result }} |" >> $GITHUB_STEP_SUMMARY

if [[ "${{ needs.code-quality.result }}" == "failure" ]] || \
[[ "${{ needs.build.result }}" == "failure" ]] || \
[[ "${{ needs.test.result }}" == "failure" ]] || \
[[ "${{ needs.security-scan.result }}" == "failure" ]]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "❌ **CI Pipeline Failed**" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ **CI Pipeline Passed**" >> $GITHUB_STEP_SUMMARY
fi
48 changes: 47 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,50 @@ CodeCoverage/
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
nunit-*.xml

# ========================
# Environment / Secrets
# ========================
appsettings.*.json
!appsettings.*.example.json

.env
!.env.example
Infrastructure/env/.env*

# Lock files - uncomment to ignore lock files
# packages.lock.json
# global.json
# ========================
# OS / IDE
# ========================
.DS_Store
Thumbs.db
.vs/
.vscode/

# ========================
# .NET build artifacts
# ========================
bin/
obj/
*.user
*.suo
*.nuget.*
project.assets.json
project.nuget.cache

# ========================
# NodeJS
# ========================
**/node_modules/
**/.next/
# ========================
# Logs
# ========================
*.log
#=========================
# package-lock root repo
#=========================
/package-lock.json
18 changes: 18 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.Run();
31 changes: 31 additions & 0 deletions Project-sem3-backend.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="FluentValidation" Version="12.0.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.23" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.22">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.22">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.22" />
<PackageReference Include="MySql.Data" Version="9.1.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageReference Include="StackExchange.Redis" Version="2.10.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="System.Text.Json" Version="10.0.4" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions Project-sem3-backend.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Project_sem3_backend_HostAddress = http://localhost:5148

GET {{Project_sem3_backend_HostAddress}}/weatherforecast/
Accept: application/json

###
34 changes: 34 additions & 0 deletions Project-sem3-backend.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Project-sem3-backend", "Project-sem3-backend.csproj", "{340EC36E-A46D-4EB3-B3B2-1244FD77A766}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Debug|Any CPU.Build.0 = Debug|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Debug|x64.ActiveCfg = Debug|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Debug|x64.Build.0 = Debug|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Debug|x86.ActiveCfg = Debug|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Debug|x86.Build.0 = Debug|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Release|Any CPU.ActiveCfg = Release|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Release|Any CPU.Build.0 = Release|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Release|x64.ActiveCfg = Release|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Release|x64.Build.0 = Release|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Release|x86.ActiveCfg = Release|Any CPU
{340EC36E-A46D-4EB3-B3B2-1244FD77A766}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading
Loading