From e68aa5834c2d8a246b8ff948409d7977691d1293 Mon Sep 17 00:00:00 2001 From: Timothy Date: Wed, 8 Jul 2026 19:37:31 +0200 Subject: [PATCH] ci: speed up build pipeline (NuGet cache, shallow checkout, jar layer reorder) Three CI wins from ersatztv#190, all config-only: - Cache ~/.nuget/packages via actions/cache@v4 in both the `test` and `migrations` jobs, keyed on Directory.Packages.props + global.json, so dotnet restore no longer starts from scratch every run. - Shallow-checkout the `test` job (fetch-depth: 1) since it never runs git describe/log; only `build` needs full history for versioning. The `migrations` job's checkout was already effectively shallow (default fetch-depth 1), documented explicitly. - Reorder the Dockerfile so the openapi-generator jar wget happens before the openapi spec COPY, decoupling the ~30MB download layer from spec changes (e.g. v1.json) that previously busted it on every API PR. Documented all three in docs/ci-cd.md alongside the existing job/Dockerfile notes. Co-Authored-By: Claude Opus 4.8 (1M context) --- .gitea/workflows/docker-build.yml | 20 +++++++++++++++++++- docker/Dockerfile | 6 +++++- docs/ci-cd.md | 14 ++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index 65cb65f58..54f7a86e1 100644 --- a/.gitea/workflows/docker-build.yml +++ b/.gitea/workflows/docker-build.yml @@ -40,13 +40,22 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 0 + # only the test job's steps below need the working tree; git history/tags + # are only needed by the `build` job's `git describe` (ersatztv#190) + fetch-depth: 1 - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: '10.0.x' + - name: Cache NuGet packages + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: nuget-${{ runner.os }}-${{ hashFiles('Directory.Packages.props', 'global.json') }} + restore-keys: nuget-${{ runner.os }}- + - name: Restore run: dotnet restore @@ -112,12 +121,21 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + # default fetch-depth: 1 -- this job never runs git describe/log, only + # actions/checkout@v4's default (shallow) history is needed (ersatztv#190) - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: '10.0.x' + - name: Cache NuGet packages + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: nuget-${{ runner.os }}-${{ hashFiles('Directory.Packages.props', 'global.json') }} + restore-keys: nuget-${{ runner.os }}- + - name: Restore run: dotnet restore diff --git a/docker/Dockerfile b/docker/Dockerfile index f36236268..e3a989fb9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -24,9 +24,13 @@ FROM mcr.microsoft.com/dotnet/sdk:10.0-noble-amd64 AS build RUN apt-get update && apt-get install -y ca-certificates gnupg default-jre-headless python3-pip WORKDIR /source +# download the openapi-generator jar first so this layer is cached independently +# of the openapi spec dir below -- otherwise every spec change (e.g. v1.json) +# busts the layer and re-downloads the ~30MB jar (ersatztv#190) +RUN wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.15.0/openapi-generator-cli-7.15.0.jar + # generate openapi client COPY ErsatzTV/wwwroot/openapi/. /app/ErsatzTV/wwwroot/openapi/ -RUN wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.15.0/openapi-generator-cli-7.15.0.jar RUN java -jar openapi-generator-cli-7.15.0.jar generate -i /app/ErsatzTV/wwwroot/openapi/scripted-schedule.json -g python -o /app/etv-client --package-name etv_client RUN rm -rf openapi-generator-cli-7.15.0.jar /app/ErsatzTV RUN python3 -m pip install --target=/app/pythonlibs /app/etv-client diff --git a/docs/ci-cd.md b/docs/ci-cd.md index a5e115929..23df3b153 100644 --- a/docs/ci-cd.md +++ b/docs/ci-cd.md @@ -53,6 +53,14 @@ release flow in parallel (shared `:buildcache` tag, shared smoke container). Docker build) → `dotnet build -c Release` → `dotnet test -c Release --no-build`. Gates the image build. +- **Shallow checkout**: `fetch-depth: 1` (ersatztv#190) — this job never runs `git + describe`/`git log`, only `build` needs full history/tags for version computation, so + `test` and `migrations` both check out shallow. `build`'s checkout stays `fetch-depth: 0`. +- **NuGet package cache**: both `test` and `migrations` cache `~/.nuget/packages` via + `actions/cache@v4`, keyed on `hashFiles('Directory.Packages.props', 'global.json')` with + a `restore-keys` OS-level fallback (ersatztv#190). Avoids a from-scratch `dotnet restore` + on every run; the key only changes when the central package manifest or SDK pin changes. + ### `build` job 1. Compute `INFO_VERSION` (`git describe` + short sha on `main`; tag version on `v*`). @@ -85,6 +93,12 @@ the image build. here: under Central Package Management the csproj carry no inline versions, so the image's restore fails (`NU1015`) without the central manifest. - amd64-only (jazz is x86_64). No arm32/arm64, no DMG/exe artifacts, no GHCR/DockerHub. +- **openapi-generator jar layer ordering** (ersatztv#190): the `wget` for the + openapi-generator-cli jar runs *before* the `COPY` of `ErsatzTV/wwwroot/openapi/`, so the + ~30MB download layer is cached independently of the openapi spec. Previously the jar was + downloaded after that `COPY`, so any PR touching the spec (e.g. `v1.json`) busted the + download layer too and re-fetched the jar on every such change. Codegen itself still runs + after the spec `COPY`, since it needs both the jar and the spec files. ## Dependency management (Central Package Management + scans) -- 2.47.3