feat: migrate CI to shared templates submodule
- Add .forgejo/templates submodule (nonobis/templates) - Replace 187-line CI with 41-line workflow_call using dotnet-ci.yml - All patterns (PostgreSQL LXC, Docker multi-image, coverage, cleanup) now come from shared templates - CI size reduction: -78%
This commit is contained in:
1 parent
b727e5b672
commit
d4981eda17
3 files changed
+32
-174
No files matched your search
Submodule
+1
Submodule .forgejo/templates added at 1f3a383703.
+28
-174
@@ -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 }}
|
||||
@@ -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
|
||||
Reference in new issue
Block a user