Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
693 changes: 693 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Weekly, grouped: one PR for all NuGet updates, one for all GitHub Actions.
# Weekly, grouped: one PR for all NuGet updates, one for all GitHub Actions, one for the SDK.
# CI runs the tests on every PR, so a green check is what makes these safe to merge.
version: 2
updates:
Expand All @@ -20,8 +20,13 @@ updates:
update-types: ["version-update:semver-major"]
- dependency-name: "MySql.*"
update-types: ["version-update:semver-major"]
- dependency-name: "Pomelo.*"
update-types: ["version-update:semver-major"]
# The SDK pinned in global.json: one PR per new patch, which CI then builds with it.
- package-ecosystem: dotnet-sdk
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
# Actions run the NuGet release, so they get updated too.
- package-ecosystem: github-actions
directory: /
Expand Down
19 changes: 7 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ jobs:
steps:
- uses: actions/checkout@v7

# One SDK per target framework: each TFM builds and tests against its own EF Core major
# (8, 9, 10, 11), and the tests need that runtime to run. The newest SDK builds them all.
- uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
11.0.x
# The SDK global.json pins, plus the runtime of the older target framework.
global-json-file: global.json
dotnet-version: 10.0.x

- name: Restore
run: dotnet restore
Expand Down Expand Up @@ -68,13 +64,12 @@ jobs:
steps:
- uses: actions/checkout@v7

# The .NET 11 SDK too: restoring the library, which this project references, includes
# its net11.0 target, which the .NET 10 SDK can't build.
# The pinned SDK too: restoring the library, which this project references, includes its
# net11.0 target, which the .NET 10 SDK can't build.
- uses: actions/setup-dotnet@v5
with:
dotnet-version: |
10.0.x
11.0.x
global-json-file: global.json
dotnet-version: 10.0.x

- name: Integration tests
run: dotnet test --project tests/Hlibz.EntityFrameworkCore.ModelRules.IntegrationTests --configuration Release
21 changes: 11 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,29 @@ jobs:

- uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
11.0.x
# The SDK global.json pins, plus the runtime of the older target framework.
global-json-file: global.json
dotnet-version: 10.0.x

- name: Determine package version from tag
id: version
run: echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"

- name: Restore
run: dotnet restore

# Built once, at the tag's version: the tests run against these binaries, and Pack packs
# them as they are (--no-build) rather than rebuilding.
- name: Build
run: dotnet build --no-restore --configuration Release
run: dotnet build --no-restore --configuration Release -p:Version=${{ steps.version.outputs.value }}

- name: Test
run: dotnet test --project tests/Hlibz.EntityFrameworkCore.ModelRules.Tests --no-build --configuration Release

- name: Determine package version from tag
id: version
run: echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"

- name: Pack
run: >
dotnet pack src/Hlibz.EntityFrameworkCore.ModelRules
--no-build
--configuration Release
--output ./artifacts
-p:Version=${{ steps.version.outputs.value }}
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ nupkg/

# macOS
.DS_Store

# Claude Code local settings
.claude/

# Test results
TestResults/
62 changes: 37 additions & 25 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ builds the model (`UseModelRules` in `ConfigureConventions`) or from a test

## Requires

* .NET 11 SDK, plus the .NET 8, 9 and 10 runtimes to run every test target.
* The .NET SDK `global.json` pins (11.0.100, patches roll forward; Dependabot bumps it), plus
the .NET 10 runtime to run both test targets. Pinned because warnings are errors and
`AnalysisMode=All`: a new SDK feature band brings new analyzer rules.

## Commands

