diff --git a/.gitea/workflows/continuous_integration.yaml b/.gitea/workflows/continuous_integration.yaml index 1337e54..def921b 100644 --- a/.gitea/workflows/continuous_integration.yaml +++ b/.gitea/workflows/continuous_integration.yaml @@ -134,6 +134,7 @@ jobs: - 'src/**' - 'tests/**' - '*.sln' + - '*.slnf' - '**/*.csproj' frontend: - *workflow @@ -149,8 +150,32 @@ jobs: - uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} + # The CI builds and tests the master CMS only (SlpModularCms.Api with every module, Core and all test + # projects), listed in SlpModularCms.Ci.slnf. The site projects (Api.SlpSoftware, Api.AndreaSlopFotografie, + # Api.Slave) are thin compositions: they are compiled by compile-sites below and built/published only when a + # deploy needs them. Their behaviour is covered by the tests on the master host (see SiteContractTests). - name: Restore and build (Release) - run: dotnet build SlpModularCms.sln -c Release + run: dotnet build SlpModularCms.Ci.slnf -c Release + + # --- Not required: the thin site projects still compile --- + # Compile only (no tests, a few seconds): catches a broken reference or a renamed type in a site project on the + # pull request instead of at deploy time. Deliberately not a required check; the smoke tests after the test + # deploys catch composition errors that compile fine. + compile-sites: + needs: changes + if: needs.changes.outputs.backend == 'true' + runs-on: linux + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + - name: Compile the site projects (Release) + run: | + for project in SlpSoftware AndreaSlopFotografie Slave; do + echo "== SlpModularCms.Api.$project" + dotnet build "src/SlpModularCms.Api.$project/SlpModularCms.Api.$project.csproj" -c Release + done # --- Gate 2: backend tests --- backend-test: @@ -199,7 +224,7 @@ jobs: sleep 2 done export ConnectionStrings__DefaultConnection="Server=$HOST;Port=3308;Database=SlpModularCms;Uid=root;Pwd=ci_test_password" - dotnet test SlpModularCms.sln -c Release + dotnet test SlpModularCms.Ci.slnf -c Release # --- Gate 3: vulnerability scan --- # `dotnet list package --vulnerable` always exits 0, even when it reports vulnerabilities, so the @@ -364,9 +389,9 @@ jobs: # gate's outcome is checked explicitly via needs..result instead: a skipped gate is fine, # but a gate that actually ran and failed or was cancelled still blocks the publish. The # changes.outputs check makes sure there's something to publish at all: a run that touched - # neither backend nor frontend has nothing new to deploy. The final line skips this build on a - # manual workflow_dispatch run that didn't check deploy_sls_test — building and uploading a test - # artifact nobody is going to deploy is wasted work; push/PR runs are unaffected. + # neither backend nor frontend has nothing new to deploy. The last two lines build this site only when a + # deploy will use it: never on a pull_request (the pull request builds and tests the master CMS only) and, on a + # manual workflow_dispatch run, only when deploy_sls_test is checked. if: | always() && needs.changes.result == 'success' && @@ -377,6 +402,7 @@ jobs: needs.frontend-test.result != 'failure' && needs.frontend-test.result != 'cancelled' && needs.frontend-lint.result != 'failure' && needs.frontend-lint.result != 'cancelled' && (needs.changes.outputs.backend == 'true' || needs.changes.outputs.frontend == 'true') && + github.event_name != 'pull_request' && (github.event_name != 'workflow_dispatch' || github.event.inputs.deploy_sls_test == 'true') runs-on: linux steps: @@ -654,3 +680,28 @@ jobs: service_name: ${{ vars.SERVICE_NAME_ASF_TEST }} health_check_url: ${{ vars.HEALTH_CHECK_URL_ASF_TEST }} run_db_backup: false + + # --- Smoke tests of the deployed compositions (anonymous requests, see scripts/smoke-site.sh) --- + # The CI tests the master CMS; this is the check that the composition of each site that was just deployed to test + # is the intended one (modules, website mode, noindex, protected admin routes). A failing smoke test fails the run. + smoke-sls-test: + needs: [deploy-sls-test] + if: always() && needs.deploy-sls-test.result == 'success' + runs-on: linux + steps: + - uses: actions/checkout@v4 + - name: Smoke test SLS test + env: + HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_TEST }} + run: bash scripts/smoke-site.sh "$HEALTH_URL" sls-test + + smoke-asf-test: + needs: [deploy-asf-test] + if: always() && needs.deploy-asf-test.result == 'success' + runs-on: linux + steps: + - uses: actions/checkout@v4 + - name: Smoke test ASF test + env: + HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_ASF_TEST }} + run: bash scripts/smoke-site.sh "$HEALTH_URL" asf-test diff --git a/SlpModularCms.Ci.slnf b/SlpModularCms.Ci.slnf new file mode 100644 index 0000000..a5045cf --- /dev/null +++ b/SlpModularCms.Ci.slnf @@ -0,0 +1,21 @@ +{ + "solution": { + "path": "SlpModularCms.sln", + "projects": [ + "src\\SlpModularCms.Api\\SlpModularCms.Api.csproj", + "src\\SlpModularCms.Core\\SlpModularCms.Core.csproj", + "src\\SlpModularCms.Core.Tests\\SlpModularCms.Core.Tests.csproj", + "src\\SlpModularCms.Modules.Availability\\SlpModularCms.Modules.Availability.csproj", + "src\\SlpModularCms.Modules.Availability.Tests\\SlpModularCms.Modules.Availability.Tests.csproj", + "src\\SlpModularCms.Modules.Identity\\SlpModularCms.Modules.Identity.csproj", + "src\\SlpModularCms.Modules.Identity.Tests\\SlpModularCms.Modules.Identity.Tests.csproj", + "src\\SlpModularCms.Modules.Master\\SlpModularCms.Modules.Master.csproj", + "src\\SlpModularCms.Modules.Master.Tests\\SlpModularCms.Modules.Master.Tests.csproj", + "src\\SlpModularCms.Api.Tests\\SlpModularCms.Api.Tests.csproj", + "src\\SlpModularCms.Modules.Offerings\\SlpModularCms.Modules.Offerings.csproj", + "src\\SlpModularCms.Modules.Offerings.Tests\\SlpModularCms.Modules.Offerings.Tests.csproj", + "src\\SlpModularCms.Modules.Contact\\SlpModularCms.Modules.Contact.csproj", + "src\\SlpModularCms.Modules.Contact.Tests\\SlpModularCms.Modules.Contact.Tests.csproj" + ] + } +} diff --git a/docs/deploy-en-testomgevingen.md b/docs/deploy-en-testomgevingen.md index d25e9f8..49caa9a 100644 --- a/docs/deploy-en-testomgevingen.md +++ b/docs/deploy-en-testomgevingen.md @@ -16,7 +16,7 @@ De werkelijke health-URL's komen uit de Gitea-variabelen `HEALTH_CHECK_URL_TEST` | Trigger | Wat er gebeurt | |---|---| -| `pull_request` (opened, synchronize, reopened) | De poorten (build, tests, kwetsbaarheidscontrole, frontend build/test/lint) en daarna `publish-sls-test`: bouwt een testartefact. Er wordt **niet** gedeployed. Een nieuwe push naar dezelfde PR annuleert de lopende run (alleen bij PR's). | +| `pull_request` (opened, synchronize, reopened) | De poorten voor het master-CMS (`SlpModularCms.Api` met alle modules, Core, alle testprojecten via `SlpModularCms.Ci.slnf`; kwetsbaarheidscontrole; frontend build/test/lint) en de niet-verplichte `compile-sites` (alleen compileren van de dunne site-projecten). Er wordt **niet** gepubliceerd of gedeployed: een site wordt pas gebouwd bij een deploy. Een nieuwe push naar dezelfde PR annuleert de lopende run. | | `push` op `master` | Dezelfde poorten, daarna automatisch `deploy-sls-test` (SlpSoftware test) en, als `ASF_TEST_DEPLOY_ENABLED` op `true` staat, ook `deploy-asf-test`. Nooit productie. | | `workflow_dispatch` (handmatig, op elke gekozen branch) | Alle poorten draaien altijd volledig (het pad-filter meldt dan backend en frontend als gewijzigd). Deployen gebeurt alleen voor de aangevinkte invoer, zie hieronder. | @@ -36,7 +36,9 @@ Zonder een van de drie aangevinkt draaien alleen de poorten (handig als losse CI Jobnamen volgen `{actie}-{site}-{omgeving}`: `config-sls`, `publish-sls-test`, `deploy-sls-test`, `publish-sls-production`, `deploy-sls-production` en voor Andrea `config-asf`, `publish-asf-test`, `deploy-asf-test`. Ook de invoeren van de handmatige run hebben de sitenaam: `deploy_sls_test`, `deploy_sls_production` en `deploy_asf_test` (vroeger `deploy_test` en `deploy_production`). De uitvoer van `config-sls` heet `artifact_name_sls_*`, `deploy_environment_sls_*`, `deploy_path_sls_*`, `service_name_sls_*` en `health_check_url_sls_*`, de artefacten `app-sls-test` en `app-sls-production` (ASF: `app-asf-test`). De Gitea-variabelen en -secrets (bijv. `DEPLOY_PATH_TEST`) zijn niet hernoemd. -Branch protection op `master` vereist de checks `Continuous Integration / backend-test (pull_request)`, `frontend-test (pull_request)` en een publish-check. **Die derde check heette vroeger `publish-test (pull_request)` en moet nu `publish-sls-test (pull_request)` heten** (Gitea: repository, Instellingen, Branches, beschermde branch `master`, vereiste statuschecks). Pas dat vlak voor de merge aan, met Bryans go; tot dan zou een merge wachten op een check die niet meer bestaat. +Wat de CI per site doet: bij een pull request bouwt en test de CI alleen het master-CMS (alle modules, `SlpModularCms.Ci.slnf`). De sites (`Api.SlpSoftware`, `Api.AndreaSlopFotografie`, `Api.Slave`) zijn dunne composities zonder eigen logica; hun samenstelling en standaardwaarden worden getest op de master-host (`SiteContractTests`, `AsfVariantPipelineTests`, `SiteVariantContactTests`), `compile-sites` controleert dat ze nog compileren (niet verplicht) en `publish-*` bouwt een site pas bij een deploy (push naar `master` of een aangevinkte invoer). Na elke test-deploy draait een rooktest (`scripts/smoke-site.sh`, jobs `smoke-sls-test` en `smoke-asf-test`: health, modulelijst in `/System/capabilities`, noindex, beschermde beheerroutes, 404 op een onbekend pad bij ASF); faalt die, dan faalt de run. + +Branch protection op `master`: verplicht zijn alleen `Continuous Integration / backend-test (pull_request)` en `frontend-test (pull_request)`. De eerdere verplichte check `publish-test (pull_request)` bestaat niet meer (er wordt bij een pull request niet meer gepubliceerd) en **moet vóór de merge uit de vereiste checks worden gehaald** (Gitea: repository, Instellingen, Branches, beschermde branch `master`, vereiste statuschecks), anders wacht de merge op een check die nooit meer draait. Pas dat vlak voor de merge aan, met Bryans go. ## Een branch naar test deployen diff --git a/scripts/smoke-site.sh b/scripts/smoke-site.sh new file mode 100644 index 0000000..ffb08c0 --- /dev/null +++ b/scripts/smoke-site.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# Smoke test of a deployed site: anonymous GET requests only, no secrets. +# +# Usage: scripts/smoke-site.sh +# any URL of the host, for example its /health URL; only scheme and host are used +# sls-test | asf-test +# +# A site project is a thin composition (modules + appsettings.json), so what can still go wrong at deploy time is +# the composition itself: a module missing, the wrong website mode, a missing setting. The CI builds and tests the +# master CMS only; this script is the check that the deployed composition of a site is the one that was intended. +# A failing check makes the CI run fail. +set -u + +base="$(printf '%s' "${1:?usage: smoke-site.sh }" | sed -E 's#^(https?://[^/]+).*#\1#')" +profile="${2:?profile (sls-test | asf-test) is required}" +failures=0 + +curl_get() { curl -sS --max-time 20 --retry 4 --retry-delay 3 --retry-all-errors "$@"; } +status_of() { curl_get -o /dev/null -w '%{http_code}' "$base$1"; } + +pass() { echo "ok $1"; } +fail() { echo "FAIL $1"; failures=$((failures + 1)); } + +expect_status() { # path expected description + local got; got="$(status_of "$1")" + if [ "$got" = "$2" ]; then pass "$3 ($1 -> $got)"; else fail "$3 ($1 -> $got, expected $2)"; fi +} + +expect_header() { # path header-name expected-substring description + local got; got="$(curl_get -D - -o /dev/null "$base$1" | tr -d '\r' | grep -i "^$2:" | head -1)" + if printf '%s' "$got" | grep -qi "$3"; then pass "$4 ($1 $2)"; else fail "$4 ($1 $2: '${got:-}')"; fi +} + +expect_body() { # path expected-substring description + if curl_get "$base$1" | grep -qF "$2"; then pass "$3 ($1)"; else fail "$3 ($1 does not contain '$2')"; fi +} + +echo "Smoke test '$profile' on $base" + +expect_status /health 200 "health" + +caps="$(curl_get "$base/api/v1/System/capabilities" || true)" +module_listed() { printf '%s' "$caps" | grep -q "\"$1\""; } +expect_module() { if module_listed "$1"; then pass "module $1 is loaded"; else fail "module $1 is NOT loaded (capabilities: ${caps:-})"; fi; } +expect_no_module() { if module_listed "$1"; then fail "module $1 is loaded but must not be"; else pass "module $1 is not loaded"; fi; } + +expect_status /api/v1/offerings 200 "public offerings" +# 204 = no active banner, 200 = there is one; both are a healthy answer. +banner="$(status_of '/api/v1/offerings/banner')" +if [ "$banner" = "200" ] || [ "$banner" = "204" ]; then pass "public banner (/api/v1/offerings/banner -> $banner)"; else fail "public banner (-> $banner, expected 200 or 204)"; fi +expect_status /api/v1/offerings/all 401 "the administrator list is protected" + +# A test host is never indexed. +expect_header / X-Robots-Tag noindex "noindex on the website" +expect_body /robots.txt "Disallow: /" "robots.txt disallows everything" + +case "$profile" in + sls-test) + for m in Identity Availability Offerings Contact Master; do expect_module "$m"; done + expect_status /sitemap.xml 404 "no sitemap on a test host" + ;; + asf-test) + for m in Identity Availability Offerings Contact; do expect_module "$m"; done + expect_no_module Master + # Prerendered website: an unknown path is a real 404 (an SPA would answer 200). + expect_status /smoke-test-path-that-does-not-exist 404 "unknown website path is a 404" + ;; + *) + echo "Unknown profile '$profile' (use sls-test or asf-test)" + exit 2 + ;; +esac + +if [ "$failures" -gt 0 ]; then + echo "Smoke test FAILED: $failures check(s)." + exit 1 +fi +echo "Smoke test passed."