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
3 changes: 3 additions & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
self-hosted-runner:
labels:
- windows-11-arm
paths:
.github/workflows/*.yaml:
# actionlint 1.7.7's job-context schema predates job.workflow_sha (documented in the GitHub Actions contexts reference)
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,28 @@ jobs:

- name: Run python tests
run: python3 -m unittest discover -s test -p '*_test.py'

test-net10-guard:
name: test net10.0 package guard (${{ matrix.os }})
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest, windows-11-arm]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: '10.0.x'

- name: Test net10.0 package guard
run: bash test/guard-net10-package-majors_test.sh
21 changes: 20 additions & 1 deletion .github/workflows/csharp-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ on:
required: false
type: string
default: ''
net10-package-exceptions:
description: >-
Comma or whitespace separated `package@major` pairs (for example
`Microsoft.Extensions.Options@11`) that the net10.0 package guard
accepts. After restore, the guard fails every `build-and-test` shard
when a packable project's net10.0 target (a RID-specific
`net10.0/<rid>` target included) resolves a `Microsoft.Extensions.*`
or `Microsoft.AspNetCore.*` package at major 11 or higher, directly
or transitively. The package id match is case-insensitive and the
major must match exactly. Empty accepts nothing.
required: false
type: string
default: ''
artifact-prefix:
description: >-
Prefix applied to per-run artifact names (coverage-percent,
Expand Down Expand Up @@ -287,7 +300,6 @@ jobs:
global-json-file: ${{ inputs.dotnet-version == '' && ((inputs.working-directory == '.' || inputs.working-directory == '') && 'global.json' || format('{0}/global.json', inputs.working-directory)) || '' }}

- name: Checkout CI helpers
if: ${{ matrix.coverage }}
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: peacefulstudio/github-actions
Expand Down Expand Up @@ -316,6 +328,13 @@ jobs:
set -euo pipefail
dotnet restore

- name: Guard net10.0 package majors
env:
NET10_PACKAGE_EXCEPTIONS: ${{ inputs.net10-package-exceptions }}
run: |
set -euo pipefail
"$GITHUB_WORKSPACE/.github-actions-helpers/scripts/guard-net10-package-majors.sh"
Comment thread
monsieurleberre marked this conversation as resolved.
Resolved

- name: Build
run: |
set -euo pipefail
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- `csharp-ci.yaml` fails every `build-and-test` shard, in a new `Guard net10.0 package majors` step between `Restore` and `Build`, when a packable project's `net10.0` target resolves a `Microsoft.Extensions.*` or `Microsoft.AspNetCore.*` package at major 11 or later, direct or transitive. A library that ships a `net10.0` asset would otherwise force its consumers onto the 11.x line, and CI stayed green because `net10.0` builds and tests fine with 11.x packages. The step reads the resolved graph from each project's `obj/project.assets.json`, `net10.0/<rid>` targets included, so a minor or patch bump of any package that pulls in 11.x is caught, not only a bump of a named package. It checks only projects that MSBuild evaluates as packable in the `Release` configuration (the one `Build` and `Pack` use, `IsPackable` in any letter case) with a `net10.0` target framework (`TargetFrameworks` may use spaces, newlines or any letter case): test projects, non-packable apps and `net11.0`-only projects are untouched, and the `net11.0` target of a multi-targeted library is not read. One `::error::` annotation per project names the project, each package, its resolved version and the top-level package that pulled it in. A packable `net10.0` project with no restore assets (one outside the restored solution) gets a warning and is skipped. A passing step prints `net10.0 package guard: checked N packable project(s)` so a green run shows how many projects it covered. The scan covers the descendants of `working-directory`. New optional input `net10-package-exceptions` (default empty) takes comma or whitespace separated `package@major` pairs to accept; it reaches the step only through the environment and a malformed entry fails the step before anything is checked. The check is on by default with no caller change, so a caller whose `net10.0` target resolves 11.x goes red until it pins the package to 10.x or lists an exception. The step needs `jq`, which the GitHub-hosted images and the self-hosted Hetzner runners provide, and it strips the carriage returns `jq` and `dotnet` print under Git Bash on Windows so that a Windows shard checks the same projects as a Linux one. The helper checkout (`Checkout CI helpers`) now runs on every shard, not only the coverage shard. `scripts/guard-net10-package-majors.sh` carries the logic, and `test/guard-net10-package-majors_test.sh` runs it against fixture projects on Linux, macOS, Windows and Windows ARM in `build-and-test.yaml`.

## [2.8.1] - 2026-11-06

### Fixed
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ choosing which shard carries coverage — use `build-matrix` instead (see
| `coverage-pr-comment-header` | `csharp-coverage` | Sticky-comment header (make unique per workspace if a repo calls this workflow more than once). |
| `pack` | `false` | When true, also runs `dotnet pack` and uploads `.nupkg` artifacts. |
| `pack-project` | *(empty)* | Project to pack. Required when `pack: true`. |
| `net10-package-exceptions` | *(empty)* | Comma or whitespace separated `package@major` pairs (e.g. `Microsoft.Extensions.Options@11`) the net10.0 package guard accepts. See the net10.0 package guard note below. |

**net10.0 package guard**: after restore, a `Guard net10.0 package majors` step
fails the build when a packable project with a `net10.0` target framework
resolves any `Microsoft.Extensions.*` or `Microsoft.AspNetCore.*` package at
major 11 or later, directly or transitively (it reads `obj/project.assets.json`,
including `net10.0/<rid>` targets). A `net10.0` package that requires the 11.x
line would otherwise pull its consumers off 10.x while CI stays green. The error
names the project, the package, its version and the top-level package that
brought it in. Accept a known case with
`net10-package-exceptions: 'Microsoft.Extensions.Options@11'`. Test projects,
non-packable projects and `net11.0`-only projects are not checked. The step
needs `jq` on the runner.

**Restore is credential-free**: `dotnet restore` and `dotnet pack` run with no
token and resolve every package from nuget.org. The private GitHub Packages feed
Expand Down
59 changes: 59 additions & 0 deletions scripts/guard-net10-package-majors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
# Copyright (c) 2026 Peaceful Studio OÜ
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail

here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

for tool in jq dotnet; do
if ! command -v "$tool" > /dev/null; then
echo "::error::the net10.0 package guard needs '$tool' on the runner PATH"
exit 3
fi
done

# jq.exe and dotnet.exe print CRLF line endings under Git Bash on Windows (jq 1.7.1, windows-latest), which leaves a trailing \r on every captured value
strip_cr() { tr -d '\r'; }
jq_clean() { jq "$@" | strip_cr; }

filter="$(strip_cr < "$here/net10-package-majors.jq")"

entries="$(printf '%s' "${NET10_PACKAGE_EXCEPTIONS:-}" | tr ',[:space:]' '\n' | sed '/^$/d')"
malformed="$(grep -Ev '^[A-Za-z0-9][A-Za-z0-9._-]*@[1-9][0-9]*$' <<< "$entries" || true)"
if [ -n "$malformed" ]; then
echo "::error::net10-package-exceptions entries must look like package@major, got: $(paste -sd ' ' - <<< "$malformed")"
exit 2
fi
allowed="$(printf '%s\n' "$entries" | jq_clean -R -s 'split("\n") | map(select(length > 0) | ascii_downcase)')"

failed=0
checked=0
while IFS= read -r project; do
[ -n "$project" ] || continue
display="${project#./}"
properties="$(dotnet msbuild "$project" -nologo -property:Configuration=Release -getProperty:IsPackable -getProperty:TargetFramework -getProperty:TargetFrameworks -getProperty:ProjectAssetsFile -getProperty:MSBuildProjectExtensionsPath | strip_cr)"
packable="$(jq_clean -r '.Properties.IsPackable | ascii_downcase' <<< "$properties")"
frameworks=";$(jq_clean -r '.Properties.TargetFrameworks + ";" + .Properties.TargetFramework' <<< "$properties" | tr -d '[:space:]');"
assets="$(jq_clean -r '.Properties.ProjectAssetsFile' <<< "$properties")"
if [ -z "$assets" ]; then
assets="$(jq_clean -r '.Properties.MSBuildProjectExtensionsPath' <<< "$properties")project.assets.json"
fi
if [ "$packable" != "true" ] || ! grep -Eqi ';net10\.0(-[^;]*)?;' <<< "$frameworks"; then
Comment thread
monsieurleberre marked this conversation as resolved.
Resolved
continue
fi
if command -v cygpath > /dev/null; then
assets="$(cygpath -u "$assets")"
fi
if [ ! -f "$assets" ]; then
echo "::warning::$display is packable for net10.0 but has no restore assets at $assets, so its package versions were not checked"
continue
fi
checked=$((checked + 1))
findings="$(jq_clean -r --argjson allowed "$allowed" "$filter" < "$assets" | sort -u | paste -sd ';' - | sed 's/;/; /g')"
if [ -n "$findings" ]; then
echo "::error::$display resolves $findings for its net10.0 target. A net10.0 package must not require Microsoft.Extensions or Microsoft.AspNetCore 11 or later; pin it to 10.x, or accept it with the net10-package-exceptions input."
failed=1
fi
done < <(find . \( -name obj -o -name bin -o -name node_modules -o -name .git -o -name .github-actions-helpers \) -prune -o \( -name '*.csproj' -o -name '*.fsproj' -o -name '*.vbproj' \) -print | sort)
Comment thread
monsieurleberre marked this conversation as resolved.
Resolved
echo "net10.0 package guard: checked $checked packable project(s)"
exit "$failed"
41 changes: 41 additions & 0 deletions scripts/net10-package-majors.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2026 Peaceful Studio OÜ
# SPDX-License-Identifier: Apache-2.0

def package_name: split("/")[0];
def package_version: split("/")[1];
def watched: test("^(microsoft\\.extensions|microsoft\\.aspnetcore)\\."; "i");
def major: package_version | split(".")[0] | tonumber;
def first_direct($reverse; $direct; $start):
def walk($frontier; $seen):
if ($frontier | length) == 0 then null
else
([$frontier[] | select(. as $n | $direct | index($n | ascii_downcase))]) as $hits
| if ($hits | length) > 0 then $hits[0]
else
([$frontier[] | ($reverse[ascii_downcase] // [])[]] | unique - $seen) as $next
| walk($next; $seen + $next)
end
end;
walk([$start]; [$start]);
. as $assets
| ($assets.targets // {}) | to_entries[]
| select(.key | test("^net10\\.0(-[^/]+)?(/.*)?$"; "i"))
| .key as $target
| .value as $libraries
| ([($assets.projectFileDependencyGroups[$target | split("/")[0]] // [])[] | split(" ")[0] | ascii_downcase]) as $direct
| (reduce ($libraries | to_entries[]) as $library ({};
reduce (($library.value.dependencies // {}) | keys[]) as $dependency (.;
.[$dependency | ascii_downcase] += [$library.key | package_name]))) as $reverse
| $libraries | to_entries[]
| select(.value.type == "package")
| select(.key | package_name | watched)
| select(.key | major >= 11)
| (.key | package_name) as $package
| (.key | package_version) as $version
| (.key | major) as $major
| select(($allowed | index(($package | ascii_downcase) + "@" + ($major | tostring))) | not)
| first_direct($reverse; $direct; $package) as $top
| if $top == null then "\($package) \($version) (via a project reference)"
elif ($top | ascii_downcase) == ($package | ascii_downcase) then "\($package) \($version) (direct dependency)"
else "\($package) \($version) (via \($top))"
end
Loading
Loading