```bash
# Build everything
dotnet build

# Run all tests (all four target frameworks)
# Run all tests (both target frameworks)
dotnet test --project tests/Hlibz.EntityFrameworkCore.ModelRules.Tests

# One target framework only
Expand All @@ -43,16 +45,15 @@ Testcontainers 4.15 talks Docker API 1.44+. With an older local Docker Engine (e

## Architecture

- **Multi-targeting = one EF Core major per TFM.** `Directory.Build.props` sets
`net8.0;net9.0;net10.0;net11.0` for every project, and `Directory.Packages.props` pins
`Microsoft.EntityFrameworkCore.Relational` (and the test-only providers) per TFM: 8.0.x on
net8.0, 9.0.x on net9.0, 10.0.x on net10.0, 11.0.x on net11.0. On net11.0 the Npgsql and
Oracle MySQL providers are still prereleases (test-only, so that's fine); the test project
suppresses NU1608 because Npgsql's rc pins EF Core to its own rc. So each build of the
library is compiled and tested against its own EF major, and the package's dependency group
for each TFM pulls the matching EF. Use `#if NET10_0_OR_GREATER` for APIs that only exist in
newer EF majors (see `ModelWalker.IsJson` and the JSON complex-type container column in
`ModelIdentifiers`). From EF Core 11 `IReadOnlyIndex.Properties` is a list of
- **Multi-targeting = one EF Core major per TFM.** `Directory.Build.props` sets `net10.0;net11.0`
for every project, and `Directory.Packages.props` pins `Microsoft.EntityFrameworkCore.Relational`
(and the test-only providers) per TFM: 10.0.x on net10.0, 11.0.x on net11.0. On net11.0 the Npgsql
and Oracle MySQL providers are still prereleases (test-only, so that's fine); the test project
suppresses NU1608 because Npgsql's rc pins EF Core to its own rc. So each build of the library is
compiled and tested against its own EF major, and the package's dependency group for each TFM
pulls the matching EF. Use `#if NET11_0_OR_GREATER` for APIs that only exist in EF Core 11 (the EF
Core 11 tests in `NoRedundantIndexesTests` and `TableRulesTests` do). The 1.x line also built
net8.0/net9.0; 2.0.0 dropped them. From EF Core 11 `IReadOnlyIndex.Properties` is a list of
`IReadOnlyPropertyBase` (an index can hold a JSON complex property), so take index members as
`IEnumerable<IReadOnlyPropertyBase>`.
- **The Relational pin is the package's minimum EF Core version.** Its version becomes the
Expand Down Expand Up @@ -132,7 +133,7 @@ Testcontainers 4.15 talks Docker API 1.44+. With an older local Docker Engine (e
`Internal/ModelRuleSet`.
- `tests/` builds real models with no database: building a model never opens the connection.
Tests use Npgsql by default. `ProviderCompatibilityTests` builds the same models on every
`TestProvider` (Npgsql, SQL Server, SQLite, Oracle MySQL, and Pomelo on net8.0/net9.0 only)
`TestProvider` (Npgsql, SQL Server, SQLite and Oracle MySQL; Pomelo has no EF Core 10/11 build)
and asserts identical violations, so provider-specific behavior shows up there first. SQL
Server temporal period columns are an example: `NoShadowPropertiesRule` recognizes them
through SQL Server's annotation names, so the library never references a provider package.
Expand Down Expand Up @@ -184,17 +185,22 @@ Testcontainers 4.15 talks Docker API 1.44+. With an older local Docker Engine (e
Versions follow the policy in README's "Versioning" section: rule IDs are permanent, a rule may
report more in a minor or patch release, and new rules are opt-in.

`.github/workflows/release.yml` runs on a pushed `vX.Y.Z` tag (or `vX.Y.Z-preview.N`, which
publishes a prerelease). It builds and tests, packs
`src/Hlibz.EntityFrameworkCore.ModelRules` with `-p:Version` taken from the tag, and publishes
via NuGet Trusted Publishing (OIDC, no API key; see
1. Set `Version` in `Directory.Build.props`, commit, then push the tag `vX.Y.Z`.
2. The user approves the `release` environment run.
3. Once the run succeeds and
`https://api.nuget.org/v3-flatcontainer/hlibz.entityframeworkcore.modelrules/index.json`
lists the version, Claude creates the GitHub release that `PackageReleaseNotes` links to:
`gh release create vX.Y.Z --verify-tag --title X.Y.Z [--prerelease when the version has a suffix] --notes-file <notes>`.
Claude writes the notes from `git log <previous tag>..vX.Y.Z`: breaking changes first, then
features and fixes, then a nuget.org link. Nothing is attached.

`.github/workflows/release.yml` builds once at the tag's version (`-p:Version`), runs the unit
tests against those binaries, packs them with `--no-build`, and publishes via NuGet Trusted
Publishing (OIDC, no API key; see
https://learn.microsoft.com/nuget/nuget-org/trusted-publishing). The job uses the `release` GitHub
Environment, which must match the Environment on the nuget.org trusted-publishing policy. It also
needs a `${{ secrets.NUGET_USER }}` repo secret holding the nuget.org profile username (not the
email).

To publish, don't bump anything in the csproj (the tag drives the version). Just run
`git tag vX.Y.Z && git push origin vX.Y.Z`.
email). It doesn't create the GitHub release; step 3 does.

## Conventions

Expand All @@ -204,10 +210,16 @@ To publish, don't bump anything in the csproj (the tag drives the version). Just
without a `Version=` attribute.
- No `Microsoft.SourceLink.GitHub` package reference: the .NET SDK (8+) includes Source Link
itself, and the 8.0.0 package pulls a vulnerable `Microsoft.Build.Tasks.Git`.
- No StyleCop/SonarAnalyzer: this is a small single-purpose package, kept lightweight on purpose.
`TreatWarningsAsErrors` is still on, and `GenerateDocumentationFile` means every public member
needs an XML doc comment.
- StyleCop + Sonar + `AnalysisMode=All`, warnings as errors, `LangVersion` pinned to 14 (the
Hlibz family setup, in `Directory.Build.props` and `.editorconfig`). Every public member needs
an XML doc comment, and a documented internal one documents its parameters and return value
too. Tests and the sample relax a few rules in their own `.editorconfig` sections.
- Shared NuGet metadata and `Version` live in `Directory.Build.props`; the csproj sets only
`PackageId`, `Description` and `PackageTags`. `src/Directory.Build.props` packs the package's
own `src/Hlibz.EntityFrameworkCore.ModelRules/README.md` (what nuget.org shows: short,
absolute links only) and turns on package validation. The root `README.md` is the full
documentation; keep the two in step when an API changes.
- The package icon's source is `docs/icon.svg`. `docs/icon.png` (128x128) is packed as
`PackageIcon` and shown at the top of README through its `raw.githubusercontent.com` URL on
`PackageIcon` and shown at the top of both READMEs through its `raw.githubusercontent.com` URL on
`main`, because nuget.org renders neither relative image paths nor raw HTML. So a changed
icon shows in README only once it's pushed.
46 changes: 44 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
<Project>

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<TargetFrameworks>net10.0;net11.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<!--
One language version for every target framework, pinned rather than "latest" so the
build doesn't change with the installed SDK. C# 14 so the net10.0 target compiles from
the same source as net11.0.
-->
<LangVersion>14</LangVersion>
<AnalysisMode>All</AnalysisMode>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SonarAnalyzer.CSharp">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- NuGet metadata shared by every package; each csproj sets its own PackageId, Description and tags. -->
<PropertyGroup Label="NuGet metadata">
<Version>2.0.0</Version>
<Authors>Hlib Zinchenko</Authors>
<Copyright>Copyright (c) 2026 Hlib Zinchenko</Copyright>
<PackageReleaseNotes>https://github.com/hlib-zinchenko/Hlibz.EntityFrameworkCore.ModelRules/releases</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/hlib-zinchenko/Hlibz.EntityFrameworkCore.ModelRules</PackageProjectUrl>
<RepositoryUrl>https://github.com/hlib-zinchenko/Hlibz.EntityFrameworkCore.ModelRules</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>icon.png</PackageIcon>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<!-- Deterministic PDB paths in CI builds, so the published packages are reproducible. -->
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

</Project>
37 changes: 8 additions & 29 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.35.0.4138" />
<PackageVersion Include="SQLitePCLRaw.bundle_e_sqlite3" Version="3.0.5" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<PackageVersion Include="Testcontainers.MsSql" Version="4.16.0" />
<PackageVersion Include="Testcontainers.MySql" Version="4.16.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.16.0" />
Expand All @@ -23,37 +25,13 @@
One EF Core major per target framework: each TFM's build of the library is compiled (and
tested) against the EF Core major that ships for it, so the package's dependency group for
that TFM pulls the matching EF Core. The providers are test-only: tests build every model
on each of them (no database needed) to prove the rules are provider-neutral. Pomelo has no
EF Core 10 or 11 release yet, so it only covers net8.0/net9.0; Oracle's
MySql.EntityFrameworkCore covers MySQL on all four. Sqlite.Core plus an explicit
on each of them (no database needed) to prove the rules are provider-neutral. MySQL is
Oracle's MySql.EntityFrameworkCore: Pomelo has no EF Core 10 or 11 release yet (add it
back per target framework once it has). Sqlite.Core plus an explicit
SQLitePCLRaw bundle rather than the Sqlite package: the provider loads native SQLite even
just to build a model, and the bundle the Sqlite package pulls in (2.1.6-2.1.11) ships a
known-vulnerable SQLite.
-->
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.31" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.31" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.31" />
<PackageVersion Include="MySql.EntityFrameworkCore" Version="8.0.28" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.20" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.20" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="9.0.20" />
<PackageVersion Include="MySql.EntityFrameworkCore" Version="9.0.17" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
</ItemGroup>
<!--
Test-only, never packed: Pomelo (net8.0/net9.0 only) pulls in MySqlConnector 2.3.5/2.4.0,
which NuGet audit fails (GHSA-473q-m89c-ghf8; patched in 2.6.1). Drop it once Pomelo
depends on 2.6.1 or later.
-->
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0' Or '$(TargetFramework)' == 'net9.0'">
<PackageVersion Include="MySqlConnector" Version="2.6.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.12" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.3" />
Expand All @@ -63,8 +41,9 @@
<!--
Test-only, never packed: the SqlServer provider pulls in Pkcs 9.0.11 through
Microsoft.Data.SqlClient 6.1.x, which NuGet audit fails (GHSA-846f-f764-76mx,
GHSA-2fmv-rv2c-59x7; patched in 9.0.21). net10.0 only, since EF Core 8/9's SqlClient
doesn't depend on it. Drop it once the provider's SqlClient depends on 9.0.21 or later.
GHSA-2fmv-rv2c-59x7; patched in 9.0.21). net10.0 only: the EF Core 11 provider's
SqlClient doesn't pull it in. Drop it once the provider's SqlClient depends on 9.0.21
or later.
-->
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="10.0.14" />
</ItemGroup>
Expand Down
Loading
Loading