Skip to content

Commit 900dd18

Browse files
authored
Move to monthly releases and expand the NuGet readme (#34)
## Summary Moves the template from a release on every push to `main` to one release a month, and gives the NuGet page real instructions. - Pushes to `main` now build and test only. NuGet publishing and the GitHub release happen on the 1st of each month at 9am America/Chicago. - A new Release Check job compares `main` with the latest release tag and skips the release when nothing outside `.github/` has changed. - Running the Build Pipeline by hand still releases straight away. The new **force** input releases even when only `.github/` has changed. - Each release opens with a line saying it's the monthly release (or an out-of-cycle one), followed by the generated notes for everything merged since the previous release. - Dependabot moves to a cron on the 15th, so dependency updates can be merged before the next release. The scheduled build and Scorecard scan move from weekly to the 15th at 9am America/Chicago, so all the maintenance runs together and releases stay on the 1st. - `NUGET.md` now covers install, creating a solution and its options, running it, what's inside, updating and where to get help, with links back to GitHub. The README gets a Releases section. The Docker docs are unchanged. - PR builds use `pr-<number>` as the prerelease suffix instead of the branch names, which were long enough to trip NuGet's NU5123 path length check. - On pull requests the Code Coverage job now also requires 90% coverage of the changed lines, on top of the 95% overall gate. README, CONTRIBUTING and the PR template say so. Coverlet and `codecov.yml` now leave out generated code (`obj/`, `[GeneratedCode]`, migrations), so the Codecov report shows the same lines the gate checks. Codecov stays informational. ## Related issues None ## Type of change - [ ] Bug fix - [ ] New feature - [ ] Breaking change (the generated solution or template parameters change in a way existing users will notice) - [ ] Refactoring or clean-up - [x] Documentation - [x] Build, pipeline or dependency update ## Shared layers - [ ] This only touches the Presentation layer of this template. - [x] This touches the Application or Infrastructure layers, tests, pipeline or repository setup, so it needs to be carried across all five templates. ## Checklist - [ ] `dotnet build` and `dotnet test` pass locally with no warnings. - [ ] I added or updated tests, and coverage stays at or above 95%. - [x] I updated the README or docs where behaviour changed. - [ ] I checked the template still installs and creates a working solution (see CONTRIBUTING.md).
1 parent 9b2ff5d commit 900dd18

9 files changed

Lines changed: 179 additions & 24 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ version: 2
33
multi-ecosystem-groups:
44
monthly-dependencies:
55
schedule:
6-
interval: "monthly"
6+
interval: "cron"
7+
cronjob: "0 9 15 * *"
8+
timezone: "America/Chicago"
79

810
updates:
911
- package-ecosystem: "nuget"

‎.github/pull_request_template.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
## Checklist
2424

2525
- [ ] `dotnet build` and `dotnet test` pass locally with no warnings.
26-
- [ ] I added or updated tests, and coverage stays at or above 95%.
26+
- [ ] I added or updated tests, and coverage stays at or above 95% overall and 90% on changed lines.
2727
- [ ] I updated the README or docs where behaviour changed.
2828
- [ ] I checked the template still installs and creates a working solution (see CONTRIBUTING.md).

‎.github/workflows/build-pipeline.yml‎

Lines changed: 92 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ on:
66
pull_request:
77
branches: [main]
88
schedule:
9-
- cron: "0 3 * * 1"
9+
- cron: "0 9 15 * *"
10+
timezone: "America/Chicago"
11+
- cron: "0 9 1 * *"
12+
timezone: "America/Chicago"
1013
workflow_dispatch:
14+
inputs:
15+
force:
16+
description: Release even if only .github/ has changed since the last release
17+
type: boolean
18+
default: false
1119

1220
permissions:
1321
contents: read
@@ -39,11 +47,7 @@ jobs:
3947
VERSION_PREFIX=$(date +'%Y.%m.%d').${GITHUB_RUN_NUMBER}
4048
4149
if [[ ${GITHUB_EVENT_NAME} == 'pull_request' ]]; then
42-
BRANCH_BASE=${GITHUB_BASE_REF#refs/*/}
43-
BRANCH_BASE=${BRANCH_BASE/[^a-zA-Z0-9]//-}
44-
BRANCH_COMPARE=${GITHUB_HEAD_REF#refs/*/}
45-
BRANCH_COMPARE=${BRANCH_COMPARE//[^a-zA-Z0-9]/-}
46-
VERSION_SUFFIX="merge-${BRANCH_BASE}-${BRANCH_COMPARE}"
50+
VERSION_SUFFIX="pr-${PR_NUMBER}"
4751
fi
4852
4953
if [[ $VERSION_SUFFIX == '' ]]; then
@@ -56,6 +60,8 @@ jobs:
5660
echo "version_prefix=$(eval printf "%s" "$VERSION_PREFIX")" >> $GITHUB_OUTPUT
5761
echo "version_suffix=$(eval printf "%s" "$VERSION_SUFFIX")" >> $GITHUB_OUTPUT
5862
echo "version=$(eval printf "%s" "$VERSION")" >> $GITHUB_OUTPUT
63+
env:
64+
PR_NUMBER: ${{ github.event.pull_request.number }}
5965
shell: bash
6066

6167
- name: Test
@@ -160,6 +166,8 @@ jobs:
160166
- name: Checkout
161167
id: checkout
162168
uses: actions/checkout@v7
169+
with:
170+
fetch-depth: 0
163171

164172
- name: Download Coverage
165173
id: download
@@ -179,7 +187,7 @@ jobs:
179187
id: threshold
180188
run: |
181189
python3 - <<'PY'
182-
import os, sys, xml.etree.ElementTree as ET
190+
import os, re, subprocess, sys, xml.etree.ElementTree as ET
183191
from collections import defaultdict
184192
root = ET.parse("out/coverage.opencover.xml").getroot()
185193
lines = {}
@@ -205,10 +213,31 @@ jobs:
205213
coverage = 100 * hit / total if total else 0
206214
threshold = float(os.environ["THRESHOLD"])
207215
print(f"Line coverage {coverage:.2f}% ({hit}/{total}), threshold {threshold}%")
208-
sys.exit(0 if coverage >= threshold else 1)
216+
passed = coverage >= threshold
217+
base = os.environ.get("BASE_REF")
218+
if base:
219+
diff = subprocess.run(["git", "diff", "--unified=0", f"origin/{base}...HEAD"], capture_output=True, text=True, check=True).stdout
220+
changed, path = set(), None
221+
for line in diff.splitlines():
222+
if line.startswith("+++ "):
223+
path = line[6:] if line.startswith("+++ b/") else None
224+
elif line.startswith("@@") and path:
225+
start, count = re.match(r"@@ -\S+ \+(\d+)(?:,(\d+))? @@", line).groups()
226+
changed.update((path, n) for n in range(int(start), int(start) + int(count or 1)))
227+
patch = [hits for key, hits in lines.items() if key in changed]
228+
if patch:
229+
patch_coverage = 100 * sum(1 for hits in patch if hits > 0) / len(patch)
230+
patch_threshold = float(os.environ["PATCH_THRESHOLD"])
231+
print(f"Patch coverage {patch_coverage:.2f}% ({sum(1 for hits in patch if hits > 0)}/{len(patch)}), threshold {patch_threshold}%")
232+
passed = passed and patch_coverage >= patch_threshold
233+
else:
234+
print("Patch coverage: no coverable lines changed")
235+
sys.exit(0 if passed else 1)
209236
PY
210237
env:
211238
THRESHOLD: 95
239+
PATCH_THRESHOLD: 90
240+
BASE_REF: ${{ github.base_ref }}
212241

213242
scan:
214243
name: Container Scan
@@ -290,11 +319,54 @@ jobs:
290319
with:
291320
category: "/language:${{ matrix.language }}"
292321

322+
release:
323+
name: Release Check
324+
runs-on: ubuntu-latest
325+
if: ${{ github.repository == 'stphnwlsh/CleanGraphQLApi' && github.ref == 'refs/heads/main' && (github.event.schedule == '0 9 1 * *' || github.event_name == 'workflow_dispatch') }}
326+
permissions:
327+
contents: read
328+
329+
outputs:
330+
publish: ${{ steps.check.outputs.publish }}
331+
332+
steps:
333+
- name: Checkout
334+
id: checkout
335+
uses: actions/checkout@v7
336+
with:
337+
fetch-depth: 0
338+
339+
- name: Check Changes
340+
id: check
341+
run: |
342+
LATEST=$(gh release view --json tagName --jq .tagName 2>/dev/null || true)
343+
344+
if [[ -z "$LATEST" ]]; then
345+
echo "No previous release"
346+
PUBLISH=true
347+
elif [[ "$FORCE" == 'true' ]]; then
348+
echo "Forced release"
349+
PUBLISH=true
350+
elif git diff --quiet "$LATEST" HEAD -- . ':(exclude).github'; then
351+
echo "Nothing outside .github/ has changed since $LATEST, skipping the release"
352+
PUBLISH=false
353+
else
354+
echo "Changes since $LATEST:"
355+
git diff --stat "$LATEST" HEAD -- . ':(exclude).github'
356+
PUBLISH=true
357+
fi
358+
359+
echo "publish=$PUBLISH" >> $GITHUB_OUTPUT
360+
env:
361+
GH_TOKEN: ${{ github.token }}
362+
FORCE: ${{ inputs.force }}
363+
shell: bash
364+
293365
publish:
294366
name: Publish
295367
runs-on: ubuntu-latest
296-
needs: [build, coverage, scan, analysis]
297-
if: ${{ github.repository == 'stphnwlsh/CleanGraphQLApi' && github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }}
368+
needs: [build, coverage, scan, analysis, release]
369+
if: ${{ needs.release.outputs.publish == 'true' }}
298370
permissions:
299371
contents: write
300372
id-token: write
@@ -319,7 +391,16 @@ jobs:
319391

320392
- name: GitHub Release
321393
id: github-release
322-
run: gh release create "$VERSION" packages/*.nupkg --repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" --title "$VERSION" --generate-notes
394+
run: |
395+
if [[ "$EVENT" == 'schedule' ]]; then
396+
NOTES="Monthly release for $(date +'%B %Y'). The template is released on the 1st of each month with every change merged since the previous release."
397+
else
398+
NOTES="Out-of-cycle release. The template is normally released on the 1st of each month with every change merged since the previous release."
399+
fi
400+
401+
gh release create "$VERSION" packages/*.nupkg --repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" --title "$VERSION" --notes "$NOTES" --generate-notes
323402
env:
324403
GH_TOKEN: ${{ github.token }}
404+
EVENT: ${{ github.event_name }}
325405
VERSION: ${{ needs.build.outputs.version }}
406+
shell: bash

‎.github/workflows/scorecard.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ on:
55
push:
66
branches: [main]
77
schedule:
8-
- cron: "0 4 * * 1"
8+
- cron: "0 9 15 * *"
9+
timezone: "America/Chicago"
910
workflow_dispatch:
1011

1112
permissions: read-all

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ dotnet new uninstall ./
4949

5050
1. Create a branch from `main` named `feature/`, `fix/` or `chore/` followed by a short description, for example `fix/review-validation`.
5151
1. Keep the change focused. Unrelated refactors are easier to review as separate pull requests.
52-
1. Add or update tests. The pipeline fails if line coverage drops below 95%.
52+
1. Add or update tests. The pipeline fails if line coverage drops below 95%, or if less than 90% of the lines your pull request changes are covered.
5353
1. Follow the style in `.editorconfig` and `Directory.Build.props`. Warnings are treated as errors, so the build must be clean.
5454
1. Update the README or docs if behaviour changes.
5555

‎Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ RUN dotnet build --no-restore -c Release -v minimal -p:VersionPrefix=${VERSION_P
3535

3636
# Dotnet Test
3737
FROM build AS test
38-
RUN dotnet test --no-restore --no-build -c Release -v minimal -p:CollectCoverage=true -p:CoverletOutput=../results/ -p:MergeWith="../results/coverage.json" -p:CoverletOutputFormat=opencover%2cjson -m:1 -p:ExcludeByFile="**/Program.cs%2c**/Migrations/*.cs"
38+
RUN dotnet test --no-restore --no-build -c Release -v minimal -p:CollectCoverage=true -p:CoverletOutput=../results/ -p:MergeWith="../results/coverage.json" -p:CoverletOutputFormat=opencover%2cjson -m:1 -p:ExcludeByFile="**/Program.cs%2c**/Migrations/*.cs%2c**/obj/**/*.cs" -p:ExcludeByAttribute="GeneratedCodeAttribute"
3939

4040
FROM scratch AS coverage
4141
COPY --from=test /sln/tests/results/*.xml .

‎NUGET.md‎

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,76 @@
22

33
A `dotnet new` template for a GraphQL API built with a streamlined version of Clean Architecture and [Hot Chocolate](https://chillicream.com/docs/hotchocolate).
44

5-
It shares its Application and Infrastructure layers with four sibling templates for Minimal APIs, Web API controllers, GraphQL, Model Context Protocol and AWS Lambda.
5+
It's one of five templates, for Minimal APIs, Web API controllers, GraphQL, Model Context Protocol and AWS Lambda, that share the same Application and Infrastructure layers, tests and CI pipeline.
66

7-
## Installation
7+
## Requirements
8+
9+
- [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0)
10+
- [Docker](https://www.docker.com/products/docker-desktop) (optional, to build and run the container image)
11+
12+
## Install
813

914
``` bash
1015
dotnet new install CleanGraphQLApi.Template
1116
```
1217

13-
## Usage
18+
## Create a solution
1419

1520
``` bash
1621
dotnet new cleangraphqlapi --name {YOUR_SOLUTION_NAMESPACE} --authorName "{YOUR_NAME}"
1722
```
1823

19-
## Documentation
24+
| Option | Description |
25+
| --- | --- |
26+
| `--name` | The name of the solution, also used as the root namespace. |
27+
| `--authorName` | The name of the author of the solution. |
28+
| `--authority` | The OAuth authorization server that issues access tokens. Leave it empty to run the API without authentication. |
29+
| `--audience` | The audience access tokens must be issued for, usually the API's own URL. |
30+
31+
With an authority set, the movie, author and review queries and the review mutations need a JWT bearer token, and the `version` query, the schema and Nitro stay open.
32+
33+
## Run it
34+
35+
From the new solution's folder, start the app and a Seq container for logs.
36+
37+
``` bash
38+
docker compose up -d
39+
```
40+
41+
Then open Nitro, the GraphQL IDE, at <http://localhost:8080/graphql>. Seq shows the logs at <http://localhost:5341>.
42+
43+
Or run it without Docker.
44+
45+
``` bash
46+
dotnet run --project ./src/Presentation
47+
```
48+
49+
Run the tests with `dotnet test`. Every way to run the solution is in `docs/RUN.md` inside it.
50+
51+
## What's inside
52+
53+
- **Presentation**: A [Hot Chocolate](https://chillicream.com/docs/hotchocolate) GraphQL schema with Relay paging, DataLoaders and the [Nitro](https://chillicream.com/docs/nitro) IDE
54+
- **Application**: commands and queries through [Mediator](https://github.com/martinothamar/Mediator), validation with [FluentValidation](https://github.com/FluentValidation/FluentValidation) and mapping with [Mapperly](https://mapperly.riok.app)
55+
- **Infrastructure**: [Entity Framework Core](https://learn.microsoft.com/ef/core) on SQLite with migrations and optional sample data
56+
- **Tests**: [xUnit](https://xunit.net), [Shouldly](https://github.com/shouldly/shouldly) and [NSubstitute](https://github.com/nsubstitute/NSubstitute), each test on its own in-memory database
57+
- A Dockerfile that runs as a non-root user, a `docker-compose.yml`, and a GitHub Actions pipeline with tests, a coverage gate, a container scan and CodeQL
58+
59+
## Updates
60+
61+
A new version is released on the 1st of each month with every change merged since the previous release, as long as something has changed. To update an installed template:
62+
63+
``` bash
64+
dotnet new update
65+
```
66+
67+
What changed in each version is in the [release notes](https://github.com/stphnwlsh/CleanGraphQLApi/releases). To remove the template, run `dotnet new uninstall CleanGraphQLApi.Template`.
68+
69+
## More help
2070

21-
The [README on GitHub](https://github.com/stphnwlsh/CleanGraphQLApi#readme) covers the architecture, features and how to run the generated solution. Report bugs and ideas in [GitHub issues](https://github.com/stphnwlsh/CleanGraphQLApi/issues).
71+
- [README on GitHub](https://github.com/stphnwlsh/CleanGraphQLApi#readme) for the architecture, every feature and the Docker build options
72+
- [Running guide](https://github.com/stphnwlsh/CleanGraphQLApi/blob/main/docs/RUN.md) for every way to run, configure and test the solution
73+
- [GitHub issues](https://github.com/stphnwlsh/CleanGraphQLApi/issues) for bugs and ideas
74+
- [Security policy](https://github.com/stphnwlsh/CleanGraphQLApi/security/policy) to report a vulnerability privately
2275

2376
## Support
2477

‎README.md‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ It's one of five templates that share the same Application and Infrastructure la
1818
- [Running the project](#running-the-project)
1919
- [Architecture](#architecture)
2020
- [Features](#features)
21+
- [Releases](#releases)
2122
- [Related templates](#related-templates)
2223
- [Resources](#resources)
2324
- [Contributing](#contributing)
@@ -96,11 +97,23 @@ The one deliberate break from Clean Architecture is that the Presentation projec
9697
- Data stored in [SQLite](https://learn.microsoft.com/ef/core/providers/sqlite/) using [Entity Framework Core](https://learn.microsoft.com/ef/core) migrations, seeded with [Bogus](https://github.com/bchavez/Bogus) only when `Database:SeedSampleData` is on. Each test uses its own throwaway in-memory SQLite database, so tests never touch a real one or each other's data
9798
- Testing using [xUnit](https://xunit.net), [Shouldly](https://github.com/shouldly/shouldly) and [NSubstitute](https://github.com/nsubstitute/NSubstitute), with coverage from [Coverlet](https://github.com/coverlet-coverage/coverlet)
9899
- Build rules in `Directory.Build.props`: code style and the recommended analyzers are checked on every build, warnings fail it, and package versions live in one place with [Central Package Management](https://learn.microsoft.com/nuget/consume-packages/central-package-management)
99-
- CI with GitHub Actions: build and test, a `dotnet format` check, 95% coverage gate, [Trivy](https://trivy.dev) container scan, [CodeQL](https://codeql.github.com) static analysis, then NuGet publishing and a GitHub release from `main` using [trusted publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing)
100+
- CI with GitHub Actions: build and test, a `dotnet format` check, 95% coverage gate with at least 90% on the lines each pull request changes, [Trivy](https://trivy.dev) container scan, [CodeQL](https://codeql.github.com) static analysis, then a monthly NuGet release and GitHub release from `main` using [trusted publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing)
100101
- Health checks at `/health/live` and `/health/ready`, using [ASP.NET Core health checks](https://learn.microsoft.com/aspnet/core/host-and-deploy/health-checks)
101-
- Monthly grouped dependency updates using [Dependabot](https://docs.github.com/code-security/dependabot), including the pinned Seq image
102+
- Grouped dependency updates on the 15th of each month using [Dependabot](https://docs.github.com/code-security/dependabot), including the pinned Seq image
102103
- A Docker image that runs as a non-root user with a health check
103104

105+
## Releases
106+
107+
The template is released once a month. On the 1st, at 9am US Central time, the pipeline checks for changes since the last release. If anything outside `.github/` has changed, it builds and tests `main`, publishes the new version to [NuGet](https://www.nuget.org/packages/CleanGraphQLApi.Template) and creates a [GitHub release](https://github.com/stphnwlsh/CleanGraphQLApi/releases) with notes for every pull request merged since the previous one. If nothing has changed, there's no release that month. Dependency updates arrive on the 15th, so they're merged in time for the next release.
108+
109+
Versions keep the `YYYY.MM.DD.RUN` format. Up to the end of October 2026, every merge to `main` was released, so the older releases are much smaller. To release outside the monthly cycle, run the **Build Pipeline** workflow by hand. Tick **force** to release even when only `.github/` has changed.
110+
111+
To update an installed template to the latest release:
112+
113+
``` bash
114+
dotnet new update
115+
```
116+
104117
## Related templates
105118

106119
All five templates share the same Application and Infrastructure layers, tests, CI pipeline and repository setup.

‎codecov.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@ coverage:
66
informational: true
77
patch:
88
default:
9-
target: 95%
9+
target: 90%
1010
informational: true
11+
12+
ignore:
13+
- "**/Program.cs"
14+
- "**/Migrations/**"
15+
- "**/obj/**"

0 commit comments

Comments
 (0)