Repository navigation
feat(csharp-ci): fail when a packable net10.0 target resolves Microsoft.Extensions or AspNetCore 11 #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(csharp-ci): fail when a packable net10.0 target resolves Microsoft.Extensions or AspNetCore 11 #53
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
a2cb8a2
feat(csharp-ci): fail when a packable net10.0 target resolves Microso…
monsieurleberre 68d6c10
chore(csharp-ci): add the SPDX header to the guard filter
monsieurleberre 16c3127
fix(csharp-ci): evaluate guard packability in Release, ignore IsPacka…
monsieurleberre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
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) | ||
|
monsieurleberre marked this conversation as resolved.
Resolved
|
||
| echo "net10.0 package guard: checked $checked packable project(s)" | ||
| exit "$failed" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.