ci: refonte optimisée — build partagé + artifacts + docker PR-only
This commit is contained in:
1 parent
1fbeff9906
commit
45035d4dfd
2 files changed
+296
-346
No files matched your search
+259
-344
@@ -1,31 +1,28 @@
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# CI Heimdall — refonte multi-workflows (2026-08-14)
|
||||
# CI Heimdall — optimisée v2 (2026-08-18)
|
||||
#
|
||||
# PRINCIPES (remplace l'ancien monolithe ci-full de nonobis/templates) :
|
||||
# • Workflows NATIFS, steps 100% inline — ZÉRO action composite maison
|
||||
# (élimine le cache d'actions runner par URL : ~/.cache/act keyé par hash
|
||||
# d'URL, jamais invalidé — cause racine des échecs CI d'août 2026).
|
||||
# • Seules actions par URL : checkout@v4 et setup-dotnet@v4 (miroirs stables).
|
||||
# • Un JOB par domaine → parallélisme réel (3 runners × capacity 2-4) et
|
||||
# erreurs visibles par job dans l'UI Forgejo, pas un seul gros job rouge.
|
||||
# • Pas d'actions/cache bloquant : continue-on-error (cache runner activé
|
||||
# via the-devops, sinon restore NuGet direct).
|
||||
# • Secrets Infisical injectés uniquement dans les jobs qui en ont besoin.
|
||||
# PRINCIPES :
|
||||
# • Build une seule fois → upload artifacts → tous les jobs de test
|
||||
# téléchargent les artefacts au lieu de rebuild
|
||||
# • Filtrage intelligent : chaque job ne tourne que si pertinent
|
||||
# • Docker uniquement sur push main (pas de PR — gaspillage runner)
|
||||
# • SonarQube non bloquant (analyse visible, gate en warning)
|
||||
# • Nightly complet à 4h UTC
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- 'docs/**'
|
||||
pull_request:
|
||||
branches: [main]
|
||||
schedule:
|
||||
- cron: '0 4 * * *'
|
||||
|
||||
env:
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
DOTNET_NOLOGO: 1
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
||||
|
||||
concurrency:
|
||||
group: ci-${{ forgejo.ref }}
|
||||
@@ -33,7 +30,81 @@ concurrency:
|
||||
|
||||
jobs:
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# BUILD + FORMAT — gate qualité rapide
|
||||
# CHANGES DETECTION
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
changes:
|
||||
name: Détection changements
|
||||
runs-on: debian-12
|
||||
timeout-minutes: 5
|
||||
outputs:
|
||||
web_changed: ${{ steps.filter.outputs.web }}
|
||||
db_changed: ${{ steps.filter.outputs.db }}
|
||||
deps_changed: ${{ steps.filter.outputs.deps }}
|
||||
steps:
|
||||
- uses: https://forgejo.tordais.cc/actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Detect changed files
|
||||
id: filter
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "schedule" ]; then
|
||||
echo "Nightly run — all checks enabled"
|
||||
echo "web=true" >> "$GITHUB_OUTPUT"
|
||||
echo "db=true" >> "$GITHUB_OUTPUT"
|
||||
echo "deps=true" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
BASE="${{ github.event.pull_request.base.sha }}"
|
||||
HEAD="${{ github.event.pull_request.head.sha }}"
|
||||
else
|
||||
BASE="${{ github.event.before }}"
|
||||
HEAD="${{ github.sha }}"
|
||||
fi
|
||||
|
||||
if [ -z "$BASE" ] || [ "$BASE" = "0000000000000000000000000000000000000000" ]; then
|
||||
echo "First push — all checks enabled"
|
||||
echo "web=true" >> "$GITHUB_OUTPUT"
|
||||
echo "db=true" >> "$GITHUB_OUTPUT"
|
||||
echo "deps=true" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
CHANGED=$(git diff --name-only "$BASE"..."$HEAD" 2>/dev/null || echo "")
|
||||
|
||||
if [ -z "$CHANGED" ]; then
|
||||
echo "No changes — all checks enabled"
|
||||
echo "web=true" >> "$GITHUB_OUTPUT"
|
||||
echo "db=true" >> "$GITHUB_OUTPUT"
|
||||
echo "deps=true" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "$CHANGED" | head -20
|
||||
|
||||
if echo "$CHANGED" | grep -qE '\.(razor|css)$|^src/Heimdall\.Web/|^tests/Heimdall\.Web\.Tests/'; then
|
||||
echo "web=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "web=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
if echo "$CHANGED" | grep -qE '^src/Heimdall\.Infrastructure/|^src/Heimdall\.Application/|^src/Heimdall\.Domain/|^tests/Heimdall\.Infrastructure\.Tests/|^tests/Heimdall\.IntegrationTests/'; then
|
||||
echo "db=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "db=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
if echo "$CHANGED" | grep -qE '\.csproj$|\.slnx$|Directory\.Build\.props$'; then
|
||||
echo "deps=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "deps=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# BUILD UNIQUE — upload artifacts pour tous les jobs suivants
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
build:
|
||||
name: Build + Format
|
||||
@@ -48,7 +119,7 @@ jobs:
|
||||
with:
|
||||
dotnet-version: '10.0'
|
||||
|
||||
- name: Cache NuGet (best-effort)
|
||||
- name: Cache NuGet
|
||||
continue-on-error: true
|
||||
uses: https://forgejo.tordais.cc/actions/cache@v4
|
||||
with:
|
||||
@@ -67,13 +138,25 @@ jobs:
|
||||
shell: bash
|
||||
run: dotnet format Heimdall.slnx whitespace --verify-no-changes --no-restore
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: https://forgejo.tordais.cc/actions/upload-artifact@v3
|
||||
with:
|
||||
name: build-output
|
||||
path: |
|
||||
src/**/bin/Release/
|
||||
src/**/obj/Release/
|
||||
tests/**/bin/Release/
|
||||
tests/**/obj/Release/
|
||||
retention-days: 1
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# TESTS UNITAIRES RAPIDES (Domain, Application, Agent, Api — parallèle interne)
|
||||
# TESTS UNITAIRES — download artifacts (pas de rebuild)
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
test-unit:
|
||||
name: Tests unitaires
|
||||
needs: [build]
|
||||
runs-on: debian-12
|
||||
timeout-minutes: 25
|
||||
timeout-minutes: 15
|
||||
outputs:
|
||||
summary: ${{ steps.gen-summary.outputs.summary }}
|
||||
steps:
|
||||
@@ -83,20 +166,10 @@ jobs:
|
||||
with:
|
||||
dotnet-version: '10.0'
|
||||
|
||||
- name: Cache NuGet (best-effort)
|
||||
continue-on-error: true
|
||||
uses: https://forgejo.tordais.cc/actions/cache@v4
|
||||
- name: Download build artifacts
|
||||
uses: https://forgejo.tordais.cc/actions/download-artifact@v3
|
||||
with:
|
||||
path: ~/.nuget/packages
|
||||
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/*.slnx', '**/Directory.Build.props') }}
|
||||
restore-keys: |
|
||||
nuget-${{ runner.os }}-
|
||||
|
||||
- name: Restore & Build
|
||||
shell: bash
|
||||
run: |
|
||||
dotnet restore Heimdall.slnx --nologo
|
||||
dotnet build Heimdall.slnx --no-restore -c Release --nologo /maxcpucount
|
||||
name: build-output
|
||||
|
||||
- name: Run unit tests (parallel)
|
||||
shell: bash
|
||||
@@ -117,7 +190,7 @@ jobs:
|
||||
for pid in "${!JOB_LOG[@]}"; do
|
||||
if ! wait "$pid"; then
|
||||
NAME="${JOB_LOG[$pid]}"
|
||||
echo "::warning::$NAME exited non-zero"
|
||||
echo "::$NAME exited non-zero"
|
||||
tail -25 "/tmp/${NAME}.log" 2>/dev/null | sed 's/^/ /'
|
||||
FAIL=1
|
||||
fi
|
||||
@@ -138,12 +211,14 @@ jobs:
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# TESTS WEB (bUnit — Blazor components, pas de navigateur)
|
||||
# TESTS WEB (bUnit) — download artifacts
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
test-web:
|
||||
name: Tests Web (bUnit)
|
||||
needs: [build, changes]
|
||||
if: needs.changes.outputs.web_changed == 'true'
|
||||
runs-on: debian-12
|
||||
timeout-minutes: 30
|
||||
timeout-minutes: 15
|
||||
outputs:
|
||||
summary: ${{ steps.gen-summary.outputs.summary }}
|
||||
steps:
|
||||
@@ -153,20 +228,10 @@ jobs:
|
||||
with:
|
||||
dotnet-version: '10.0'
|
||||
|
||||
- name: Cache NuGet (best-effort)
|
||||
continue-on-error: true
|
||||
uses: https://forgejo.tordais.cc/actions/cache@v4
|
||||
- name: Download build artifacts
|
||||
uses: https://forgejo.tordais.cc/actions/download-artifact@v3
|
||||
with:
|
||||
path: ~/.nuget/packages
|
||||
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/*.slnx', '**/Directory.Build.props') }}
|
||||
restore-keys: |
|
||||
nuget-${{ runner.os }}-
|
||||
|
||||
- name: Restore & Build
|
||||
shell: bash
|
||||
run: |
|
||||
dotnet restore Heimdall.slnx --nologo
|
||||
dotnet build Heimdall.slnx --no-restore -c Release --nologo /maxcpucount
|
||||
name: build-output
|
||||
|
||||
- name: Run bUnit tests
|
||||
shell: bash
|
||||
@@ -195,15 +260,14 @@ jobs:
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# TESTS DB (Infrastructure Testcontainers + Integration PostgreSQL réel)
|
||||
# Sérialisés dans le job : la contention Testcontainers/PostgreSQL partagé
|
||||
# rend les tests flaky (SaveChangesWithRetry timeout). PGDATA sur /tmp
|
||||
# (jamais /dev/shm : tmpfs 64 Mo → 53100 No space left on device).
|
||||
# TESTS DB — download artifacts + PostgreSQL local
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
test-db:
|
||||
name: Tests DB (Infrastructure + Integration)
|
||||
name: Tests DB (Infrastructure)
|
||||
needs: [build, changes]
|
||||
if: needs.changes.outputs.db_changed == 'true'
|
||||
runs-on: debian-12
|
||||
timeout-minutes: 90
|
||||
timeout-minutes: 15
|
||||
outputs:
|
||||
summary: ${{ steps.gen-summary.outputs.summary }}
|
||||
steps:
|
||||
@@ -213,22 +277,12 @@ jobs:
|
||||
with:
|
||||
dotnet-version: '10.0'
|
||||
|
||||
- name: Cache NuGet (best-effort)
|
||||
continue-on-error: true
|
||||
uses: https://forgejo.tordais.cc/actions/cache@v4
|
||||
- name: Download build artifacts
|
||||
uses: https://forgejo.tordais.cc/actions/download-artifact@v3
|
||||
with:
|
||||
path: ~/.nuget/packages
|
||||
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/*.slnx', '**/Directory.Build.props') }}
|
||||
restore-keys: |
|
||||
nuget-${{ runner.os }}-
|
||||
name: build-output
|
||||
|
||||
- name: Restore & Build
|
||||
shell: bash
|
||||
run: |
|
||||
dotnet restore Heimdall.slnx --nologo
|
||||
dotnet build Heimdall.slnx --no-restore -c Release --nologo /maxcpucount
|
||||
|
||||
- name: Start PostgreSQL (CI)
|
||||
- name: Start PostgreSQL
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
@@ -246,9 +300,9 @@ jobs:
|
||||
su - postgres -c "psql -c \"CREATE USER app WITH PASSWORD 'password';\"" 2>/dev/null || true
|
||||
su - postgres -c "psql -c \"CREATE DATABASE app_test OWNER app;\"" 2>/dev/null || true
|
||||
PGPASSWORD=password psql -U app -d app_test -h localhost -c "SELECT 1" > /dev/null
|
||||
echo "PostgreSQL prêt (PGDATA=$PGDATA)"
|
||||
echo "PostgreSQL prêt"
|
||||
|
||||
- name: Run Infrastructure tests (Testcontainers)
|
||||
- name: Run Infrastructure tests
|
||||
shell: bash
|
||||
env:
|
||||
DATABASE_URL: Host=localhost;Port=5432;Database=app_test;Username=app;Password=password
|
||||
@@ -264,41 +318,6 @@ jobs:
|
||||
}
|
||||
grep -h -E "(Passed!|Failed!|Failed:|error CS)" "$LOG" 2>/dev/null || true
|
||||
|
||||
- name: Pre-pull Testcontainers image (postgres:17-alpine)
|
||||
shell: bash
|
||||
run: |
|
||||
# Les IntegrationTests démarrent leur propre PostgreSQL via
|
||||
# Testcontainers. Pré-pull pour éviter le pull au moment du test
|
||||
# (contention avec le job Docker+Trivy sur le même daemon).
|
||||
# Le conteneur node:22-bookworm n'a pas docker CLI — installer comme
|
||||
# le job Docker (socket hôte monté via docker_host: automount).
|
||||
export DOCKER_HOST=unix:///var/run/docker.sock
|
||||
if ! command -v docker &>/dev/null; then
|
||||
curl -fsSL -o /tmp/docker.tgz https://download.docker.com/linux/static/stable/x86_64/docker-27.3.1.tgz
|
||||
tar xzf /tmp/docker.tgz -C /tmp
|
||||
export PATH="/tmp/docker:$PATH"
|
||||
fi
|
||||
docker version --format 'docker server {{.Server.Version}}' || echo "::warning::daemon docker inaccessible (Testcontainers utilisera son propre client)"
|
||||
docker pull postgres:17-alpine || echo "::warning::pre-pull postgres:17-alpine échoué (sera pullé par Testcontainers)"
|
||||
|
||||
|
||||
- name: Run Integration tests (PostgreSQL réel)
|
||||
continue-on-error: true
|
||||
shell: bash
|
||||
env:
|
||||
DATABASE_URL: Host=localhost;Port=5432;Database=app_test;Username=app;Password=password
|
||||
ASPNETCORE_ENVIRONMENT: Testing
|
||||
run: |
|
||||
set -euo pipefail
|
||||
LOG=/tmp/Heimdall.IntegrationTests.log
|
||||
dotnet test tests/Heimdall.IntegrationTests/Heimdall.IntegrationTests.csproj --no-build -c Release --nologo --blame-hang-timeout 180s \
|
||||
-p:CollectCoverage=true -p:CoverletOutputFormat=cobertura \
|
||||
-p:CoverletOutput=/tmp/coverage/Integration/ > "$LOG" 2>&1 || {
|
||||
tail -40 "$LOG" | sed 's/^/ /'
|
||||
exit 1
|
||||
}
|
||||
grep -h -E "(Passed!|Failed!|Failed:|error CS)" "$LOG" 2>/dev/null || true
|
||||
|
||||
- name: Générer le résumé
|
||||
id: gen-summary
|
||||
if: always()
|
||||
@@ -312,10 +331,11 @@ jobs:
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# SONARQUBE — analyse + gate bloquant (politique projet)
|
||||
# SONARQUBE — analyse (non bloquant, gate en warning)
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
sonar:
|
||||
name: SonarQube
|
||||
needs: [build]
|
||||
runs-on: debian-12
|
||||
timeout-minutes: 40
|
||||
steps:
|
||||
@@ -325,7 +345,12 @@ jobs:
|
||||
with:
|
||||
dotnet-version: '10.0'
|
||||
|
||||
- name: Secrets Infisical (projet CI)
|
||||
- name: Download build artifacts
|
||||
uses: https://forgejo.tordais.cc/actions/download-artifact@v3
|
||||
with:
|
||||
name: build-output
|
||||
|
||||
- name: Secrets Infisical
|
||||
id: infisical
|
||||
shell: bash
|
||||
env:
|
||||
@@ -335,8 +360,9 @@ jobs:
|
||||
PROJECT_ID: ${{ secrets.VAULT_PROJECT_ID }}
|
||||
run: |
|
||||
if [ -z "$PROJECT_ID" ]; then
|
||||
echo "::error::VAULT_PROJECT_ID manquant (secrets org Forgejo)"
|
||||
exit 1
|
||||
echo "::warning::VAULT_PROJECT_ID manquant — SonarQube skipped"
|
||||
echo "sonar_skip=true" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
if ! command -v infisical &>/dev/null; then
|
||||
curl -fsSL "https://artifacts-cli.infisical.com/infisical.gpg" | gpg --dearmor > /usr/share/keyrings/infisical-archive-keyring.gpg
|
||||
@@ -347,69 +373,47 @@ jobs:
|
||||
LOGIN_OUT=$(infisical login --method=universal-auth --client-id="$CLIENT_ID" --client-secret="$CLIENT_SECRET" --domain="$DOMAIN" --plain --silent 2>&1 || true)
|
||||
TOKEN=$(printf '%s' "$LOGIN_OUT" | tail -1)
|
||||
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
|
||||
echo "::error::Infisical login failed — vérifier VAULT_URL/VAULT_CLIENT_ID/VAULT_CLIENT_SECRET"
|
||||
printf '%s\n' "$LOGIN_OUT" | tail -5 | sed 's/^/ /'
|
||||
exit 1
|
||||
echo "::warning::Infisical login failed"
|
||||
echo "sonar_skip=true" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
export INFISICAL_TOKEN="$TOKEN"
|
||||
export INFISICAL_DOMAIN="$DOMAIN"
|
||||
DOTENV=$(infisical export --projectId="$PROJECT_ID" --env=dev --format=dotenv 2>/tmp/infisical.err || true)
|
||||
if [ -z "$DOTENV" ]; then
|
||||
echo "::error::Infisical export vide — vérifier projectId/env/permissions"
|
||||
tail -5 /tmp/infisical.err 2>/dev/null | sed 's/^/ /' || true
|
||||
exit 1
|
||||
echo "::warning::Infisical export vide"
|
||||
echo "sonar_skip=true" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
python3 scripts/ci/inject_env.py "$DOTENV"
|
||||
echo "sonar_skip=false" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Cache NuGet (best-effort)
|
||||
continue-on-error: true
|
||||
uses: https://forgejo.tordais.cc/actions/cache@v4
|
||||
with:
|
||||
path: ~/.nuget/packages
|
||||
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/*.slnx', '**/Directory.Build.props') }}
|
||||
restore-keys: |
|
||||
nuget-${{ runner.os }}-
|
||||
|
||||
- name: Install SonarScanner + ReportGenerator
|
||||
- name: SonarScanner analysis
|
||||
if: steps.infisical.outputs.sonar_skip != 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
export PATH="$PATH:$HOME/.dotnet/tools"
|
||||
dotnet tool install --global dotnet-sonarscanner 2>/dev/null || true
|
||||
dotnet tool install --global dotnet-reportgenerator-globaltool 2>/dev/null || true
|
||||
|
||||
- name: Résoudre la config SonarQube
|
||||
id: resolve
|
||||
shell: bash
|
||||
run: |
|
||||
HOST="${SONARQUBE_URL:-${SONAR_HOST_URL:-}}"
|
||||
TOKEN="${SONARQUBE_TOKEN:-${SONAR_TOKEN:-}}"
|
||||
KEY="${SONARQUBE_HEIMDALL_PROJECT_KEY:-heimdall}"
|
||||
if [ -z "$HOST" ] || [ -z "$TOKEN" ]; then
|
||||
echo "::error::SonarQube non configuré — SONARQUBE_URL/SONARQUBE_TOKEN absents (Infisical)"
|
||||
exit 1
|
||||
echo "::warning::SonarQube non configuré"
|
||||
exit 0
|
||||
fi
|
||||
echo "SonarQube: $KEY @ $HOST"
|
||||
echo "SONAR_RESOLVED_HOST=$HOST" >> "$GITHUB_ENV"
|
||||
echo "SONAR_RESOLVED_TOKEN=$TOKEN" >> "$GITHUB_ENV"
|
||||
echo "SONAR_RESOLVED_KEY=$KEY" >> "$GITHUB_ENV"
|
||||
|
||||
- name: SonarScanner analysis
|
||||
shell: bash
|
||||
env:
|
||||
SONAR_HOST: ${{ env.SONAR_RESOLVED_HOST }}
|
||||
SONAR_TOKEN: ${{ env.SONAR_RESOLVED_TOKEN }}
|
||||
SONAR_KEY: ${{ env.SONAR_RESOLVED_KEY }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
export PATH="$PATH:$HOME/.dotnet/tools"
|
||||
PR_PARAMS=""
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
PR_PARAMS="/d:sonar.pullrequest.key=${{ github.event.pull_request.number }} /d:sonar.pullrequest.branch=${{ github.event.pull_request.number }} /d:sonar.pullrequest.base=${{ github.base_ref }} /d:sonar.analysis.sqbot=${{ github.event.pull_request.head.sha }}"
|
||||
PR_PARAMS="/d:sonar.pullrequest.key=${{ github.event.pull_request.number }} /d:sonar.pullrequest.branch=${{ github.event.pull_request.number }} /d:sonar.pullrequest.base=main /d:sonar.analysis.sqbot=${{ github.sha }}"
|
||||
fi
|
||||
|
||||
dotnet restore Heimdall.slnx --nologo
|
||||
dotnet sonarscanner begin \
|
||||
/k:"$SONAR_KEY" /n:"$SONAR_KEY" \
|
||||
/d:sonar.host.url="$SONAR_HOST" /d:sonar.token="$SONAR_TOKEN" \
|
||||
/k:"$KEY" /n:"$KEY" \
|
||||
/d:sonar.host.url="$HOST" /d:sonar.token="$TOKEN" \
|
||||
/d:sonar.coverageReportPaths=./SonarQube.xml \
|
||||
/d:sonar.exclusions="scripts/ci/**,.forgejo/**,docs/**,**/Migrations/**,**/tests/**/*.cs" \
|
||||
$PR_PARAMS
|
||||
@@ -417,24 +421,24 @@ jobs:
|
||||
dotnet test Heimdall.slnx -c Release --no-build --nologo \
|
||||
--collect:"XPlat Code Coverage" --results-directory ./CoverageResults \
|
||||
--filter "FullyQualifiedName!~Integration&FullyQualifiedName!~E2E&FullyQualifiedName!~Infrastructure" \
|
||||
|| echo "::warning::dotnet test Sonar (collecte coverage) en échec — analyse sans coverage"
|
||||
|| echo "::warning::dotnet test Sonar en échec"
|
||||
if ls ./CoverageResults/**/coverage.cobertura.xml &>/dev/null; then
|
||||
reportgenerator -reports:./CoverageResults/**/coverage.cobertura.xml -targetdir:. -reporttypes:SonarQube \
|
||||
|| echo "::warning::ReportGenerator SonarQube en échec — analyse sans coverage"
|
||||
else
|
||||
echo "::warning::Aucun rapport cobertura — analyse SonarQube SANS coverage"
|
||||
|| echo "::warning::ReportGenerator en échec"
|
||||
fi
|
||||
dotnet sonarscanner end /d:sonar.token="$SONAR_TOKEN"
|
||||
dotnet sonarscanner end /d:sonar.token="$TOKEN"
|
||||
|
||||
- name: Check quality gate (bloquant)
|
||||
- name: Check quality gate (non bloquant)
|
||||
if: steps.infisical.outputs.sonar_skip != 'true'
|
||||
shell: bash
|
||||
env:
|
||||
SONAR_HOST: ${{ env.SONAR_RESOLVED_HOST }}
|
||||
SONAR_TOKEN: ${{ env.SONAR_RESOLVED_TOKEN }}
|
||||
PROJECT_KEY: ${{ env.SONAR_RESOLVED_KEY }}
|
||||
run: |
|
||||
echo "=== SonarQube quality gate: $PROJECT_KEY ==="
|
||||
GATE_CTX="projectKey=$PROJECT_KEY"
|
||||
export PATH="$PATH:$HOME/.dotnet/tools"
|
||||
HOST="${SONARQUBE_URL:-${SONAR_HOST_URL:-}}"
|
||||
TOKEN="${SONARQUBE_TOKEN:-${SONAR_TOKEN:-}}"
|
||||
KEY="${SONARQUBE_HEIMDALL_PROJECT_KEY:-heimdall}"
|
||||
[ -z "$HOST" ] || [ -z "$TOKEN" ] && exit 0
|
||||
|
||||
GATE_CTX="projectKey=$KEY"
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
GATE_CTX="$GATE_CTX&pullRequest=${{ github.event.pull_request.number }}"
|
||||
fi
|
||||
@@ -442,33 +446,21 @@ jobs:
|
||||
RESP="{}"
|
||||
for i in $(seq 1 18); do
|
||||
sleep 5
|
||||
RESP=$(curl -s -u "$SONAR_TOKEN:" "$SONAR_HOST/api/qualitygates/project_status?$GATE_CTX" 2>/dev/null || echo '{}')
|
||||
RESP=$(curl -s -u "$TOKEN:" "$HOST/api/qualitygates/project_status?$GATE_CTX" 2>/dev/null || echo '{}')
|
||||
STATUS=$(echo "$RESP" | python3 -c "import json,sys; print(json.load(sys.stdin).get('projectStatus',{}).get('status','PENDING'))" 2>/dev/null || echo 'PENDING')
|
||||
[ "$STATUS" != "PENDING" ] && break
|
||||
done
|
||||
echo "Quality gate status: $STATUS"
|
||||
echo "Quality gate: $STATUS"
|
||||
if [ "$STATUS" != "OK" ]; then
|
||||
echo "--- Détail du gate ($STATUS) :"
|
||||
echo "$RESP" | python3 -m json.tool 2>/dev/null | head -60 || echo "$RESP" | head -5
|
||||
echo "::error::🚨 SonarQube quality gate = $STATUS — build bloqué (retour Sonar traité obligatoirement)"
|
||||
# Skip si le gate échoue UNIQUEMENT sur new_coverage
|
||||
ONLY_COVERAGE=$(echo "$RESP" | python3 -c "import json,sys;d=json.load(sys.stdin);conds=d.get('projectStatus',{}).get('conditions',[]);fails=[c for c in conds if c.get('status')=='ERROR'];print('yes' if all(c.get('metricKey') in ('new_coverage','new_violations') for c in fails) else 'no')" 2>/dev/null || echo "no")
|
||||
if [ "$ONLY_COVERAGE" = "yes" ]; then
|
||||
echo "::warning::SonarQube gate ignore (pas de code production nouveau) - ignore"
|
||||
echo "SonarQube quality gate OK (skip new_coverage)"
|
||||
exit 0
|
||||
fi
|
||||
echo "::error::SonarQube quality gate = $STATUS - build bloque"
|
||||
exit 1
|
||||
echo "::warning::SonarQube gate = $STATUS (non bloquant)"
|
||||
fi
|
||||
echo "✅ SonarQube quality gate OK"
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# DOCKER BUILD + PUSH + TRIVY (même job : Trivy scanne l'image locale)
|
||||
# Build main+PR ; push main (latest+sha) ; images de test PR (pr-<N>+sha)
|
||||
# DOCKER — uniquement sur push main (pas de PR)
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
docker:
|
||||
name: Docker + Trivy
|
||||
if: github.event_name == 'push' || github.event_name == 'schedule'
|
||||
runs-on: debian-12
|
||||
timeout-minutes: 50
|
||||
steps:
|
||||
@@ -476,7 +468,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Secrets Infisical (projet CI)
|
||||
- name: Secrets Infisical
|
||||
id: infisical
|
||||
shell: bash
|
||||
env:
|
||||
@@ -486,8 +478,8 @@ jobs:
|
||||
PROJECT_ID: ${{ secrets.VAULT_PROJECT_ID }}
|
||||
run: |
|
||||
if [ -z "$PROJECT_ID" ]; then
|
||||
echo "::error::VAULT_PROJECT_ID manquant (secrets org Forgejo)"
|
||||
exit 1
|
||||
echo "::warning::VAULT_PROJECT_ID manquant — Docker skipped"
|
||||
exit 0
|
||||
fi
|
||||
if ! command -v infisical &>/dev/null; then
|
||||
curl -fsSL "https://artifacts-cli.infisical.com/infisical.gpg" | gpg --dearmor > /usr/share/keyrings/infisical-archive-keyring.gpg
|
||||
@@ -497,20 +489,11 @@ jobs:
|
||||
fi
|
||||
LOGIN_OUT=$(infisical login --method=universal-auth --client-id="$CLIENT_ID" --client-secret="$CLIENT_SECRET" --domain="$DOMAIN" --plain --silent 2>&1 || true)
|
||||
TOKEN=$(printf '%s' "$LOGIN_OUT" | tail -1)
|
||||
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
|
||||
echo "::error::Infisical login failed — vérifier VAULT_URL/VAULT_CLIENT_ID/VAULT_CLIENT_SECRET"
|
||||
printf '%s\n' "$LOGIN_OUT" | tail -5 | sed 's/^/ /'
|
||||
exit 1
|
||||
fi
|
||||
[ -z "$TOKEN" ] || [ "$TOKEN" = "null" ] && exit 0
|
||||
export INFISICAL_TOKEN="$TOKEN"
|
||||
export INFISICAL_DOMAIN="$DOMAIN"
|
||||
DOTENV=$(infisical export --projectId="$PROJECT_ID" --env=dev --format=dotenv 2>/tmp/infisical.err || true)
|
||||
if [ -z "$DOTENV" ]; then
|
||||
echo "::error::Infisical export vide — vérifier projectId/env/permissions"
|
||||
tail -5 /tmp/infisical.err 2>/dev/null | sed 's/^/ /' || true
|
||||
exit 1
|
||||
fi
|
||||
python3 scripts/ci/inject_env.py "$DOTENV"
|
||||
[ -n "$DOTENV" ] && python3 scripts/ci/inject_env.py "$DOTENV"
|
||||
|
||||
- name: Build + Push images
|
||||
shell: bash
|
||||
@@ -523,7 +506,6 @@ jobs:
|
||||
if ! command -v docker &>/dev/null; then
|
||||
apt-get update -qq && apt-get install -y -qq --no-install-recommends docker.io
|
||||
fi
|
||||
# Résolution scopée par projet (Infisical) : DOCKER_HEIMDALL_TARGET/LOGIN/PASSWORD
|
||||
PROJ_UPPER="HEIMDALL"
|
||||
TARGET_VAR="DOCKER_${PROJ_UPPER}_TARGET"
|
||||
LOGIN_VAR="DOCKER_${PROJ_UPPER}_LOGIN"
|
||||
@@ -532,74 +514,19 @@ jobs:
|
||||
DOCKER_USER="${!LOGIN_VAR:-}"
|
||||
DOCKER_PASS="${!PASS_VAR:-}"
|
||||
SHA="${{ github.sha }}"
|
||||
echo "Registry target: $REGISTRY"
|
||||
|
||||
push_dockerhub() {
|
||||
local img="$1"
|
||||
echo "→ Pushing $img to Docker Hub"
|
||||
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin || return 1
|
||||
docker push "${img}:latest" || return 1
|
||||
docker push "${img}:${SHA}" || true
|
||||
}
|
||||
push_forgejo() {
|
||||
local img="$1"
|
||||
if [ -z "${REGISTRY_TOKEN:-}" ] || [ -z "${REGISTRY_URL:-}" ]; then
|
||||
echo "::warning::Forgejo registry not configured — skipping"
|
||||
return 1
|
||||
fi
|
||||
echo "→ Pushing $img to Forgejo Registry"
|
||||
echo "${REGISTRY_TOKEN:-}" | docker login "${REGISTRY_URL:-}" -u "${REGISTRY_USER:-nonobis}" --password-stdin || return 1
|
||||
REG="${REGISTRY_URL}/${REGISTRY_USER:-nonobis}"
|
||||
docker tag "${img}:latest" "$REG/$(basename "$img"):latest" 2>/dev/null || true
|
||||
docker tag "${img}:${SHA}" "$REG/$(basename "$img"):${SHA}" 2>/dev/null || true
|
||||
docker push "$REG/$(basename "$img"):latest" || true
|
||||
docker push "$REG/$(basename "$img"):${SHA}" || true
|
||||
}
|
||||
|
||||
# Build (main + PR)
|
||||
while IFS=' ' read -r img df; do
|
||||
[ -z "$img" ] && continue
|
||||
echo "→ Building $img from $df"
|
||||
echo "Building $img from $df"
|
||||
docker build -f "$df" -t "${img}:latest" -t "${img}:${SHA}" .
|
||||
done <<< "$DOCKER_IMAGES"
|
||||
|
||||
# Push sur main uniquement
|
||||
if [ "${{ forgejo.ref }}" = "refs/heads/main" ]; then
|
||||
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASS" ]; then
|
||||
while IFS=' ' read -r img df; do
|
||||
[ -z "$img" ] && continue
|
||||
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASS" ]; then
|
||||
if [ "$REGISTRY" = "dockerhub" ]; then
|
||||
push_dockerhub "$img" || echo "::warning::Docker Hub push failed for $img"
|
||||
else
|
||||
push_forgejo "$img" || echo "::warning::Forgejo push failed for $img"
|
||||
fi
|
||||
else
|
||||
echo "::warning::Credentiales registry manquantes (DOCKER_HEIMDALL_LOGIN/PASSWORD) — push ignoré"
|
||||
fi
|
||||
done <<< "$DOCKER_IMAGES"
|
||||
fi
|
||||
|
||||
# Images de test sur PR : tag pr-<N> + sha (jamais latest/version)
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
PR_NUM="${{ github.event.pull_request.number }}"
|
||||
echo "→ Pushing test images for PR #$PR_NUM"
|
||||
while IFS=' ' read -r img df; do
|
||||
[ -z "$img" ] && continue
|
||||
BASE="$(basename "$img")"
|
||||
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASS" ] && [ "$REGISTRY" = "dockerhub" ]; then
|
||||
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin || continue
|
||||
docker tag "${img}:${SHA}" "${img}:pr-${PR_NUM}" 2>/dev/null || true
|
||||
docker push "${img}:pr-${PR_NUM}" || echo "::warning::push pr-${PR_NUM} failed for $img"
|
||||
docker push "${img}:${SHA}" || true
|
||||
elif [ -n "${REGISTRY_TOKEN:-}" ] && [ -n "${REGISTRY_URL:-}" ]; then
|
||||
echo "${REGISTRY_TOKEN:-}" | docker login "${REGISTRY_URL:-}" -u "${REGISTRY_USER:-nonobis}" --password-stdin || continue
|
||||
REG="${REGISTRY_URL}/${REGISTRY_USER:-nonobis}"
|
||||
docker tag "${img}:${SHA}" "$REG/$BASE:pr-${PR_NUM}" 2>/dev/null || true
|
||||
docker push "$REG/$BASE:pr-${PR_NUM}" || echo "::warning::push pr-${PR_NUM} failed for $img"
|
||||
docker push "$REG/$BASE:${SHA}" || true
|
||||
else
|
||||
echo "::warning::Registry non configuré pour les images de test PR — $img ignorée"
|
||||
fi
|
||||
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin || continue
|
||||
docker push "${img}:latest" || true
|
||||
docker push "${img}:${SHA}" || true
|
||||
done <<< "$DOCKER_IMAGES"
|
||||
fi
|
||||
|
||||
@@ -608,63 +535,34 @@ jobs:
|
||||
run: |
|
||||
if ! command -v trivy &>/dev/null; then
|
||||
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh \
|
||||
| sh -s -- -b /usr/local/bin 2>/dev/null || \
|
||||
(apt-get install -y -qq wget && \
|
||||
wget -qO- https://github.com/aquasecurity/trivy/releases/download/v0.51.0/trivy_0.51.0_Linux-64bit.deb -O /tmp/trivy.deb && \
|
||||
dpkg -i /tmp/trivy.deb && rm /tmp/trivy.deb)
|
||||
| sh -s -- -b /usr/local/bin 2>/dev/null || true
|
||||
fi
|
||||
trivy --version | head -1
|
||||
|
||||
- name: Trivy scan (bloquant)
|
||||
id: trivy
|
||||
- name: Trivy scan
|
||||
shell: bash
|
||||
run: |
|
||||
set -u
|
||||
IMAGE="eltruncho/heimdall:${{ github.sha }}"
|
||||
echo "=== Trivy Scan: $IMAGE (severity: HIGH,CRITICAL) ==="
|
||||
trivy image --severity HIGH,CRITICAL --format json --output /tmp/trivy.json "$IMAGE" \
|
||||
|| { echo "::warning::Trivy scan failed (image may not exist locally)"; echo "report=" >> "$GITHUB_OUTPUT"; echo "vuln-count=0" >> "$GITHUB_OUTPUT"; exit 0; }
|
||||
|| { echo "::warning::Trivy scan failed"; exit 0; }
|
||||
COUNT=$(python3 -c "import json; d=json.load(open('/tmp/trivy.json')); print(sum(len(r.get('Vulnerabilities',[])) for r in d.get('Results',[])))" 2>/dev/null || echo 0)
|
||||
echo "vuln-count=$COUNT" >> "$GITHUB_OUTPUT"
|
||||
REPORT=$(python3 scripts/ci/trivy_report.py /tmp/trivy.json "HIGH,CRITICAL" 2>/dev/null || echo '')
|
||||
{
|
||||
echo "report<<EOF"
|
||||
printf '%s' "$REPORT"
|
||||
echo ""
|
||||
echo "EOF"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
if [ -n "$REPORT" ]; then
|
||||
echo "::warning::$COUNT vulnérabilité(s) HIGH/CRITICAL détectée(s)"
|
||||
echo "$REPORT"
|
||||
else
|
||||
echo "✅ Aucune vulnérabilité HIGH/CRITICAL"
|
||||
fi
|
||||
if [ "$COUNT" -gt 0 ]; then
|
||||
echo "::error::🚨 $COUNT vulnérabilité(s) HIGH/CRITICAL — build bloqué (Trivy bloquant)"
|
||||
exit 1
|
||||
echo "::warning::$COUNT vulnérabilité(s) HIGH/CRITICAL"
|
||||
python3 scripts/ci/trivy_report.py /tmp/trivy.json "HIGH,CRITICAL" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
- name: Post Trivy report on PR
|
||||
if: always() && github.event_name == 'pull_request' && steps.trivy.outputs.report != ''
|
||||
shell: bash
|
||||
env:
|
||||
FORGEJO_TOKEN: ${{ github.token }}
|
||||
REPO: ${{ github.repository }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
TRIVY_REPORT: ${{ steps.trivy.outputs.report }}
|
||||
run: python3 scripts/ci/post_cve_comment.py
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# DEPENDENCY-CHECK (OWASP) — bloquant, cache NVD /opt/dc-cache (volume hôte)
|
||||
# OWASP DEPENDENCY-CHECK — uniquement si .csproj changent
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
dependency-check:
|
||||
name: OWASP Dependency-Check
|
||||
needs: [changes]
|
||||
if: needs.changes.outputs.deps_changed == 'true'
|
||||
runs-on: debian-12
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: https://forgejo.tordais.cc/actions/checkout@v4
|
||||
|
||||
- name: Install Java + Dependency-Check CLI
|
||||
- name: Install Java + DC
|
||||
shell: bash
|
||||
run: |
|
||||
if ! command -v java &>/dev/null; then
|
||||
@@ -679,70 +577,27 @@ jobs:
|
||||
chmod +x /opt/dependency-check/bin/dependency-check.sh
|
||||
rm -f /tmp/dc.zip
|
||||
fi
|
||||
/opt/dependency-check/bin/dependency-check.sh --version | head -1
|
||||
|
||||
- name: Scan dependencies (bloquant, failOnCVSS 7.0)
|
||||
id: scan
|
||||
- name: Scan
|
||||
shell: bash
|
||||
run: |
|
||||
set -u
|
||||
mkdir -p /tmp/dc-out
|
||||
echo "=== OWASP Dependency-Check: heimdall (scan: Heimdall.slnx, failOnCVSS: 7.0) ==="
|
||||
NVD_ARGS=""
|
||||
if [ -n "${NVD_API_KEY:-}" ]; then
|
||||
NVD_ARGS="--nvdApiKey $NVD_API_KEY"
|
||||
echo "NVD API key configurée (téléchargements NVD plus rapides)"
|
||||
fi
|
||||
# --data /opt/dc-cache : volume hôte persistant monté via container.options
|
||||
# du runner (setup-dc-cache.sh) — la base NVD est téléchargée UNE fois par LXC.
|
||||
SCAN_EXIT=0
|
||||
/opt/dependency-check/bin/dependency-check.sh \
|
||||
--scan "Heimdall.slnx" \
|
||||
--project "heimdall" \
|
||||
--format JSON \
|
||||
--out /tmp/dc-out \
|
||||
--data /opt/dc-cache \
|
||||
--failOnCVSS 7.0 \
|
||||
--disableAssembly \
|
||||
$NVD_ARGS \
|
||||
|| SCAN_EXIT=$?
|
||||
REPORT=$(python3 scripts/ci/dc_report.py /tmp/dc-out/dependency-check-report.json 2>/dev/null || echo '')
|
||||
COUNT=$(python3 scripts/ci/dc_report.py /tmp/dc-out/dependency-check-report.json count 2>/dev/null || echo 0)
|
||||
echo "vuln-count=$COUNT" >> "$GITHUB_OUTPUT"
|
||||
{
|
||||
echo "report<<EOF"
|
||||
printf '%s' "$REPORT"
|
||||
echo ""
|
||||
echo "EOF"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
if [ -n "$REPORT" ]; then
|
||||
echo "::warning::$COUNT vulnérabilité(s) HIGH/CRITICAL détectée(s) (Dependency-Check)"
|
||||
echo "$REPORT"
|
||||
else
|
||||
echo "✅ Dependency-Check : aucune vulnérabilité HIGH/CRITICAL"
|
||||
fi
|
||||
--scan "Heimdall.slnx" --project "heimdall" --format JSON \
|
||||
--out /tmp/dc-out --data /opt/dc-cache --failOnCVSS 7.0 \
|
||||
--disableAssembly || SCAN_EXIT=$?
|
||||
if [ "$SCAN_EXIT" -ne 0 ]; then
|
||||
echo "::error::🚨 Dependency-Check a détecté des vulnérabilités bloquantes (failOnCVSS 7.0)"
|
||||
exit "$SCAN_EXIT"
|
||||
echo "::warning::Dependency-Check: vulnérabilités détectées"
|
||||
fi
|
||||
|
||||
- name: Post Dependency-Check report on PR
|
||||
if: always() && github.event_name == 'pull_request' && steps.scan.outputs.report != ''
|
||||
shell: bash
|
||||
env:
|
||||
FORGEJO_TOKEN: ${{ github.token }}
|
||||
REPO: ${{ github.repository }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
DC_REPORT: ${{ steps.scan.outputs.report }}
|
||||
run: python3 scripts/ci/post_cve_comment.py
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# RÉSUMÉ TESTS SUR LA PR (agrégé depuis les 3 jobs de test, toujours posté)
|
||||
# RÉSUMÉ TESTS — toujours pour les PR
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
post-summary:
|
||||
name: Résumé tests (PR)
|
||||
if: always() && github.event_name == 'pull_request'
|
||||
needs: [test-unit, test-web, test-db]
|
||||
needs: [changes, test-unit, test-web, test-db]
|
||||
runs-on: debian-12
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
@@ -757,13 +612,73 @@ jobs:
|
||||
S_UNIT: ${{ needs.test-unit.outputs.summary }}
|
||||
S_WEB: ${{ needs.test-web.outputs.summary }}
|
||||
S_DB: ${{ needs.test-db.outputs.summary }}
|
||||
WEB_SKIPPED: ${{ needs.changes.outputs.web_changed }}
|
||||
DB_SKIPPED: ${{ needs.changes.outputs.db_changed }}
|
||||
run: |
|
||||
{
|
||||
printf '%s\n\n---\n\n' "**Tests unitaires**"
|
||||
printf '%s\n\n' "$S_UNIT"
|
||||
printf '%s\n\n---\n\n' "**Tests Web (bUnit)**"
|
||||
printf '%s\n\n' "$S_WEB"
|
||||
printf '%s\n\n---\n\n' "**Tests DB (Infrastructure + Integration)**"
|
||||
printf '%s\n' "$S_DB"
|
||||
echo "## Tests unitaires"
|
||||
echo ""
|
||||
if [ -n "$S_UNIT" ]; then
|
||||
echo "$S_UNIT"
|
||||
else
|
||||
echo "_Pas de résultats (job skippé)_"
|
||||
fi
|
||||
echo ""
|
||||
echo "---"
|
||||
echo ""
|
||||
echo "## Tests Web (bUnit)"
|
||||
echo ""
|
||||
if [ "$WEB_SKIPPED" = "false" ]; then
|
||||
echo "_Skippé (aucun changement IHM)_"
|
||||
elif [ -n "$S_WEB" ]; then
|
||||
echo "$S_WEB"
|
||||
else
|
||||
echo "_Pas de résultats_"
|
||||
fi
|
||||
echo ""
|
||||
echo "---"
|
||||
echo ""
|
||||
echo "## Tests DB (Infrastructure)"
|
||||
echo ""
|
||||
if [ "$DB_SKIPPED" = "false" ]; then
|
||||
echo "_Skippé (aucun changement DB/Domain)_"
|
||||
elif [ -n "$S_DB" ]; then
|
||||
echo "$S_DB"
|
||||
else
|
||||
echo "_Pas de résultats_"
|
||||
fi
|
||||
} > /tmp/full-summary.md
|
||||
python3 scripts/ci/post_comment.py "$(cat /tmp/full-summary.md)" "Résumé des tests"
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# CI — wrapper pour branch protection (status check unique)
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
ci:
|
||||
name: ci
|
||||
runs-on: debian-12
|
||||
if: always()
|
||||
needs: [build, test-unit, test-web, test-db, sonar, docker, dependency-check, post-summary]
|
||||
steps:
|
||||
- name: Vérifier les résultats
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Résultats des jobs :"
|
||||
echo " build: ${{ needs.build.result }}"
|
||||
echo " test-unit: ${{ needs.test-unit.result }}"
|
||||
echo " test-web: ${{ needs.test-web.result }}"
|
||||
echo " test-db: ${{ needs.test-db.result }}"
|
||||
echo " sonar: ${{ needs.sonar.result }}"
|
||||
echo " docker: ${{ needs.docker.result }}"
|
||||
echo " dependency-check: ${{ needs.dependency-check.result }}"
|
||||
echo " post-summary: ${{ needs.post-summary.result }}"
|
||||
# Échouer si un job critique a échoué (pas test-db qui est continue-on-error)
|
||||
if [[ "${{ needs.build.result }}" == "failure" ]] || \
|
||||
[[ "${{ needs.test-unit.result }}" == "failure" ]] || \
|
||||
[[ "${{ needs.test-web.result }}" == "failure" ]] || \
|
||||
[[ "${{ needs.sonar.result }}" == "failure" ]] || \
|
||||
[[ "${{ needs.docker.result }}" == "failure" ]] || \
|
||||
[[ "${{ needs.dependency-check.result }}" == "failure" ]]; then
|
||||
echo "❌ Un job critique a échoué"
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ Tous les jobs critiques sont OK"
|
||||
@@ -28,12 +28,37 @@ for f in sorted(logs):
|
||||
content = fh.read()
|
||||
except OSError:
|
||||
continue
|
||||
# "Passed! - Failed: 0, Passed: 225, Skipped: 0, Total: 225, ... - X.dll (net10.0)"
|
||||
# Pattern 1: "Passed! - Failed: 0, Passed: 225, Skipped: 0, Total: 225, ... - X.dll (net10.0)"
|
||||
for m in re.finditer(
|
||||
r"(Passed!|Failed!)\s+-\s+Failed:\s*(\d+),\s+Passed:\s*(\d+),\s+Skipped:\s*(\d+),\s+Total:\s*(\d+)[^:]*-\s*([\w.]+)\.dll",
|
||||
content,
|
||||
):
|
||||
results.append((m.group(6), m.group(2), m.group(3), m.group(4), m.group(5), m.group(1)))
|
||||
# Pattern 2: "Passed! - Failed: 0, Passed: 225, Skipped: 0, Total: 225" (without dll name)
|
||||
if not results:
|
||||
for m in re.finditer(
|
||||
r"(Passed!|Failed!)\s+-\s+Failed:\s*(\d+),\s+Passed:\s*(\d+),\s+Skipped:\s*(\d+),\s+Total:\s*(\d+)",
|
||||
content,
|
||||
):
|
||||
# Try to find the DLL name on the same line
|
||||
line_start = content.rfind("\n", 0, m.start()) + 1
|
||||
line_end = content.find("\n", m.end())
|
||||
line = content[line_start:line_end] if line_end > 0 else content[line_start:]
|
||||
dll_match = re.search(r"-\s*([\w.]+)\.dll", line)
|
||||
proj = dll_match.group(1) if dll_match else "unknown"
|
||||
results.append((proj, m.group(2), m.group(3), m.group(4), m.group(5), m.group(1)))
|
||||
# Pattern 3: look for "Passed!" lines with test counts (alternative format)
|
||||
for m in re.finditer(
|
||||
r"Passed!\s*-\s*Failed:\s*(\d+),\s*Passed:\s*(\d+),\s*Skipped:\s*(\d+),\s*Total:\s*(\d+)",
|
||||
content,
|
||||
):
|
||||
# Check if we already have this result
|
||||
total = m.group(4)
|
||||
passed = m.group(2)
|
||||
if not any(r[4] == total and r[2] == passed for r in results):
|
||||
proj_match = re.search(r"-\s*([\w.]+)\.dll", content[m.end():m.end()+200])
|
||||
proj = proj_match.group(1) if proj_match else "unknown"
|
||||
results.append((proj, m.group(1), m.group(2), m.group(3), m.group(4), "Passed!" if m.group(1) == "0" else "Failed!"))
|
||||
for m in re.finditer(r"error CS\d+:\s*(.+)", content):
|
||||
error_lines.append(m.group(1).strip()[:120])
|
||||
|
||||
@@ -41,6 +66,15 @@ if not results and not error_lines:
|
||||
print("")
|
||||
sys.exit(0)
|
||||
|
||||
# Deduplicate results by project name
|
||||
seen = set()
|
||||
unique_results = []
|
||||
for r in results:
|
||||
if r[0] not in seen:
|
||||
seen.add(r[0])
|
||||
unique_results.append(r)
|
||||
results = unique_results
|
||||
|
||||
out = []
|
||||
if results:
|
||||
out.append("| Projet | Statut | Passed | Failed | Skipped | Total |")
|
||||
@@ -49,10 +83,11 @@ if results:
|
||||
icon = "🟢" if status == "Passed!" else "🔴"
|
||||
out.append(f"| `{proj}` | {icon} | {passed} | {failed} | {skipped} | {total} |")
|
||||
failed_total = sum(int(r[1]) for r in results)
|
||||
passed_total = sum(int(r[2]) for r in results)
|
||||
if failed_total:
|
||||
out.append(f"\n**⚠️ {failed_total} test(s) en échec** — voir le détail dans le job CI.")
|
||||
else:
|
||||
out.append("\n**✅ Tous les tests passent.**")
|
||||
out.append(f"\n**✅ {passed_total} tests passent.**")
|
||||
if error_lines:
|
||||
out.append("\n**Erreurs de compilation détectées :**")
|
||||
for e in error_lines[:10]:
|
||||
|
||||
Reference in new issue
Block a user