All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m25s
Phase 1 (MVP) — chống regression Workflow state machine. 54 test pure function (no DB / IO), all pass < 7 giây. Test project: - tests/SolutionErp.Domain.Tests/ (xUnit 2.9.3 + FluentAssertions 7.2 — pin trước v8 commercial license) - ProjectReference SolutionErp.Domain - Added vào SolutionErp.slnx folder /tests/ Test files: - Contracts/WorkflowPolicyTests.cs (~17 test): - Standard policy 9-phase: role transitions, CCM check, BOD signing, terminal - SkipCcm policy 7-phase: bypass CCM verify, no DangKiemTraCCM transition - Registry: DefaultPolicyName per ContractType (7 type), bypass flag override - FromDefinition versioned: build từ ordered steps + reject path + TuChoi auto-add + UserKindApprover populate UserTransitions - PurchaseEvaluations/PurchaseEvaluationPolicyTests.cs (~17 test): - NccOnly (A) 3-step: skip ChoDuAn + ChoCEODuyetPA, CCM đẩy thẳng CEO duyệt NCC - NccWithPlan (B) 5-step: có ChoDuAn (PM) + ChoCEODuyetPA (Director) trước - Reject path cả 2 quy trình về DangSoanThao - Registry mapping per PEType - Budgets/BudgetPolicyTests.cs (~13 test): - Default 3-step (Drafter→CCM→CEO) role guard - Reject paths về DangSoanThao - DaDuyet + TuChoi terminal (no NextPhases) - SLA spec 5d/3d/2d cho 3 phase đầu CI gate (.gitea/workflows/deploy.yml): - Step "Run unit tests (Domain)" thêm TRƯỚC build/publish/deploy - Test fail (LASTEXITCODE != 0) → exit → KHÔNG deploy - TRX log saved + upload artifact (continue-on-error nếu Gitea runner thiếu actions/upload-artifact) Verify local: - dotnet test tests/SolutionErp.Domain.Tests → Total tests: 54 / Passed: 54 / 6.4s - dotnet build SolutionErp.slnx (full solution incl. test project) → 0 error Phase 2-5 pending (xem plan ở chat): - Code generator atomic concurrency tests (Infra) - DbInitializer reconcile drift tests (Infra) - Application handler smoke tests (CQRS) với EF InMemory - API smoke tests qua WebApplicationFactory - FE Vitest cho lib utility (queryMatches, fmtMoney) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
141 lines
5.8 KiB
YAML
141 lines
5.8 KiB
YAML
# Gitea Actions CI/CD - build + deploy SOLUTION_ERP to IIS on same VPS.
|
|
# Trigger: push to main, or manual dispatch.
|
|
#
|
|
# Self-hosted Windows runner on VPS (shared with VIETREPORT). Runner has:
|
|
# - git, .NET 10 SDK, Node 20, IIS
|
|
# - Can deploy locally (no WinRM needed)
|
|
#
|
|
# Secrets required in Gitea repo settings:
|
|
# - JWT_SECRET (64+ chars random)
|
|
# - DB_CONNECTION (full connection string with vrapp password)
|
|
|
|
name: Deploy SOLUTION_ERP
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build-deploy:
|
|
runs-on: windows-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Show tool versions
|
|
shell: powershell
|
|
run: |
|
|
& 'C:\Program Files\dotnet\dotnet.exe' --version
|
|
& 'C:\Program Files\nodejs\node.exe' --version
|
|
& 'C:\Program Files\nodejs\npm.cmd' --version
|
|
|
|
# ============== TEST GATE ==============
|
|
# Run unit tests TRƯỚC build/publish/deploy. Test fail → exit non-zero
|
|
# → toàn bộ job stop, KHÔNG deploy. Phase 1 chỉ Domain layer (~54 test
|
|
# phase machine + policy registry). Mở rộng Application/Infra/Api
|
|
# khi có nhu cầu (xem docs/changelog/migration-todos.md).
|
|
- name: Run unit tests (Domain)
|
|
shell: powershell
|
|
run: |
|
|
& 'C:\Program Files\dotnet\dotnet.exe' test tests/SolutionErp.Domain.Tests/SolutionErp.Domain.Tests.csproj `
|
|
--configuration Release `
|
|
--logger "trx;LogFileName=domain-tests.trx" `
|
|
--results-directory test-results
|
|
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
|
|
|
- name: Upload test results
|
|
if: always()
|
|
continue-on-error: true # nếu Gitea runner chưa có upload-artifact action, skip không block deploy
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: test-results
|
|
path: test-results/*.trx
|
|
retention-days: 14
|
|
|
|
# ============== BUILD ==============
|
|
- name: Build backend
|
|
shell: powershell
|
|
run: |
|
|
& 'C:\Program Files\dotnet\dotnet.exe' restore SolutionErp.slnx
|
|
& 'C:\Program Files\dotnet\dotnet.exe' publish src/Backend/SolutionErp.Api/SolutionErp.Api.csproj `
|
|
--configuration Release `
|
|
--output out/api `
|
|
--runtime win-x64 `
|
|
--self-contained false
|
|
|
|
- name: Build fe-admin
|
|
shell: powershell
|
|
working-directory: fe-admin
|
|
run: |
|
|
# Vite 8 rolldown native binding must match platform; fresh resolve on Windows
|
|
Remove-Item node_modules, package-lock.json -Recurse -Force -ErrorAction SilentlyContinue
|
|
& 'C:\Program Files\nodejs\npm.cmd' install --no-audit --no-fund
|
|
& 'C:\Program Files\nodejs\npm.cmd' run build
|
|
|
|
- name: Build fe-user
|
|
shell: powershell
|
|
working-directory: fe-user
|
|
run: |
|
|
Remove-Item node_modules, package-lock.json -Recurse -Force -ErrorAction SilentlyContinue
|
|
& 'C:\Program Files\nodejs\npm.cmd' install --no-audit --no-fund
|
|
& 'C:\Program Files\nodejs\npm.cmd' run build
|
|
|
|
- name: Deploy to IIS (local)
|
|
if: github.ref == 'refs/heads/main'
|
|
shell: powershell
|
|
env:
|
|
JWT_SECRET: ${{ secrets.JWT_SECRET }}
|
|
DB_CONNECTION: ${{ secrets.DB_CONNECTION }}
|
|
run: |
|
|
Import-Module WebAdministration
|
|
|
|
# Stop app pool (if running) so DLLs are writable
|
|
$poolState = (Get-WebAppPoolState -Name SolutionErp-Api -ErrorAction SilentlyContinue).Value
|
|
if ($poolState -eq 'Started') {
|
|
Stop-WebAppPool -Name SolutionErp-Api
|
|
Start-Sleep -Seconds 3
|
|
}
|
|
|
|
# Deploy API
|
|
Remove-Item -Path 'C:\inetpub\solution-erp\api\*' -Recurse -Force -Exclude 'appsettings.Production.json','logs','uploads','wwwroot' -ErrorAction SilentlyContinue
|
|
Copy-Item -Path 'out\api\*' -Destination 'C:\inetpub\solution-erp\api\' -Recurse -Force
|
|
|
|
# Write appsettings.Production.json from source template + secrets.
|
|
# Template is in source workspace (not in publish output - dotnet publish
|
|
# doesn't copy .example files).
|
|
$example = 'src\Backend\SolutionErp.Api\appsettings.Production.json.example'
|
|
$prod = 'C:\inetpub\solution-erp\api\appsettings.Production.json'
|
|
$settings = Get-Content $example -Raw | ConvertFrom-Json
|
|
$settings.ConnectionStrings.Default = $env:DB_CONNECTION
|
|
$settings.Jwt.Secret = $env:JWT_SECRET
|
|
$settings | ConvertTo-Json -Depth 10 | Set-Content -Path $prod -Encoding UTF8
|
|
Write-Host "Wrote appsettings.Production.json"
|
|
|
|
# Restrict ACL
|
|
icacls $prod /inheritance:r | Out-Null
|
|
icacls $prod /grant:r 'Administrators:(R,W)' 'IIS AppPool\SolutionErp-Api:(R)' | Out-Null
|
|
|
|
# Deploy fe-admin
|
|
Remove-Item -Path 'C:\inetpub\solution-erp\fe-admin\*' -Recurse -Force -Exclude 'web.config' -ErrorAction SilentlyContinue
|
|
Copy-Item -Path 'fe-admin\dist\*' -Destination 'C:\inetpub\solution-erp\fe-admin\' -Recurse -Force
|
|
|
|
# Deploy fe-user
|
|
Remove-Item -Path 'C:\inetpub\solution-erp\fe-user\*' -Recurse -Force -Exclude 'web.config' -ErrorAction SilentlyContinue
|
|
Copy-Item -Path 'fe-user\dist\*' -Destination 'C:\inetpub\solution-erp\fe-user\' -Recurse -Force
|
|
|
|
# Restart app pool
|
|
Start-WebAppPool -Name SolutionErp-Api
|
|
Write-Host "Deploy done. App pool started."
|
|
|
|
- name: Smoke test
|
|
if: github.ref == 'refs/heads/main'
|
|
shell: powershell
|
|
run: |
|
|
Start-Sleep -Seconds 10
|
|
try {
|
|
$r = Invoke-WebRequest -Uri 'https://api.solutions.com.vn/health/live' -TimeoutSec 30 -UseBasicParsing
|
|
Write-Host "API /health/live -> $($r.StatusCode)"
|
|
} catch {
|
|
Write-Warning "API smoke test: $_"
|
|
}
|