Files
Heimdall/.forgejo/workflows/ci.yml
T
Arnaud Dartois 6d075e37a4 feat(ci): unified pipeline with all features (coverage, sonar, e2e, trivy, gitversion, cleanup)
All features controlled by env vars. Same structure across all projects.
2026-07-22 09:15:16 +00:00

277 lines
11 KiB
YAML

# Heimdall — CI Pipeline (unifiée)
# Templates : https://forgejo.tordais.cc/nonobis/templates
# Secrets requis : TEMPLATES_PAT, DOCKER_USERNAME, DOCKER_PASSWORD
name: CI
on:
push:
branches: [main, develop]
paths-ignore:
- '**.md'
- '.opencode/**'
pull_request:
branches: [main]
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 }}
cancel-in-progress: true
jobs:
ci:
runs-on: debian-12
steps:
# ── 1. CHECKOUT ────────────────────────────────────
- name: Checkout project
uses: https://forgejo.tordais.cc/actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout CI templates
uses: https://forgejo.tordais.cc/actions/checkout@v4
with:
repository: nonobis/templates
token: ${{ secrets.TEMPLATES_PAT }}
path: .ci
ref: main
# ── 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
# ── 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:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Cache NuGet packages
uses: https://forgejo.tordais.cc/actions/cache@v4
with:
path: |
~/.nuget/packages
~/.local/share/NuGet/http-cache
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/*.slnx', '**/Directory.Build.props') }}
restore-keys: |
nuget-${{ runner.os }}-
- 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 ${{ env.SOLUTION }} --nologo
- name: Build
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
- 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
env:
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
# 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' && env.DOCKERFILE != ''
run: |
if ! command -v docker &>/dev/null; then
apt-get install -y -qq --no-install-recommends docker.io
fi
- name: Build Docker image(s)
if: forgejo.ref == 'refs/heads/main' && env.DOCKERFILE != ''
env:
IMAGE: ${{ env.DOCKER_IMAGE }}
EXTRA_IMAGES: ${{ env.DOCKER_EXTRA_IMAGES }}
EXTRA_DFS: ${{ env.DOCKER_EXTRA_DOCKERFILES }}
VERSION: ${{ steps.version.outputs.version }}
run: |
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: Push Docker images
if: forgejo.ref == 'refs/heads/main' && env.DOCKERFILE != ''
env:
DOCKER_USER: ${{ secrets.DOCKER_USERNAME || secrets.DOCKER_HUB_USERNAME }}
DOCKER_PASS: ${{ secrets.DOCKER_PASSWORD || secrets.DOCKER_HUB_TOKEN }}
run: |
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
# 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