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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
48bde8411845cb66
75fec62441fc8729

Large diffs are not rendered by default.

37 changes: 22 additions & 15 deletions .github/actions/package-consume-nuget/package_consume_nuget.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,28 @@ def global_json_line(path: Path) -> str | None:
def project_properties(project: str) -> dict[str, str]:
# The leaf packs Release on main and Debug elsewhere, and a property can be conditioned on it.
configuration = "Release" if os.environ.get("BRANCH") == "main" else "Debug"
result = subprocess.run(
[
"dotnet",
"msbuild",
project,
"-nologo",
f"-property:Configuration={configuration}",
"-getProperty:" + ",".join(PROPERTIES),
],
capture_output=True,
text=True,
encoding="utf-8",
check=False,
timeout=COMMAND_TIMEOUT_SECONDS,
)
try:
result = subprocess.run(
[
"dotnet",
"msbuild",
project,
"-nologo",
f"-property:Configuration={configuration}",
"-getProperty:" + ",".join(PROPERTIES),
],
capture_output=True,
text=True,
encoding="utf-8",
check=False,
timeout=COMMAND_TIMEOUT_SECONDS,
)
except subprocess.TimeoutExpired as error:
# An uncaught timeout is a bare traceback, so it is reported as the annotated failure it is.
print(
f"::error::{escape_command(f'Reading {project} properties timed out after {COMMAND_TIMEOUT_SECONDS} seconds.')}"
)
raise SystemExit(1) from error
if result.returncode != 0:
raise SystemExit(f"Reading {project}'s properties failed:\n{result.stdout}{result.stderr}")
return {k: str(v) for k, v in json.loads(result.stdout)["Properties"].items()}
Expand Down
29 changes: 23 additions & 6 deletions .github/actions/package-consume-pypi/package_consume_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def consume(
name: str,
version: str,
project: Path,
requirements: Sequence[str],
requirements: Sequence[str] | None,
work: Path,
env: Mapping[str, str],
report: Report,
Expand All @@ -275,8 +275,9 @@ def consume(
if not report.add(target, "install", installed.returncode == 0, artifact.name):
return
# The project is excluded from the groups, so only its dependencies and tools are added to the artifact's.
groups = run(["uv", "pip", "install", "--python", python, *requirements], project, env)
report.add(target, "test dependencies", groups.returncode == 0, "locked groups, no project")
if requirements is not None:
groups = run(["uv", "pip", "install", "--python", python, *requirements], project, env)
report.add(target, "test dependencies", groups.returncode == 0, "locked groups, no project")

files = run([python, "-I", "-c", FILES_PROBE, name], work, env)
metadata = probe_rows(files.stdout)
Expand Down Expand Up @@ -321,6 +322,15 @@ def consume(
if not tests.is_dir():
report.add(target, "tests", True, f"{tests.name} folder is absent", skipped=True)
return
if requirements is None:
# A pass would claim the tests ran against dependencies that were never installed.
report.add(
target,
"tests",
False,
"not run, the locked test dependencies could not be exported",
)
return
# The working directory is outside the project, so the source tree is not on sys.path.
cache = f"cache_dir={work / '.pytest_cache'}"
outcome = run([python, "-m", "pytest", str(tests), *PYTEST_ARGUMENTS, "-o", cache], work, env)
Expand All @@ -335,11 +345,18 @@ def check(project: Path, version: str, lines: Sequence[str], work: Path) -> int:
env = clean_environment()
name = project_name(project / "pyproject.toml")
artifacts = find_artifacts(project / "dist")
requirements: list[str] | None
try:
requirements = export_requirements(project, work / "requirements.txt", env)
except OSError as error:
report.add("all", "test dependencies", False, str(error))
requirements = []
except (OSError, subprocess.TimeoutExpired) as error:
# A timed-out export must still reach the per-artifact checks and the summary, and the step still fails.
detail = (
f"uv export timed out after {COMMAND_TIMEOUT_SECONDS} seconds"
if isinstance(error, subprocess.TimeoutExpired)
else str(error)
)
report.add("all", "test dependencies", False, detail)
requirements = None
for line in lines:
print(f"::group::{escape_command(f'consume py{line}')}")
try:
Expand Down

Large diffs are not rendered by default.

39 changes: 23 additions & 16 deletions .github/workflows/validate-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ on:
type: string
default: ''
dotnet-versions:
description: JSON array of the X.Y .NET lines a multi-targeted caller's projects build, one per target framework, for example ["11.0", "10.0"]. The first entry is the line the root global.json selects, which builds every target framework, and a first entry differing from it fails the run. Every listed line is installed in each .NET leg, and each entry is its own Unit test job (.NET X.Y) leg running dotnet test --framework netX.Y under that line's runtime. Quote each entry, since an unquoted one is a JSON number rather than a line. Empty installs the one line global.json selects, or the hub's fallback line where it carries none.
description: JSON array of the X.Y .NET lines a multi-targeted caller's projects build, one per target framework, for example ["11.0", "10.0"]. The first entry is the line the root global.json selects, which builds every target framework, and a first entry differing from it fails the run. Every listed line is installed in each .NET leg, and each entry is its own Unit test job (.NET X.Y) leg running dotnet test --framework netX.Y under that line's runtime. A leg runs only the tracked *Tests*.csproj projects declaring netX.Y in their TargetFramework or TargetFrameworks, skips and names the others, and fails where no test project declares its line. Quote each entry, since an unquoted one is a JSON number rather than a line. Empty installs the one line global.json selects, or the hub's fallback line where it carries none.
required: false
type: string
default: ''
Expand Down Expand Up @@ -1074,32 +1074,39 @@ jobs:
with:
versions: ${{ inputs.dotnet-versions }}

- name: Resolve .NET workspaces step
id: dotnet
if: hashFiles('**/*Tests*.csproj') != ''
uses: $/.github/actions/dotnet-workspaces
with:
projects: ':(glob)**/*Tests*.csproj'

# --coverage-output stays unset because pinning one filename gives every test project in the solution the same path, and the last to finish overwrites the rest.
# The default <guid>.cobertura.xml written instead is a name codecov-cli's finder does not match.
# Each report is therefore prefixed rather than renamed, keeping the guid that makes it unique.
- name: Run unit tests step
if: hashFiles('**/*Tests*.csproj') != ''
env:
WORKSPACES: ${{ steps.dotnet.outputs.workspaces }}
DOTNET_VERSION: ${{ matrix.dotnet-version }}
run: |
set -Eeuo pipefail
rm -rf ./coverage
# A solution holding no test project fails dotnet test with no test projects found, so the tests are named one project at a time.
if [ -z "$WORKSPACES" ]; then
dotnet test --framework "net$DOTNET_VERSION" --coverage --coverage-output-format cobertura --results-directory ./coverage
# A solution holding no test project fails dotnet test with no test projects found, and a project not declaring the leg's line fails --framework.
# So every tracked test project is read and named one at a time, whatever the root holds.
projects="$(git ls-files -- ':(glob)**/*Tests*.csproj')"
# A project not declaring the leg's line fails --framework, so it is skipped by name rather than failing the leg.
selected=()
while IFS= read -r project; do
[ -n "$project" ] || continue
properties="$(dotnet msbuild "$project" -nologo -getProperty:TargetFramework -getProperty:TargetFrameworks < /dev/null)"
# MSBuild trims each list entry and compares a framework without regard to case, so the match does too.
if jq -e --arg line "net$DOTNET_VERSION" '[.Properties.TargetFramework, .Properties.TargetFrameworks] | map(select(. != null) | split(";")[] | gsub("\\s"; "") | ascii_downcase) | any(. == $line)' <<< "$properties" > /dev/null; then
selected+=("$project")
else
echo "Skipping $project, which does not declare net$DOTNET_VERSION."
fi
done <<< "$projects"
# A declared line must never pass by running nothing.
if [ "${#selected[@]}" -eq 0 ]; then
echo "::error::No test project declares net$DOTNET_VERSION in its TargetFramework or TargetFrameworks, so the .NET $DOTNET_VERSION leg would run no tests."
exit 1
fi
while IFS= read -r workspace; do
[ -n "$workspace" ] || continue
dotnet test --framework "net$DOTNET_VERSION" --project "$workspace" --coverage --coverage-output-format cobertura --results-directory ./coverage < /dev/null
done <<< "$WORKSPACES"
for project in "${selected[@]}"; do
dotnet test --framework "net$DOTNET_VERSION" --project "$project" --coverage --coverage-output-format cobertura --results-directory ./coverage < /dev/null
done
written=0
for report in ./coverage/*.cobertura.xml; do
[ -e "$report" ] || continue
Expand Down
Loading
Loading