diff --git a/.forgejo/templates b/.forgejo/templates new file mode 160000 index 0000000..1f3a383 --- /dev/null +++ b/.forgejo/templates @@ -0,0 +1 @@ +Subproject commit 1f3a383703371ae90b070e0a44255fb996b4c499 diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 000fb8d..5e618ad 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -1,6 +1,6 @@ -# ─── Heimdall — Forgejo CI Pipeline ──────────────────────────── -# Runner: Debian 12 (auto-scaler / LXC) -# Actions: mirror sur forgejo.tordais.cc (checkout, setup-dotnet, cache) +# Heimdall — CI Pipeline +# Utilise les templates partagés depuis .forgejo/templates/ (submodule) +# Voir https://forgejo.tordais.cc/nonobis/templates name: CI @@ -13,175 +13,29 @@ on: pull_request: branches: [main] -env: - DOTNET_VERSION: "10.0" - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - DOTNET_NOLOGO: 1 - -concurrency: - group: ci-${{ forgejo.ref }} - cancel-in-progress: true - jobs: - build-and-test: - runs-on: debian-12 - - # LXC runner (auto-scaler) does NOT support Docker service containers. - # PostgreSQL is installed via apt and started directly on the runner. - steps: - - name: Checkout - uses: https://forgejo.tordais.cc/actions/checkout@v4 - with: - fetch-depth: 0 - - # ── Housekeeping before the build ────────────────────────── - - name: Pre-build cleanup - run: | - echo "=== Disk before cleanup ===" - df -h / /var/lib/docker 2>/dev/null || df -h / - # Remove leftover Docker images from previous runs - docker system prune -af 2>/dev/null || true - # Clean apt cache - apt-get clean 2>/dev/null || true - rm -rf /var/lib/apt/lists/* 2>/dev/null || true - # Remove temp files from previous CI runs - rm -rf /tmp/* /var/tmp/* 2>/dev/null || true - # Clean .NET temporary files - rm -rf /tmp/NuGetScratch 2>/dev/null || true - echo "=== Disk after cleanup ===" - df -h / - - - name: Start PostgreSQL - # Runner: Debian 12 LXC — sudo is NOT available (use su - postgres). - # Store data on /dev/shm (tmpfs/RAM) to avoid disk space limits. - run: | - apt-get -qq update - apt-get install -y -qq --no-install-recommends postgresql-15 postgresql-client-15 - PGDATA=/dev/shm/pgdata - rm -rf "$PGDATA" - su - postgres -c "/usr/lib/postgresql/15/bin/initdb -D $PGDATA --auth=trust --no-locale --encoding=UTF8" - # Configure password auth for the heimdall user (md5 for non-local socket) - su - postgres -c "cat >> $PGDATA/pg_hba.conf << 'EOF' - host all all 127.0.0.1/32 md5 - host all all ::1/128 md5 - EOF" - # Start PostgreSQL - su - postgres -c "/usr/lib/postgresql/15/bin/pg_ctl -D $PGDATA -l /dev/shm/pgdata.log start" - # Wait for startup - for i in $(seq 1 15); do - su - postgres -c "/usr/lib/postgresql/15/bin/pg_isready -h localhost" > /dev/null 2>&1 && break - sleep 1 - done - # Create user and database - su - postgres -c "psql -c \"CREATE USER heimdall WITH PASSWORD 'heimdall';\"" 2>/dev/null || true - su - postgres -c "psql -c \"CREATE DATABASE heimdall_test OWNER heimdall;\"" 2>/dev/null || true - # Verify connectivity - PGPASSWORD=heimdall psql -U heimdall -d heimdall_test -h localhost -c "SELECT 1" > /dev/null 2>&1 || \ - (echo "ERROR: Cannot connect to PostgreSQL"; exit 1) - echo "PostgreSQL is ready on tmpfs ($PGDATA)" - - - 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 - key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Build.props') }} - restore-keys: | - ${{ runner.os }}-nuget- - - - name: Restore - run: dotnet restore - - - name: Build - run: dotnet build --no-restore -c Release - - - name: Test - run: dotnet test --no-build -c Release - env: - DATABASE_URL: "Host=localhost;Port=5432;Database=heimdall_test;Username=heimdall;Password=heimdall" - - # ── Housekeeping after the build ────────────────────────── - - name: Post-build cleanup - if: always() - run: | - docker system prune -af 2>/dev/null || true - apt-get clean 2>/dev/null || true - rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* 2>/dev/null || true - rm -rf /root/.dotnet/**/debug/*.log 2>/dev/null || true - - docker-build: - needs: build-and-test - runs-on: debian-12 - if: forgejo.ref == 'refs/heads/main' - - steps: - - name: Checkout - uses: https://forgejo.tordais.cc/actions/checkout@v4 - with: - fetch-depth: 0 - - - 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 - key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Build.props') }} - restore-keys: | - ${{ runner.os }}-nuget- - - - name: Restore & Build - run: | - dotnet restore - dotnet build --no-restore -c Release - - - name: Install Docker CLI - run: | - apt-get -qq update - apt-get install -y -qq --no-install-recommends docker.io - - - name: Build Heimdall image (Web API + Blazor UI + background jobs) - run: | - docker build -f docker/Dockerfile -t heimdall:latest . - - - name: Build Agent image - run: | - docker build -f docker/Dockerfile.agent -t heimdall/agent:latest . - - - name: Login to Docker Hub - if: secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' - run: | - echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin - - - name: Tag & Push Heimdall image - if: secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' - run: | - docker tag heimdall:latest \ - ${{ secrets.DOCKER_USERNAME }}/heimdall:${{ forgejo.sha }} - docker tag heimdall:latest \ - ${{ secrets.DOCKER_USERNAME }}/heimdall:latest - docker push ${{ secrets.DOCKER_USERNAME }}/heimdall:${{ forgejo.sha }} - docker push ${{ secrets.DOCKER_USERNAME }}/heimdall:latest - - - name: Tag & Push Agent image - if: secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' - run: | - docker tag heimdall/agent:latest \ - ${{ secrets.DOCKER_USERNAME }}/heimdall-agent:${{ forgejo.sha }} - docker tag heimdall/agent:latest \ - ${{ secrets.DOCKER_USERNAME }}/heimdall-agent:latest - docker push ${{ secrets.DOCKER_USERNAME }}/heimdall-agent:${{ forgejo.sha }} - docker push ${{ secrets.DOCKER_USERNAME }}/heimdall-agent:latest - - - name: Post-build cleanup (docker-build) - if: always() - run: | - docker system prune -af 2>/dev/null || true - df -h / + ci: + uses: .forgejo/templates/.forgejo/workflows/dotnet-ci.yml + with: + dotnet-version: "10.0" + solution-path: "*.slnx" + postgres-enabled: true + postgres-database: "heimdall_test" + postgres-username: "heimdall" + postgres-password: "heimdall" + coverage-enabled: true + docker-enabled: true + dockerfile: docker/Dockerfile + docker-image: nonobis/heimdall + docker-extra-images: "nonobis/heimdall-agent" + docker-extra-dockerfiles: "docker/Dockerfile.agent" + docker-buildx-cache: false + trivy-enabled: false + gitversion-enabled: false + e2e-enabled: false + secrets: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + REGISTRY_URL: ${{ secrets.REGISTRY_URL }} + REGISTRY_USER: ${{ secrets.REGISTRY_USER }} + REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} diff --git a/.gitmodules b/.gitmodules index 1f4946f..b767c85 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,6 @@ path = .opencode url = https://forgejo.tordais.cc/nonobis/opencode.git branch = main +[submodule ".forgejo/templates"] + path = .forgejo/templates + url = https://forgejo.tordais.cc/nonobis/templates.git