CI: alle jobs op runs-on: linux; deploy draagbaar (sudo/ssh-tools alleen indien nodig), backend-test met vrije poort

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 14:15:18 +01:00
co-authored by Claude Sonnet 5.5
parent e360f16125
commit 5b068bfa34
2 changed files with 39 additions and 27 deletions
+28 -24
View File
@@ -140,10 +140,7 @@ jobs:
backend-test:
needs: [changes, backend-build]
if: needs.changes.outputs.backend == 'true'
runs-on: raspberry-pi
# Pi only for now: the job starts MariaDB with the `docker` CLI on fixed host port 3307 (host networking), which
# is not verified on the PC runner (podman, and port 3307 is used there by the local dev database). Switch to
# `linux` after a successful trial run on the PC.
runs-on: linux
# Added for SlpModularCms.Api.Tests (slpsoftware-api feature, NFR-CS-01): its pipeline
# regression tests boot the real Api host via WebApplicationFactory, which unconditionally
# runs CmsHost.ConfigurePipeline's startup migration (MigrateCoreDatabase) -- unlike every
@@ -158,7 +155,7 @@ jobs:
# this runner already answers on (root auth was rejected by a server that was clearly NOT
# the freshly-initialized container: "Access denied ... using password: YES" against a
# password nothing but this job ever set). An explicitly `docker run` container below,
# published on host port 3307 instead of 3306, avoids that collision entirely.
# published on a free host port chosen by the engine (not 3306), avoids that collision entirely.
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
@@ -166,15 +163,24 @@ jobs:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Start MariaDB for SlpModularCms.Api.Tests
run: |
docker run -d --name ci-mariadb \
# Runner-independent: docker or podman, a unique container name per run and a free host port chosen by the
# engine (`-p 127.0.0.1::3306`), so two runs on the same machine (or the PC's local dev database) never collide.
ENGINE=$(command -v docker || command -v podman)
NAME="ci-mariadb-${{ github.run_id }}-${{ github.run_attempt }}"
echo "CI_DB_ENGINE=$ENGINE" >> "$GITHUB_ENV"
echo "CI_DB_NAME=$NAME" >> "$GITHUB_ENV"
"$ENGINE" run -d --name "$NAME" \
-e MARIADB_ROOT_PASSWORD=ci_test_password \
-e MARIADB_DATABASE=SlpModularCms \
-p 3307:3306 \
-p 127.0.0.1::3306 \
mariadb:11
PORT=$("$ENGINE" port "$NAME" 3306/tcp | head -1 | sed 's/.*://')
echo "CI_DB_PORT=$PORT" >> "$GITHUB_ENV"
echo "MariaDB published on 127.0.0.1:$PORT"
for i in $(seq 1 30); do
# mariadb:11 does not provide a `mysqladmin` alias -- verified locally against this
# exact image; the correct binary here is `mariadb-admin`.
if docker exec ci-mariadb mariadb-admin ping -uroot -pci_test_password --silent 2>/dev/null; then
if "$ENGINE" exec "$NAME" mariadb-admin ping -uroot -pci_test_password --silent 2>/dev/null; then
echo "MariaDB is ready."
break
fi
@@ -182,16 +188,15 @@ jobs:
sleep 2
done
- name: Test (Release)
env:
# Overrides the placeholder in SlpModularCms.Api/appsettings.Development.json for this
# CI run only -- ASP.NET Core's configuration layering applies environment variables
# after appsettings.*.json, so this reaches SlpModularCms.Api.Tests' WebApplicationFactory
# without touching any committed appsettings file. Port 3307, not 3306 -- see above.
ConnectionStrings__DefaultConnection: "Server=127.0.0.1;Port=3307;Database=SlpModularCms;Uid=root;Pwd=ci_test_password"
run: dotnet test SlpModularCms.sln -c Release
# ConnectionStrings__DefaultConnection overrides the placeholder in appsettings.Development.json for this CI
# run only (environment variables are applied after appsettings.*.json), so it reaches
# SlpModularCms.Api.Tests' WebApplicationFactory without touching a committed appsettings file.
run: |
export ConnectionStrings__DefaultConnection="Server=127.0.0.1;Port=$CI_DB_PORT;Database=SlpModularCms;Uid=root;Pwd=ci_test_password"
dotnet test SlpModularCms.sln -c Release
- name: Stop MariaDB for SlpModularCms.Api.Tests
if: always()
run: docker rm -f ci-mariadb || true
run: '"${CI_DB_ENGINE:-docker}" rm -f "${CI_DB_NAME:-ci-mariadb}" || true'
# --- Gate 3: vulnerability scan ---
# `dotnet list package --vulnerable` always exits 0, even when it reports vulnerabilities, so the
@@ -200,11 +205,10 @@ jobs:
# Runner labels: a job runs on a runner that has ALL of its runs-on labels.
# Pi runner: linux-arm64, ubuntu-latest, global, linux, arm64, podman, raspberry-pi
# PC runner: global, linux, x64, podman, bryan-desktop
# `linux` = any free runner (PC or Pi): for everything that is plain build/test/lint work (config, changes,
# backend-build, vulnerability-scan, frontend-*). `raspberry-pi` = the Pi only: for jobs that need the Pi's
# environment -- publish-* (linux-arm64 artefact, uploaded for the Pi) and deploy-* (ssh/sftp to the host, sshpass,
# sudo apt-get; they failed on the PC) -- and backend-test (see there). If the PC is off or busy the Pi takes
# the `linux` jobs too.
# Every job uses `linux` so that any runner (PC, Pi, future ones) can pick it up; no job assumes the host
# architecture or a specific user: publish-* cross-publishes with an explicit `-r linux-arm64`, deploy-scp.yaml only
# installs missing tools and only uses sudo when needed, backend-test picks a free port for its database.
# Use `raspberry-pi` only for a job that demonstrably cannot run elsewhere, and say why in a comment.
vulnerability-scan:
needs: changes
if: needs.changes.outputs.backend == 'true'
@@ -371,7 +375,7 @@ jobs:
needs.frontend-lint.result != 'failure' && needs.frontend-lint.result != 'cancelled' &&
(needs.changes.outputs.backend == 'true' || needs.changes.outputs.frontend == 'true') &&
(github.event_name != 'workflow_dispatch' || github.event.inputs.deploy_test == 'true')
runs-on: raspberry-pi
runs-on: linux
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
@@ -446,7 +450,7 @@ jobs:
needs.frontend-lint.result != 'failure' && needs.frontend-lint.result != 'cancelled' &&
github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_production == 'true' &&
(needs.changes.outputs.backend == 'true' || needs.changes.outputs.frontend == 'true')
runs-on: raspberry-pi
runs-on: linux
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
@@ -583,7 +587,7 @@ jobs:
(needs.changes.outputs.backend == 'true' || needs.changes.outputs.frontend == 'true') &&
((github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_asf_test == 'true') ||
(github.event_name == 'push' && github.ref == 'refs/heads/master'))
runs-on: raspberry-pi
runs-on: linux
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
+11 -3
View File
@@ -40,8 +40,18 @@ on:
jobs:
deploy:
runs-on: raspberry-pi
runs-on: linux
steps:
# Runner-independent: only installs what is missing, and only uses sudo when not already root and sudo exists
# (a container on the PC runner has neither sudo nor a need for it; the Pi runner may need it).
- name: Ensure ssh tooling
run: |
SUDO=""
if [ "$(id -u)" != "0" ] && command -v sudo >/dev/null 2>&1; then SUDO="sudo"; fi
if ! command -v sshpass >/dev/null 2>&1 || ! command -v ssh >/dev/null 2>&1 || ! command -v scp >/dev/null 2>&1; then
$SUDO apt-get update && $SUDO apt-get install -y sshpass openssh-client
fi
- name: Compute release timestamp
id: release
run: echo "timestamp=$(date -u +%Y%m%d%H%M%S)" >> "$GITHUB_OUTPUT"
@@ -68,7 +78,6 @@ jobs:
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
run: |
echo "Environment: ${{ inputs.environment }}"
sudo apt-get update && sudo apt-get install -y sshpass
sshpass -p "$SSH_PASS" ssh \
-p "$SSH_PORT" \
-o StrictHostKeyChecking=no \
@@ -92,7 +101,6 @@ jobs:
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
run: |
echo "Environment: ${{ inputs.environment }}, transport: ${{ inputs.transport }}"
sudo apt-get update && sudo apt-get install -y sshpass
RELEASE_DIR="${{ inputs.deploy_path }}/releases/${{ steps.release.outputs.timestamp }}"
sshpass -p "$SSH_PASS" ssh \
-p "$SSH_PORT" \