From 5e956ff566313545ef34573ce1e2ae96ac4d894e Mon Sep 17 00:00:00 2001 From: thecoderatekid Date: Thu, 7 Aug 2025 20:25:05 +0000 Subject: [PATCH] Update .gitea/workflows/dotnet-test.yml --- .gitea/workflows/dotnet-test.yml | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.gitea/workflows/dotnet-test.yml b/.gitea/workflows/dotnet-test.yml index d42dd53..0d56589 100644 --- a/.gitea/workflows/dotnet-test.yml +++ b/.gitea/workflows/dotnet-test.yml @@ -15,14 +15,16 @@ jobs: - name: Set up .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: '8.0.x' # or '7.0.x' if you prefer + dotnet-version: '8.0.x' - name: Detect & build/test shell: bash run: | + set -euo pipefail + has_solution=false - # Find any .sln or .csproj - if find . -maxdepth 2 -name '*.sln' -o -name '*.csproj' | grep -q .; then + # Group the -name tests so -o doesn’t mess with precedence + if find . -maxdepth 2 \( -name '*.sln' -o -name '*.csproj' \) | grep -q .; then has_solution=true fi @@ -30,7 +32,7 @@ jobs: echo "Detected .NET project; restoring/building/testing..." dotnet restore dotnet build --no-restore -c Release - # Run tests if there are any test projects; otherwise just succeed after build + # Run tests if any project is a test project if find . -name '*Tests.csproj' -o -name '*.csproj' -exec grep -l 'true' {} + | grep -q .; then dotnet test --no-build -c Release --verbosity normal else @@ -44,16 +46,17 @@ jobs: dotnet sln HelloCI.sln add src/App/App.csproj tests/App.Tests/App.Tests.csproj dotnet add tests/App.Tests/App.Tests.csproj reference src/App/App.csproj + # Heredoc terminator must start at column 0 — no indentation cat > tests/App.Tests/UnitTest1.cs <<'EOF' - using Xunit; - namespace App.Tests; - public class UnitTest1 - { - [Fact] public void Adds() => Assert.Equal(4, 2+2); - } - EOF +using Xunit; +namespace App.Tests; +public class UnitTest1 +{ + [Fact] public void Adds() => Assert.Equal(4, 2+2); +} +EOF - dotnet restore - dotnet build -c Release - dotnet test -c Release --no-build --verbosity normal + dotnet restore + dotnet build -c Release + dotnet test -c Release --no-build --verbosity normal fi