diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index bbaa6ae..98c8f47 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -1,8 +1,7 @@ -# Thin caller — pipelines live in infra/ci-workflows@v1. -# Pin @v1 (never a branch). Path filter + changes job stay local (repo-specific). -# -# Prerequisite: infra/ci-workflows Settings → Actions → collaborative owners -# must list this repo's owner. +# Thin caller. Pipelines are local reusable workflows until Trent is listed under +# infra/ci-workflows Actions → collaborative owners; then switch uses: back to +# infra/ci-workflows/.gitea/workflows/{dotnet8,node}-ci.yml@v1. +# Path filter + changes job stay local (repo-specific). name: CI on: @@ -72,7 +71,7 @@ jobs: backend: needs: changes if: needs.changes.outputs.backend == 'true' - uses: infra/ci-workflows/.gitea/workflows/dotnet8-ci.yml@v1 + uses: ./.gitea/workflows/dotnet8-ci.yml with: working_directory: . solution: VigilCareRecords.sln @@ -89,7 +88,7 @@ jobs: frontend: needs: changes if: needs.changes.outputs.frontend == 'true' - uses: infra/ci-workflows/.gitea/workflows/node-ci.yml@v1 + uses: ./.gitea/workflows/node-ci.yml with: working_directory: vigilcare-records-web node_version: "22" diff --git a/.gitea/workflows/dotnet8-ci.yml b/.gitea/workflows/dotnet8-ci.yml new file mode 100644 index 0000000..191eec6 --- /dev/null +++ b/.gitea/workflows/dotnet8-ci.yml @@ -0,0 +1,179 @@ +# Reusable .NET 8 CI pipeline (vendored from docs/CICD / infra/ci-workflows). +# Prefer uses: infra/ci-workflows/.gitea/workflows/dotnet8-ci.yml@v1 once this +# repo's owner is listed under that repo's Actions collaborative owners. +# +# Every constraint below is measured against the shared runner: +# * service containers are reached BY NAME — never publish 5432/6379 +# * host is 2 vCPU / 8 GB shared with Gitea — cap every dotnet test +# * artifact actions are @v4 +# * builtin:checkout needs no Node runtime and no github.com round-trip +name: dotnet8-ci + +on: + workflow_call: + inputs: + runs_on: + description: "Runner label. One label only — multi-label runs-on is unreliable." + type: string + default: ubuntu-latest + working_directory: + description: "Directory holding the solution, relative to the repo root." + type: string + default: "." + solution: + description: "Solution file, relative to working_directory." + type: string + required: true + dotnet_version: + type: string + default: "8.0.x" + cache_dependency_path: + description: "Glob for setup-dotnet's NuGet cache key." + type: string + default: "**/*.csproj" + postgres_image: + type: string + default: "postgres:16" + postgres_db: + type: string + default: "app_test" + redis_image: + type: string + default: "redis:7" + pre_build_command: + description: "Optional shell run at the REPO ROOT before restore (schema checks, codegen)." + type: string + default: "" + isolated_test_projects: + description: | + Test projects that must NOT see the service database — typically unit tests on an + in-memory provider. Run first, with ConnectionStrings__* blanked. One .csproj path per line. + type: string + default: "" + test_projects: + description: "Test projects that DO use the service containers. One .csproj path per line." + type: string + required: true + test_env: + description: "Optional extra KEY=VALUE lines exported for every test step." + type: string + default: "" + blame_hang_timeout: + description: "Kill testhost if a test stops completing." + type: string + default: "2m" + +jobs: + build-and-test: + runs-on: ${{ inputs.runs_on }} + defaults: + run: + working-directory: ${{ inputs.working_directory }} + services: + postgres: + image: ${{ inputs.postgres_image }} + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: ${{ inputs.postgres_db }} + options: >- + --shm-size=256mb + --health-cmd "pg_isready -U postgres -d ${{ inputs.postgres_db }}" + --health-interval 2s + --health-timeout 5s + --health-retries 30 + --health-start-period=20s + redis: + image: ${{ inputs.redis_image }} + options: >- + --health-cmd "redis-cli ping" + --health-interval 5s + --health-timeout 3s + --health-retries 10 + env: + ASPNETCORE_ENVIRONMENT: Testing + ConnectionStrings__Postgres: "Host=postgres;Port=5432;Database=${{ inputs.postgres_db }};Username=postgres;Password=postgres;SSL Mode=Disable" + ConnectionStrings__Redis: "redis:6379" + # GITEA_TOKEN is injected into every job and job containers CAN reach this + # Gitea. Blank it so product code cannot make live API calls from CI. + GITEA_TOKEN: "" + steps: + - uses: builtin:checkout + + - name: Pre-build checks + if: inputs.pre_build_command != '' + working-directory: . + run: ${{ inputs.pre_build_command }} + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ inputs.dotnet_version }} + cache: true + cache-dependency-path: ${{ inputs.working_directory }}/${{ inputs.cache_dependency_path }} + + - name: Restore + run: dotnet restore ${{ inputs.solution }} + + - name: Build + run: dotnet build ${{ inputs.solution }} -c Release --no-restore + + - name: Test (isolated — no service database) + if: inputs.isolated_test_projects != '' + env: + ConnectionStrings__Postgres: "" + ConnectionStrings__Redis: "" + DOTNET_PROCESSOR_COUNT: "1" + DOTNET_gcServer: "0" + DOTNET_GCHeapCount: "1" + run: | + set -euo pipefail + while IFS= read -r line; do + [ -n "$line" ] || continue + export "${line?}" + done <<< "${{ inputs.test_env }}" + + while IFS= read -r proj; do + [ -n "$proj" ] || continue + name="$(basename "$proj" .csproj)" + echo "::group::$name" + dotnet test "$proj" -c Release --no-build \ + --filter "Category!=Live" \ + --blame-hang-timeout ${{ inputs.blame_hang_timeout }} \ + --logger "trx;LogFileName=${name}.trx" \ + --results-directory ./TestResults \ + -- xUnit.MaxParallelThreads=1 + echo "::endgroup::" + done <<< "${{ inputs.isolated_test_projects }}" + + - name: Test (against the service containers) + env: + DOTNET_PROCESSOR_COUNT: "1" + DOTNET_gcServer: "0" + DOTNET_GCHeapCount: "1" + run: | + set -euo pipefail + while IFS= read -r line; do + [ -n "$line" ] || continue + export "${line?}" + done <<< "${{ inputs.test_env }}" + + while IFS= read -r proj; do + [ -n "$proj" ] || continue + name="$(basename "$proj" .csproj)" + echo "::group::$name" + dotnet test "$proj" -c Release --no-build \ + --filter "Category!=Live" \ + --blame-hang-timeout ${{ inputs.blame_hang_timeout }} \ + --logger "trx;LogFileName=${name}.trx" \ + --results-directory ./TestResults \ + -- xUnit.MaxParallelThreads=1 + echo "::endgroup::" + done <<< "${{ inputs.test_projects }}" + + - name: Publish test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results + path: ${{ inputs.working_directory }}/TestResults diff --git a/.gitea/workflows/node-ci.yml b/.gitea/workflows/node-ci.yml new file mode 100644 index 0000000..bef90ad --- /dev/null +++ b/.gitea/workflows/node-ci.yml @@ -0,0 +1,111 @@ +# Reusable Node CI pipeline (vendored from docs/CICD / infra/ci-workflows). +# Prefer uses: infra/ci-workflows/.gitea/workflows/node-ci.yml@v1 once this +# repo's owner is listed under that repo's Actions collaborative owners. +# +# Phase order (do not reorder in callers): +# 1. lint_command — lint + typecheck (no dist) +# 2. extra_check_command — audit, unit tests, source checks (no dist) +# 3. build_command — production build only (produces dist) +# 4. post_build_command — bundle budget, e2e, anything that needs dist +name: node-ci + +on: + workflow_call: + inputs: + runs_on: + type: string + default: ubuntu-latest + working_directory: + description: "Directory holding package.json, relative to the repo root." + type: string + required: true + node_version: + type: string + default: "22" + package_manager: + description: "npm | pnpm" + type: string + default: npm + lock_file: + type: string + default: package-lock.json + lint_command: + type: string + default: "npm run lint" + extra_check_command: + description: "Optional checks between lint and build. Must NOT require dist/." + type: string + default: "" + build_command: + description: "Build only. Typechecking belongs in lint_command, not here." + type: string + default: "npx vite build" + build_env: + description: "Optional KEY=VALUE lines exported for Build and Post-build." + type: string + default: "" + post_build_command: + description: "Optional checks after build that may use dist/ (bundle budget, e2e)." + type: string + default: "" + artifact_path: + description: "Optional build output to upload. Empty uploads nothing." + type: string + default: "" + +jobs: + build: + runs-on: ${{ inputs.runs_on }} + defaults: + run: + working-directory: ${{ inputs.working_directory }} + steps: + - uses: builtin:checkout + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node_version }} + cache: ${{ inputs.package_manager }} + cache-dependency-path: ${{ inputs.working_directory }}/${{ inputs.lock_file }} + + - name: Install + run: | + if [ "${{ inputs.package_manager }}" = "pnpm" ]; then + corepack enable && pnpm install --frozen-lockfile + else + npm ci + fi + + - name: Lint (and typecheck) + run: ${{ inputs.lint_command }} + + - name: Extra check + if: inputs.extra_check_command != '' + run: ${{ inputs.extra_check_command }} + + - name: Build + run: | + set -euo pipefail + while IFS= read -r line; do + [ -n "$line" ] || continue + export "${line?}" + done <<< "${{ inputs.build_env }}" + ${{ inputs.build_command }} + + - name: Post-build check + if: inputs.post_build_command != '' + run: | + set -euo pipefail + while IFS= read -r line; do + [ -n "$line" ] || continue + export "${line?}" + done <<< "${{ inputs.build_env }}" + ${{ inputs.post_build_command }} + + - name: Upload build output + if: inputs.artifact_path != '' + uses: actions/upload-artifact@v4 + with: + name: build-output + path: ${{ inputs.working_directory }}/${{ inputs.artifact_path }} diff --git a/docs/26-vigilcare-records-cicd.md b/docs/26-vigilcare-records-cicd.md index 2df7033..57c2652 100644 --- a/docs/26-vigilcare-records-cicd.md +++ b/docs/26-vigilcare-records-cicd.md @@ -31,13 +31,17 @@ Unlike VigilCareClinical, there is no gateway service, and the frontend does not ## 2. CI -CI is a **thin caller** of shared reusable workflows in `infra/ci-workflows@v1`. -Steps are not copied into this repo. +CI is a **thin caller** of local reusable workflows +(`.gitea/workflows/dotnet8-ci.yml`, `.gitea/workflows/node-ci.yml`). Those files +are vendored from the shared `infra/ci-workflows` kit because this repo’s owner +is not yet listed under that repo’s Actions **collaborative owners** — remote +`uses: infra/ci-workflows/...@v1` fails in 0s with no runner/steps. Switch the +caller back to `@v1` once access is granted. | Job | Workflow | | --- | --- | -| `backend` | `dotnet8-ci.yml@v1` — Postgres/Redis as `services:`, reached by DNS (`Host=postgres`, `redis:6379`) | -| `frontend` | `node-ci.yml@v1` — typecheck → unit tests → `vite build` | +| `backend` | `dotnet8-ci.yml` — Postgres/Redis as `services:`, reached by DNS (`Host=postgres`, `redis:6379`) | +| `frontend` | `node-ci.yml` — typecheck → unit tests → `vite build` | A local `changes` job path-filters so a frontend-only push does not start Postgres. `workflow_dispatch` forces both stacks. @@ -47,9 +51,6 @@ the caller maps those in `test_env` to the service containers. MinIO is not star in CI (tests do not drive object storage). Local deps still come from `docker compose up -d postgres redis minio`. -**Prerequisite:** `infra/ci-workflows` Settings → Actions → collaborative owners -must include this repo’s owner. - --- ## 3. Shared production infrastructure