name: Continuous Integration on: workflow_dispatch: inputs: deploy_sls_test: description: 'Deploy SLS test (SlpSoftware)' type: boolean default: false deploy_sls_production: description: 'Deploy SLS production (SlpSoftware)' type: boolean default: false deploy_asf_test: description: 'Deploy ASF test (Andrea Slop Fotografie)' type: boolean default: false pull_request: types: [opened, synchronize, reopened] push: branches: [master] # A new push to the same PR does not cancel an already-running CI attempt by default (each # `synchronize` event starts an independent run) — this opts in to cancelling the superseded one, # but ONLY for pull_request events. `deploy-sls-test`/`deploy-sls-production` never run on a pull_request # (they require a push to master or a workflow_dispatch, see those jobs' `if:` conditions), so # scoping cancel-in-progress to pull_request here can never abort a live deploy mid-flight. concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} # Reusable settings for this workflow. Change these in one place if the .NET/Node/pnpm version, # artifact names, or deploy destinations change. The env context is NOT available inside a called # reusable workflow's `with:` inputs (see the `config-sls` job below, which works around this by passing # these values through as job outputs to the `deploy-sls-test` / `deploy-sls-production` jobs). env: DOTNET_VERSION: '10.0.x' NODE_VERSION: '20' PNPM_VERSION: '9' PUBLISH_RID: linux-arm64 ARTIFACT_NAME_SLS_TEST: app-sls-test ARTIFACT_NAME_SLS_PRODUCTION: app-sls-production DEPLOY_ENVIRONMENT_SLS_TEST: test DEPLOY_ENVIRONMENT_SLS_PRODUCTION: production DEPLOY_PATH_TEST: ${{ vars.DEPLOY_PATH_TEST }} DEPLOY_PATH_PRODUCTION: ${{ vars.DEPLOY_PATH_PRODUCTION }} SERVICE_NAME_TEST: ${{ vars.SERVICE_NAME_TEST }} SERVICE_NAME_PRODUCTION: ${{ vars.SERVICE_NAME_PRODUCTION }} HEALTH_CHECK_URL_TEST: ${{ vars.HEALTH_CHECK_URL_TEST }} HEALTH_CHECK_URL_PRODUCTION: ${{ vars.HEALTH_CHECK_URL_PRODUCTION }} jobs: # Passes the env: values above through as job outputs, since the env context is unavailable in # the `with:` block of a job that calls a reusable workflow (see deploy-sls-test / deploy-sls-production). config-sls: runs-on: linux outputs: artifact_name_sls_test: ${{ steps.set.outputs.artifact_name_sls_test }} artifact_name_sls_production: ${{ steps.set.outputs.artifact_name_sls_production }} deploy_environment_sls_test: ${{ steps.set.outputs.deploy_environment_sls_test }} deploy_environment_sls_production: ${{ steps.set.outputs.deploy_environment_sls_production }} deploy_path_sls_test: ${{ steps.set.outputs.deploy_path_sls_test }} deploy_path_sls_production: ${{ steps.set.outputs.deploy_path_sls_production }} service_name_sls_test: ${{ steps.set.outputs.service_name_sls_test }} service_name_sls_production: ${{ steps.set.outputs.service_name_sls_production }} health_check_url_sls_test: ${{ steps.set.outputs.health_check_url_sls_test }} health_check_url_sls_production: ${{ steps.set.outputs.health_check_url_sls_production }} steps: # Gitea has no reliable way to see a past run's workflow_dispatch input values from the UI, so # this logs them explicitly — the only durable record of what was actually checked for a run. - name: Log dispatch inputs if: github.event_name == 'workflow_dispatch' run: | echo "Deploy SLS test: ${{ github.event.inputs.deploy_sls_test }}" echo "Deploy SLS production: ${{ github.event.inputs.deploy_sls_production }}" # The Gitea variables are read at STEP level (like config-asf), not through the workflow-level env block: on the PC # runner the workflow-level `${{ vars.* }}` values came through empty (deploy path "" -> mkdir /releases), while # step-level env works on both runners. The test trio must be set, otherwise fail here instead of in the deploy. - id: set env: DEPLOY_PATH_TEST: ${{ vars.DEPLOY_PATH_TEST }} DEPLOY_PATH_PRODUCTION: ${{ vars.DEPLOY_PATH_PRODUCTION }} SERVICE_NAME_TEST: ${{ vars.SERVICE_NAME_TEST }} SERVICE_NAME_PRODUCTION: ${{ vars.SERVICE_NAME_PRODUCTION }} HEALTH_CHECK_URL_TEST: ${{ vars.HEALTH_CHECK_URL_TEST }} HEALTH_CHECK_URL_PRODUCTION: ${{ vars.HEALTH_CHECK_URL_PRODUCTION }} run: | for v in DEPLOY_PATH_TEST SERVICE_NAME_TEST HEALTH_CHECK_URL_TEST; do if [ -z "${!v}" ]; then echo "The Gitea variable $v is empty or not set on this runner; the deploy would use an empty path." exit 1 fi done echo "artifact_name_sls_test=${{ env.ARTIFACT_NAME_SLS_TEST }}" >> "$GITHUB_OUTPUT" echo "artifact_name_sls_production=${{ env.ARTIFACT_NAME_SLS_PRODUCTION }}" >> "$GITHUB_OUTPUT" echo "deploy_environment_sls_test=${{ env.DEPLOY_ENVIRONMENT_SLS_TEST }}" >> "$GITHUB_OUTPUT" echo "deploy_environment_sls_production=${{ env.DEPLOY_ENVIRONMENT_SLS_PRODUCTION }}" >> "$GITHUB_OUTPUT" echo "deploy_path_sls_test=$DEPLOY_PATH_TEST" >> "$GITHUB_OUTPUT" echo "deploy_path_sls_production=$DEPLOY_PATH_PRODUCTION" >> "$GITHUB_OUTPUT" echo "service_name_sls_test=$SERVICE_NAME_TEST" >> "$GITHUB_OUTPUT" echo "service_name_sls_production=$SERVICE_NAME_PRODUCTION" >> "$GITHUB_OUTPUT" echo "health_check_url_sls_test=$HEALTH_CHECK_URL_TEST" >> "$GITHUB_OUTPUT" echo "health_check_url_sls_production=$HEALTH_CHECK_URL_PRODUCTION" >> "$GITHUB_OUTPUT" # Path-based skip: keeps the pipeline short when a change only touches one side of the repo. # fetch-depth: 0 gives paths-filter full local git history to diff against, rather than relying # on its GitHub-API fallback for missing history, which targets GitHub's REST API and cannot be # assumed to work against a Gitea remote. Changes under the workflow files themselves count as # both backend and frontend, so a workflow edit is never left partially untested. A manual # workflow_dispatch run has no `before` commit to diff against and is always an explicit request # to run everything, so it force-reports both sides as changed rather than trusting the filter. changes: runs-on: linux outputs: backend: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.backend == 'true' }} frontend: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.frontend == 'true' }} steps: # Skipped on workflow_dispatch: there's no `before` commit to diff against, and a manual run # always force-reports both sides changed anyway (see the outputs above), so the diff would be # wasted work. - uses: actions/checkout@v4 if: github.event_name != 'workflow_dispatch' with: fetch-depth: 0 - uses: dorny/paths-filter@v3 if: github.event_name != 'workflow_dispatch' id: filter with: filters: | workflow: &workflow - '.gitea/workflows/**' backend: - *workflow - 'src/**' - 'tests/**' - '*.sln' - '*.slnf' - '**/*.csproj' frontend: - *workflow - 'frontend/**' # --- Gate 1: backend build --- backend-build: 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 }} # 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.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: needs: [changes, backend-build] if: needs.changes.outputs.backend == 'true' 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 # other test project here, which mocks/uses EF Core InMemory and never touches a real # database. Without a real, reachable MariaDB, those tests fail on the connection itself # before any assertion runs. # # The database is a job-level `services:` container, so the job needs no container-engine socket (the PC # runner has no /var/run/docker.sock in its job containers; a manual `docker run` failed there). The server # listens on 3308 (MYSQL_TCP_PORT) instead of 3306: on the Pi runner job and service containers share the # host's network namespace (host networking), where the host's own database already answers on 3306 -- the # reason the first `services:` attempt there failed. On a runner with a separate job network the service is # reached by its name `mariadb`; with host networking it is reached on 127.0.0.1 (resolved in the test step). services: mariadb: image: mariadb:11 env: MARIADB_ROOT_PASSWORD: ci_test_password MARIADB_DATABASE: SlpModularCms MYSQL_TCP_PORT: '3308' options: >- --health-cmd="mariadb-admin ping -uroot -pci_test_password --silent" --health-interval=3s --health-timeout=3s --health-retries=40 steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Test (Release) shell: bash # 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: | HOST=127.0.0.1 if getent hosts mariadb >/dev/null 2>&1; then HOST=mariadb; fi echo "Waiting for MariaDB on $HOST:3308" for i in $(seq 1 60); do if (echo > "/dev/tcp/$HOST/3308") 2>/dev/null; then echo "MariaDB is accepting connections."; break; fi sleep 2 done export ConnectionStrings__DefaultConnection="Server=$HOST;Port=3308;Database=SlpModularCms;Uid=root;Pwd=ci_test_password" 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 # step greps its own output and fails deliberately (FR-22, D-12, OPEN-03 — closed by pinning # Microsoft.OpenApi and System.Security.Cryptography.Xml in the relevant .csproj files). # 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 # 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 uses a services: container (no engine socket needed). # 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' runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Check for vulnerable packages run: | OUTPUT=$(dotnet list SlpModularCms.sln package --vulnerable --include-transitive 2>&1) echo "$OUTPUT" if echo "$OUTPUT" | grep -q "has the following vulnerable packages"; then echo "Vulnerable packages detected — see above." exit 1 fi frontend-prepare: needs: changes if: needs.changes.outputs.frontend == 'true' runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} - uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - name: Get pnpm store directory id: pnpm-store working-directory: frontend run: echo "path=$(pnpm store path)" >> "$GITHUB_OUTPUT" - name: Cache pnpm store uses: actions/cache@v4 with: path: ${{ steps.pnpm-store.outputs.path }} key: pnpm-${{ hashFiles('frontend/pnpm-lock.yaml') }} - name: Install dependencies working-directory: frontend run: pnpm install --frozen-lockfile # --- Gate 4: frontend build --- # Validates the frontend compiles on its own, independent of any environment. The actual # per-environment deployable artifact is produced later by each publish job's own "Build admin # frontend" step (publish-sls-test / publish-sls-production, below), which builds frontend/ again with # that environment's Vite variables set and copies the result into wwwroot/admin before # `dotnet publish` runs — see that step's comment for why this isn't an MSBuild target instead. frontend-build: needs: [changes, frontend-prepare] if: needs.changes.outputs.frontend == 'true' runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} - uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - name: Get pnpm store directory id: pnpm-store working-directory: frontend run: echo "path=$(pnpm store path)" >> "$GITHUB_OUTPUT" - name: Restore pnpm store uses: actions/cache@v4 with: path: ${{ steps.pnpm-store.outputs.path }} key: pnpm-${{ hashFiles('frontend/pnpm-lock.yaml') }} - name: Install dependencies working-directory: frontend run: pnpm install --frozen-lockfile - name: Build working-directory: frontend run: pnpm run build # --- Gate 5: frontend tests --- frontend-test: needs: [changes, frontend-prepare] if: needs.changes.outputs.frontend == 'true' runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} - uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - name: Get pnpm store directory id: pnpm-store working-directory: frontend run: echo "path=$(pnpm store path)" >> "$GITHUB_OUTPUT" - name: Restore pnpm store uses: actions/cache@v4 with: path: ${{ steps.pnpm-store.outputs.path }} key: pnpm-${{ hashFiles('frontend/pnpm-lock.yaml') }} - name: Install dependencies working-directory: frontend run: pnpm install --frozen-lockfile - name: Unit tests working-directory: frontend run: pnpm run test # --- Gate 6: frontend lint / format-check --- frontend-lint: needs: [changes, frontend-prepare] if: needs.changes.outputs.frontend == 'true' runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} - uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - name: Get pnpm store directory id: pnpm-store working-directory: frontend run: echo "path=$(pnpm store path)" >> "$GITHUB_OUTPUT" - name: Restore pnpm store uses: actions/cache@v4 with: path: ${{ steps.pnpm-store.outputs.path }} key: pnpm-${{ hashFiles('frontend/pnpm-lock.yaml') }} - name: Install dependencies working-directory: frontend run: pnpm install --frozen-lockfile - name: Lint working-directory: frontend run: pnpm run lint # Publishes the Api project for the test environment. The admin SPA is built by this job's own # "Build admin frontend" step below, ahead of `dotnet publish` — see that step's comment for why. # # REF-U5-01: the Umami-origin drift check this gate performs exists because U3's own startup check # (BR-U3-22) can't work — the backend can never see VITE_UMAMI_WEBSITE_ID at runtime. It compares # two CI-time values instead: the frontend's Umami script origin, and a Gitea variable that MUST be # kept in sync with the host's real SecurityHeaders__AllowedScriptOrigins__0 env var (D-16). This # gate cannot see the actual runtime CSP configuration; it only catches drift between the frontend # build and what this variable claims the CSP allows. publish-sls-test: needs: [changes, backend-build, backend-test, vulnerability-scan, frontend-build, frontend-test, frontend-lint] # always() bypasses the automatic skip-cascade from a gate job that was itself skipped (because # its side of the repo didn't change). Gitea Actions only implements always() from the GitHub # Actions status-check functions — success()/failure()/cancelled() are not supported — so each # 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 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' && needs.backend-build.result != 'failure' && needs.backend-build.result != 'cancelled' && needs.backend-test.result != 'failure' && needs.backend-test.result != 'cancelled' && needs.vulnerability-scan.result != 'failure' && needs.vulnerability-scan.result != 'cancelled' && needs.frontend-build.result != 'failure' && needs.frontend-build.result != 'cancelled' && 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: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} - uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} - uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - name: Verify Umami origin is permitted (REF-U5-01) if: ${{ vars.VITE_UMAMI_SCRIPT_URL != '' }} run: | ORIGIN=$(echo "${{ vars.VITE_UMAMI_SCRIPT_URL }}" | sed -E 's#^(https?://[^/]+).*#\1#') if ! echo ",${{ vars.SECURITY_ALLOWED_SCRIPT_ORIGINS_TEST }}," | grep -qF ",$ORIGIN,"; then echo "Umami origin '$ORIGIN' is not present in the SECURITY_ALLOWED_SCRIPT_ORIGINS_TEST Gitea variable." echo "Fix the variable, or the test environment's SecurityHeaders CSP config it must mirror (D-16)." exit 1 fi # Builds the admin SPA and lands it in wwwroot/admin *before* dotnet publish runs, as its own # step rather than an MSBuild target hooked to Build/Publish. That was tried and reliably # failed two different ways (see SlpModularCms.Api.csproj's comment on the topic): the SDK's # wwwroot static-web-asset item set is fixed at project evaluation time, before any target # runs, so files a target creates afterward never make it into the publish output; and forcing # them in as an explicit Content item collided with the SDK's own static-web-asset resolution. # Physically existing on disk before dotnet publish/build ever runs is the only thing that # worked, verified locally against a clean obj/bin and a fresh node_modules. - name: Build admin frontend working-directory: frontend env: VITE_APP_ENV: test VITE_APP_TITLE: SLP Software VITE_THEME: slpsoftware VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }} VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID_TEST }} VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN }} run: | pnpm install --frozen-lockfile pnpm build mkdir -p ../src/SlpModularCms.Api.SlpSoftware/wwwroot/admin cp -r dist/. ../src/SlpModularCms.Api.SlpSoftware/wwwroot/admin/ - name: Publish (test) working-directory: src/SlpModularCms.Api.SlpSoftware run: > dotnet publish -c Release -r ${{ env.PUBLISH_RID }} --self-contained false -o ${{ github.workspace }}/${{ env.ARTIFACT_NAME_SLS_TEST }} - name: Upload publish artifact uses: actions/upload-artifact@v3 with: name: ${{ env.ARTIFACT_NAME_SLS_TEST }} path: ${{ env.ARTIFACT_NAME_SLS_TEST }} retention-days: 1 # Same as publish-sls-test, but only for a manual workflow_dispatch run with deploy_sls_production set — # a distinct job rather than a parameterized reuse of publish-sls-test, because VITE_APP_ENV is a # Vite build-time value: one dist/ bundle cannot be tagged as both 'test' and 'production' (FR-05). publish-sls-production: needs: [changes, backend-build, backend-test, vulnerability-scan, frontend-build, frontend-test, frontend-lint] # See publish-sls-test's comment above on why this checks needs..result explicitly instead of # failure()/cancelled(), which Gitea Actions doesn't support. if: | always() && needs.changes.result == 'success' && needs.backend-build.result != 'failure' && needs.backend-build.result != 'cancelled' && needs.backend-test.result != 'failure' && needs.backend-test.result != 'cancelled' && needs.vulnerability-scan.result != 'failure' && needs.vulnerability-scan.result != 'cancelled' && needs.frontend-build.result != 'failure' && needs.frontend-build.result != 'cancelled' && needs.frontend-test.result != 'failure' && needs.frontend-test.result != 'cancelled' && needs.frontend-lint.result != 'failure' && needs.frontend-lint.result != 'cancelled' && github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_sls_production == 'true' && startsWith(github.ref, 'refs/heads/release/') && (needs.changes.outputs.backend == 'true' || needs.changes.outputs.frontend == 'true') runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} - uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} - uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - name: Verify Umami origin is permitted (REF-U5-01) if: ${{ vars.VITE_UMAMI_SCRIPT_URL != '' }} run: | ORIGIN=$(echo "${{ vars.VITE_UMAMI_SCRIPT_URL }}" | sed -E 's#^(https?://[^/]+).*#\1#') if ! echo ",${{ vars.SECURITY_ALLOWED_SCRIPT_ORIGINS_PRODUCTION }}," | grep -qF ",$ORIGIN,"; then echo "Umami origin '$ORIGIN' is not present in the SECURITY_ALLOWED_SCRIPT_ORIGINS_PRODUCTION Gitea variable." echo "Fix the variable, or the production environment's SecurityHeaders CSP config it must mirror (D-16)." exit 1 fi # See publish-sls-test's "Build admin frontend" step for why this runs as its own step ahead of # dotnet publish rather than an MSBuild target. - name: Build admin frontend working-directory: frontend env: VITE_APP_ENV: production VITE_APP_TITLE: SLP Software VITE_THEME: slpsoftware VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }} VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID_PRODUCTION }} VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN }} run: | pnpm install --frozen-lockfile pnpm build mkdir -p ../src/SlpModularCms.Api.SlpSoftware/wwwroot/admin cp -r dist/. ../src/SlpModularCms.Api.SlpSoftware/wwwroot/admin/ - name: Publish (production) working-directory: src/SlpModularCms.Api.SlpSoftware run: > dotnet publish -c Release -r ${{ env.PUBLISH_RID }} --self-contained false -o ${{ github.workspace }}/${{ env.ARTIFACT_NAME_SLS_PRODUCTION }} - name: Upload publish artifact uses: actions/upload-artifact@v3 with: name: ${{ env.ARTIFACT_NAME_SLS_PRODUCTION }} path: ${{ env.ARTIFACT_NAME_SLS_PRODUCTION }} retention-days: 1 # Automatic test deploy on every push to master (unchanged — a merge should reach test without # extra steps). A manual workflow_dispatch run only deploys to test when deploy_sls_test is checked, # since a dispatch run is often just re-running CI/production, not a new test build (FR-03, D-01, # D-09). # deploy_path / service_name / health_check_url come straight from the Gitea variables, NOT from the `config-sls` job # outputs: a job output whose value contains a secret value (here most likely the deploy account name inside the # path) is dropped by the runner, so the reusable workflow received an empty deploy_path ("/releases"). The # `config-sls` outputs are still used for the artifact and environment names. deploy-sls-test: needs: [publish-sls-test, config-sls] if: (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_sls_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master') uses: ./.gitea/workflows/deploy-scp.yaml secrets: inherit with: artifact_name: ${{ needs.config-sls.outputs.artifact_name_sls_test }} environment: ${{ needs.config-sls.outputs.deploy_environment_sls_test }} deploy_path: ${{ vars.DEPLOY_PATH_TEST }} service_name: ${{ vars.SERVICE_NAME_TEST }} health_check_url: ${{ vars.HEALTH_CHECK_URL_TEST }} run_db_backup: false # Production deploy ONLY on an explicit workflow_dispatch run with deploy_sls_production checked, and # only when that run is on a release/* branch (same rule as ASF) — never reachable from a plain push # to master, so pushing cannot deploy production under any circumstance, and a dispatch from master # or a feature branch does nothing for production. deploy-sls-production: needs: [publish-sls-production, config-sls] if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_sls_production == 'true' && startsWith(github.ref, 'refs/heads/release/') uses: ./.gitea/workflows/deploy-scp.yaml secrets: inherit with: artifact_name: ${{ needs.config-sls.outputs.artifact_name_sls_production }} environment: ${{ needs.config-sls.outputs.deploy_environment_sls_production }} deploy_path: ${{ vars.DEPLOY_PATH_PRODUCTION }} service_name: ${{ vars.SERVICE_NAME_PRODUCTION }} health_check_url: ${{ vars.HEALTH_CHECK_URL_PRODUCTION }} run_db_backup: true # ========================================================================================== # Andrea Slop Fotografie (ASF) test host. Deliberately SEPARATE jobs: nothing above (the # SlpSoftware jobs, the env block, deploy-scp.yaml) is changed, a failure here never blocks the # SlpSoftware deploy and vice versa. # # Everything below is switched on by ONE Gitea variable, ASF_TEST_DEPLOY_ENABLED == 'true'. # While it is unset (or anything else) all three jobs are skipped and the pipeline behaves # exactly as before. Secrets cannot be tested in an `if:`, hence an explicit variable; it is set # only after the Pi and the other ASF_* variables exist. # Runs: on every push to master (like the SlpSoftware test deploy) or manually with the # "Deploy ASF test" box ticked. Test only: there is no production path for ASF. # ========================================================================================== config-asf: if: ${{ vars.ASF_TEST_DEPLOY_ENABLED == 'true' }} runs-on: linux outputs: deploy_path: ${{ steps.set.outputs.deploy_path }} service_name: ${{ steps.set.outputs.service_name }} health_check_url: ${{ steps.set.outputs.health_check_url }} steps: - id: set env: DEPLOY_PATH: ${{ vars.DEPLOY_PATH_ASF_TEST }} SERVICE_NAME: ${{ vars.SERVICE_NAME_ASF_TEST }} HEALTH_CHECK_URL: ${{ vars.HEALTH_CHECK_URL_ASF_TEST }} run: | for v in DEPLOY_PATH SERVICE_NAME HEALTH_CHECK_URL; do if [ -z "${!v}" ]; then echo "The Gitea variable for $v (…_ASF_TEST) is not set; set it or switch ASF_TEST_DEPLOY_ENABLED off." exit 1 fi done echo "deploy_path=$DEPLOY_PATH" >> "$GITHUB_OUTPUT" echo "service_name=$SERVICE_NAME" >> "$GITHUB_OUTPUT" echo "health_check_url=$HEALTH_CHECK_URL" >> "$GITHUB_OUTPUT" publish-asf-test: needs: [changes, backend-build, backend-test, vulnerability-scan, frontend-build, frontend-test, frontend-lint] # Same gate handling as publish-sls-test (see there for why always() and explicit results), plus the # ASF switch, and built only when it will actually be deployed. if: | always() && vars.ASF_TEST_DEPLOY_ENABLED == 'true' && needs.changes.result == 'success' && needs.backend-build.result != 'failure' && needs.backend-build.result != 'cancelled' && needs.backend-test.result != 'failure' && needs.backend-test.result != 'cancelled' && needs.vulnerability-scan.result != 'failure' && needs.vulnerability-scan.result != 'cancelled' && needs.frontend-build.result != 'failure' && needs.frontend-build.result != 'cancelled' && 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 == 'workflow_dispatch' && github.event.inputs.deploy_asf_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master')) runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} - uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} - uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} # Admin SPA with the ASF theme and Dutch as the default language. Lands in wwwroot/admin # BEFORE dotnet publish, for the same reason as in publish-sls-test. No Umami for the admin. - name: Build admin frontend (ASF theme) working-directory: frontend env: VITE_APP_ENV: test VITE_APP_TITLE: Andrea Slop Fotografie VITE_THEME: asf VITE_DEFAULT_LANGUAGE: nl VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN_ASF }} run: | pnpm install --frozen-lockfile pnpm build mkdir -p ../src/SlpModularCms.Api.AndreaSlopFotografie/wwwroot/admin cp -r dist/. ../src/SlpModularCms.Api.AndreaSlopFotografie/wwwroot/admin/ - name: Publish (ASF test) working-directory: src/SlpModularCms.Api.AndreaSlopFotografie run: > dotnet publish -c Release -r ${{ env.PUBLISH_RID }} --self-contained false -o ${{ github.workspace }}/app-asf-test - name: Upload publish artifact uses: actions/upload-artifact@v3 with: name: app-asf-test path: app-asf-test retention-days: 1 # Path/service/health straight from the Gitea variables, like deploy-sls-test (a job output containing a secret value, # here the deploy account name in the path, arrives empty). config-asf still validates that they are set. deploy-asf-test: needs: [publish-asf-test, config-asf] if: vars.ASF_TEST_DEPLOY_ENABLED == 'true' && ((github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_asf_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master')) uses: ./.gitea/workflows/deploy-scp.yaml secrets: inherit with: artifact_name: app-asf-test environment: test deploy_path: ${{ vars.DEPLOY_PATH_ASF_TEST }} 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