feat(ci): unified pipeline with all features (coverage, sonar, e2e, trivy, gitversion, cleanup)

All features controlled by env vars. Same structure across all projects.
This commit is contained in:
Arnaud Dartois committed 2026-07-22 09:15:16 +00:00
1 parent 91d932f4d3
commit 6d075e37a4
1 file changed
+200 -35
+200 -35
View File
@@ -1,6 +1,6 @@
# Heimdall — CI Pipeline
# Heimdall — CI Pipeline (unifiée)
# Templates : https://forgejo.tordais.cc/nonobis/templates
# Le PAT TEMPLATES_PAT doit être configuré dans Actions → Secrets
# Secrets requis : TEMPLATES_PAT, DOCKER_USERNAME, DOCKER_PASSWORD
name: CI
@@ -15,8 +15,26 @@ on:
env:
DOTNET_VERSION: "10.0"
NODE_VERSION: "20"
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1
ASPNETCORE_ENVIRONMENT: Testing
# Features toggle
PG_ENABLED: "true"
GITVERSION_ENABLED: "false"
NODE_ENABLED: "false"
E2E_ENABLED: "false"
SONAR_ENABLED: "false"
TRIVY_ENABLED: "false"
# Project
PROJECT_NAME: heimdall
SOLUTION: "*.slnx"
DOCKERFILE: docker/Dockerfile
DOCKER_IMAGE: nonobis/heimdall
DOCKER_EXTRA_IMAGES: "nonobis/heimdall-agent"
DOCKER_EXTRA_DOCKERFILES: "docker/Dockerfile.agent"
concurrency:
group: ci-${{ forgejo.ref }}
@@ -26,6 +44,7 @@ jobs:
ci:
runs-on: debian-12
steps:
# ── 1. CHECKOUT ────────────────────────────────────
- name: Checkout project
uses: https://forgejo.tordais.cc/actions/checkout@v4
with:
@@ -39,14 +58,22 @@ jobs:
path: .ci
ref: main
# ── PostgreSQL (LXC tmpfs) ──────────────────────────────
- uses: ./.ci/.forgejo/actions/postgres-start
with:
database: heimdall_test
username: heimdall
password: heimdall
# ── 2. SYSTEM ──────────────────────────────────────
- name: Install system dependencies
if: env.PG_ENABLED == 'true' || env.E2E_ENABLED == 'true'
run: |
apt-get -qq update && apt-get install -y -qq --no-install-recommends \
ca-certificates curl gnupg wget python3 ffmpeg
# ── .NET setup + cache ─────────────────────────────────
# ── 3. POSTGRESQL ──────────────────────────────────
- if: env.PG_ENABLED == 'true'
uses: ./.ci/.forgejo/actions/postgres-start
with:
database: ${{ env.PROJECT_NAME }}_test
username: ${{ env.PROJECT_NAME }}
password: ${{ env.PROJECT_NAME }}
# ── 4. .NET + CACHES ──────────────────────────────
- name: Setup .NET ${{ env.DOTNET_VERSION }}
uses: https://forgejo.tordais.cc/actions/setup-dotnet@v4
with:
@@ -62,50 +89,188 @@ jobs:
restore-keys: |
nuget-${{ runner.os }}-
# ── Build ───────────────────────────────────────────────
- name: Cache .NET tools (GitVersion)
if: env.GITVERSION_ENABLED == 'true'
uses: https://forgejo.tordais.cc/actions/cache@v4
with:
path: |
~/.dotnet/tools
~/.dotnet/tool-resolver-cache
key: dotnet-tools-${{ runner.os }}-6.8.1
# ── 5. GITVERSION ──────────────────────────────────
- if: env.GITVERSION_ENABLED == 'true'
uses: ./.ci/.forgejo/actions/setup-gitversion
id: version
# ── 6. NODE.JS (optional) ──────────────────────────
- if: env.NODE_ENABLED == 'true'
uses: https://forgejo.tordais.cc/actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- if: env.NODE_ENABLED == 'true'
uses: https://forgejo.tordais.cc/actions/cache@v4
with:
path: ~/.npm
key: npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
npm-${{ runner.os }}-
- name: npm ci
if: env.NODE_ENABLED == 'true'
run: npm ci
continue-on-error: true
# ── 7. BUILD ───────────────────────────────────────
- name: Restore
run: dotnet restore *.slnx --nologo
run: dotnet restore ${{ env.SOLUTION }} --nologo
- name: Build
run: dotnet build *.slnx --no-restore -c Release --nologo /maxcpucount
run: |
VERSION=""
if [ "$GITVERSION_ENABLED" = "true" ] && [ -n "${{ steps.version.outputs.version }}" ]; then
VERSION="-p:Version=${{ steps.version.outputs.version }} -p:DisableGitVersionTask=true"
fi
dotnet build ${{ env.SOLUTION }} --no-restore -c Release --nologo /maxcpucount $VERSION
# ── Tests ───────────────────────────────────────────────
- name: Publish (for E2E / Docker)
if: env.E2E_ENABLED == 'true' || contains(env.DOCKERFILE, 'Dockerfile')
run: |
VERSION=""
if [ "$GITVERSION_ENABLED" = "true" ]; then
VERSION="-p:Version=${{ steps.version.outputs.version }}"
fi
dotnet build ${{ env.SOLUTION }} --no-restore -c Release --nologo /maxcpucount $VERSION
# ── 8. TESTS ───────────────────────────────────────
- name: Run tests
run: dotnet test *.slnx --no-build -c Release --nologo
env:
ASPNETCORE_ENVIRONMENT: Testing
DATABASE_URL: "Host=localhost;Port=5432;Database=heimdall_test;Username=heimdall;Password=heimdall"
DATABASE_URL: ${{ env.PG_ENABLED == 'true' && format('Host=localhost;Port=5432;Database={0}_test;Username={0};Password={0}', env.PROJECT_NAME) || '' }}
run: |
set -euo pipefail
COVERAGE="--collect:\"XPlat Code Coverage\""
mkdir -p /tmp/coverage
# ── Docker (main only) ─────────────────────────────────
# Find test projects
TEST_PROJECTS=$(find . -type f -name '*.csproj' -path '*/tests/*' -not -path '*/node_modules/*' 2>/dev/null || true)
if [ -z "$TEST_PROJECTS" ]; then
echo "No test projects found"
exit 0
fi
FAIL=0
for proj in $TEST_PROJECTS; do
NAME=$(basename "$(dirname "$proj")")
echo "→ Testing: $NAME"
if dotnet test "$proj" --no-build -c Release --nologo \
--results-directory /tmp/coverage/$NAME/ \
$COVERAGE \
-p:CoverletOutputFormat=cobertura \
-p:CoverletOutput=/tmp/coverage/$NAME/; then
echo " ✅ $NAME passed"
else
echo " ❌ $NAME failed"
FAIL=1
fi
done
exit $FAIL
# ── 9. COVERAGE REPORT ─────────────────────────────
- if: always()
uses: ./.ci/.forgejo/actions/coverage-report
# ── 10. E2E TESTS ──────────────────────────────────
- if: env.E2E_ENABLED == 'true' && (forgejo.ref == 'refs/heads/main' || forgejo.event_name == 'pull_request')
uses: ./.ci/.forgejo/actions/e2e-playwright
# ── 11. SONARQUBE ──────────────────────────────────
- if: env.SONAR_ENABLED == 'true' && (forgejo.ref == 'refs/heads/main' || forgejo.event_name == 'pull_request')
uses: ./.ci/.forgejo/actions/sonar-dotnet
with:
sonar-project-key: ${{ env.PROJECT_NAME }}
sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
solution-path: ${{ env.SOLUTION }}
# ── 12. DOCKER BUILD ───────────────────────────────
- name: Install Docker CLI
if: forgejo.ref == 'refs/heads/main'
if: forgejo.ref == 'refs/heads/main' && env.DOCKERFILE != ''
run: |
if ! command -v docker &>/dev/null; then
apt-get install -y -qq --no-install-recommends docker.io
fi
- name: Build & push Heimdall
if: forgejo.ref == 'refs/heads/main'
- name: Build Docker image(s)
if: forgejo.ref == 'refs/heads/main' && env.DOCKERFILE != ''
env:
DOCKER_USER: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASS: ${{ secrets.DOCKER_PASSWORD }}
IMAGE: ${{ env.DOCKER_IMAGE }}
EXTRA_IMAGES: ${{ env.DOCKER_EXTRA_IMAGES }}
EXTRA_DFS: ${{ env.DOCKER_EXTRA_DOCKERFILES }}
VERSION: ${{ steps.version.outputs.version }}
run: |
docker build -f docker/Dockerfile -t nonobis/heimdall:latest .
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASS" ]; then
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
docker push nonobis/heimdall:latest
build_img() {
local df="$1" img="$2"
local tags="-t ${img}:latest"
[ -n "$VERSION" ] && tags="$tags -t ${img}:${VERSION}"
tags="$tags -t ${img}:${{ forgejo.sha }}"
docker build -f "$df" $tags .
}
build_img "${{ env.DOCKERFILE }}" "$IMAGE"
# Extra images (agent, migrator, etc.)
if [ -n "$EXTRA_IMAGES" ] && [ -n "$EXTRA_DFS" ]; then
IFS=' ' read -ra IMG_LIST <<< "$EXTRA_IMAGES"
IFS=' ' read -ra DF_LIST <<< "$EXTRA_DFS"
for i in "${!IMG_LIST[@]}"; do
[ -n "${IMG_LIST[$i]}" ] && [ -n "${DF_LIST[$i]}" ] && build_img "${DF_LIST[$i]}" "${IMG_LIST[$i]}"
done
fi
- name: Build & push Agent
if: forgejo.ref == 'refs/heads/main'
- name: Push Docker images
if: forgejo.ref == 'refs/heads/main' && env.DOCKERFILE != ''
env:
DOCKER_USER: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASS: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USER: ${{ secrets.DOCKER_USERNAME || secrets.DOCKER_HUB_USERNAME }}
DOCKER_PASS: ${{ secrets.DOCKER_PASSWORD || secrets.DOCKER_HUB_TOKEN }}
run: |
docker build -f docker/Dockerfile.agent -t nonobis/heimdall-agent:latest .
if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASS" ]; then
docker push nonobis/heimdall-agent:latest
if [ -z "$DOCKER_USER" ] || [ -z "$DOCKER_PASS" ]; then
echo "Docker credentials not set — skipping push"
exit 0
fi
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
push_img() {
local img="$1"
docker push "${img}:latest"
[ -n "$VERSION" ] && docker push "${img}:${VERSION}" || true
docker push "${img}:${{ forgejo.sha }}"
}
VERSION="${{ steps.version.outputs.version }}"
push_img "${{ env.DOCKER_IMAGE }}"
EXTRA="${{ env.DOCKER_EXTRA_IMAGES }}"
if [ -n "$EXTRA" ]; then
for img in $EXTRA; do [ -n "$img" ] && push_img "$img"; done
fi
# ── Cleanup safe ────────────────────────────────────────
- uses: ./.ci/.forgejo/actions/cleanup-safe
# Forgejo Registry
if [ -n "${{ secrets.REGISTRY_TOKEN }}" ] && [ -n "${{ secrets.REGISTRY_URL }}" ]; then
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "${{ secrets.REGISTRY_URL }}" \
-u "${{ secrets.REGISTRY_USER || 'nonobis' }}" --password-stdin || true
REG="${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER || 'nonobis' }}"
docker tag "${{ env.DOCKER_IMAGE }}:latest" "$REG/${{ github.repository }}:latest" 2>/dev/null || true
[ -n "$VERSION" ] && docker tag "${{ env.DOCKER_IMAGE }}:latest" "$REG/${{ github.repository }}:$VERSION" 2>/dev/null || true
docker push "$REG/${{ github.repository }}:latest" 2>/dev/null || true
[ -n "$VERSION" ] && docker push "$REG/${{ github.repository }}:$VERSION" 2>/dev/null || true
fi
# ── 13. TRIVY SCAN ─────────────────────────────────
- if: env.TRIVY_ENABLED == 'true' && forgejo.ref == 'refs/heads/main' && env.DOCKERFILE != ''
uses: ./.ci/.forgejo/actions/trivy-scan
with:
image: ${{ env.DOCKER_IMAGE }}:${{ steps.version.outputs.version }}
# ── 14. CLEANUP ────────────────────────────────────
- if: always()
uses: ./.ci/.forgejo/actions/cleanup-safe