From ff73ef085d4bffeb8f3fdd53969e2213cc889902 Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Mon, 23 Dec 2024 10:49:44 +0100 Subject: [PATCH 1/5] feat: update GitHub Actions workflow for multi-platform and multi-version .NET support --- .github/workflows/dotnet.yml | 52 +++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 9d309aa..f258557 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -3,34 +3,50 @@ name: .NET -on: - push: - branches: ["main"] - pull_request: - branches: ["main"] +on: [push, pull_request] + +env: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 jobs: build: - runs-on: ubuntu-latest + name: ${{ matrix.platform.name }} ${{ matrix.dotnet.name }} + runs-on: ${{ matrix.platform.os }} + #runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + platform: + - { name: Linux, os: ubuntu-22.04 } + - { name: Windows, os: windows-2022 } + - { name: macOS, os: macos-15 } + dotnet: + - { name: .NET 6, version: "6.0.x" } + - { name: .NET 7, version: "7.0.x" } + - { name: .NET 8, version: "8.0.x" } + - { name: .NET 9, version: "9.0.x" } steps: - uses: actions/checkout@v4 - - name: Setup .NET + - id: setup-dotnet uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x - - name: Restore dependencies - run: dotnet restore + dotnet-version: ${{ matrix.dotnet.version }} + - name: Enforce SDK Version + run: dotnet new globaljson --sdk-version ${{ steps.setup-dotnet.outputs.dotnet-version }} --force - name: Build - run: dotnet build --no-restore - - - run: dotnet test --results-directory "test-results" --collect:"Code Coverage" - - run: dotnet tool update --global dotnet-coverage - - run: dotnet-coverage merge --output test-result.cobertura.xml --output-format cobertura "test-results/**/*.coverage" - - run: dotnet tool install --global dotnet-reportgenerator-globaltool - - run: reportgenerator -reports:test-result.cobertura.xml -targetdir:coverage-report -reporttypes:"Html;JsonSummary;MarkdownSummaryGithub;Badges" - - run: cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY + run: dotnet build -c Release + - name: Test + if: matrix.dotnet.version == '9.0.x' && matrix.platform.name == 'MacOS' + run: | + dotnet test --results-directory "test-results" --collect:"Code Coverage" + dotnet tool update --global dotnet-coverage + dotnet-coverage merge --output test-result.cobertura.xml --output-format cobertura "test-results/**/*.coverage" + dotnet tool install --global dotnet-reportgenerator-globaltool + reportgenerator -reports:test-result.cobertura.xml -targetdir:coverage-report -reporttypes:"Html;JsonSummary;MarkdownSummaryGithub;Badges" + cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY - name: ReportGenerator uses: danielpalme/ReportGenerator-GitHub-Action@5.3.11 From ea7236c44715f8e2f5675364b26abf66cdc502ae Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Mon, 23 Dec 2024 10:51:06 +0100 Subject: [PATCH 2/5] feat: update GitHub Actions workflow to remove outdated .NET versions --- .github/workflows/dotnet.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index f258557..71baa74 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -23,9 +23,6 @@ jobs: - { name: Windows, os: windows-2022 } - { name: macOS, os: macos-15 } dotnet: - - { name: .NET 6, version: "6.0.x" } - - { name: .NET 7, version: "7.0.x" } - - { name: .NET 8, version: "8.0.x" } - { name: .NET 9, version: "9.0.x" } steps: From d7bb59b58e0803eb96c12e9a580ee8cb943d1160 Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Mon, 23 Dec 2024 10:56:59 +0100 Subject: [PATCH 3/5] feat: update GitHub Actions workflow to run tests and generate reports on MacOS platform --- .github/workflows/dotnet.yml | 9 +++++++-- CodeLineCounter.Tests/CoreUtilsTests.cs | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 71baa74..baf2f0c 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -36,7 +36,7 @@ jobs: - name: Build run: dotnet build -c Release - name: Test - if: matrix.dotnet.version == '9.0.x' && matrix.platform.name == 'MacOS' + if: matrix.platform.name == 'MacOS' run: | dotnet test --results-directory "test-results" --collect:"Code Coverage" dotnet tool update --global dotnet-coverage @@ -46,6 +46,7 @@ jobs: cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY - name: ReportGenerator + if: matrix.platform.name == 'MacOS' uses: danielpalme/ReportGenerator-GitHub-Action@5.3.11 with: reports: "test-result.cobertura.xml" @@ -54,28 +55,32 @@ jobs: - name: Upload coverage report artifact uses: actions/upload-artifact@v4 + if: matrix.platform.name == 'MacOS' with: name: coverage-report path: coverage-report - name: Upload coverage badge artifact uses: actions/upload-artifact@v4 + if: matrix.platform.name == 'MacOS' with: name: coverage-badge.svg path: coverage-report/badge_combined.svg - name: Add comment to PR - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' && matrix.platform.name == 'MacOS' run: gh pr comment $PR_NUMBER --body-file coverage-report/SummaryGithub.md env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} - name: Publish coverage in build summary # Only applicable if 'MarkdownSummaryGithub' or one of the other Markdown report types is generated + if: matrix.platform.name == 'MacOS' run: cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY # Adjust path and filename if necessary shell: bash - name: Generate Coverage Badge + if: matrix.platform.name == 'MacOS' run: | echo "![Coverage](./coverage-report/badge_combined.svg)" > coverage-badge.md cat coverage-badge.md >> README.md diff --git a/CodeLineCounter.Tests/CoreUtilsTests.cs b/CodeLineCounter.Tests/CoreUtilsTests.cs index 8cc0dea..c5864eb 100644 --- a/CodeLineCounter.Tests/CoreUtilsTests.cs +++ b/CodeLineCounter.Tests/CoreUtilsTests.cs @@ -117,6 +117,8 @@ public void GetUserChoice_Should_Return_Valid_Choice() int solutionCount = 5; string input = "3"; var inputStream = new StringReader(input); + var consoleOutput = new StringWriter(); + Console.SetOut(consoleOutput); Console.SetIn(inputStream); // Act @@ -133,6 +135,8 @@ public void GetUserChoice_Should_Return_Invalid_Choice() int solutionCount = 5; string input = "invalid"; var inputStream = new StringReader(input); + var consoleOutput = new StringWriter(); + Console.SetOut(consoleOutput); Console.SetIn(inputStream); // Act @@ -149,6 +153,8 @@ public void GetUserChoice_returns_valid_selection_for_valid_input() // Arrange var input = "2"; var consoleInput = new StringReader(input); + var consoleOutput = new StringWriter(); + Console.SetOut(consoleOutput); Console.SetIn(consoleInput); // Act @@ -166,6 +172,8 @@ public void GetUserChoice_handles_invalid_input(string input) { // Arrange var consoleInput = new StringReader(input); + var consoleOutput = new StringWriter(); + Console.SetOut(consoleOutput); Console.SetIn(consoleInput); // Act From a99e3153355be79afc678dfd7c97dee0be0be99d Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Mon, 23 Dec 2024 10:59:11 +0100 Subject: [PATCH 4/5] feat: update GitHub Actions workflow to use Ubuntu 24.04 for Linux jobs --- .github/workflows/dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index baf2f0c..d9333b7 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: platform: - - { name: Linux, os: ubuntu-22.04 } + - { name: Linux, os: ubuntu-24.04 } - { name: Windows, os: windows-2022 } - { name: macOS, os: macos-15 } dotnet: @@ -86,7 +86,7 @@ jobs: cat coverage-badge.md >> README.md publish_badge: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 needs: build steps: - name: Checkout gh-pages From 06bef880bdbbcee5a8ff4bd8cc7ae76f5b824c81 Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Mon, 23 Dec 2024 11:02:26 +0100 Subject: [PATCH 5/5] fix: improve null safety in DependencyAnalyzer for SourceAssembly retrieval --- CodeLineCounter/Services/DependencyAnalyzer.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CodeLineCounter/Services/DependencyAnalyzer.cs b/CodeLineCounter/Services/DependencyAnalyzer.cs index b9a6a40..2048ff3 100644 --- a/CodeLineCounter/Services/DependencyAnalyzer.cs +++ b/CodeLineCounter/Services/DependencyAnalyzer.cs @@ -118,7 +118,12 @@ public static void AnalyzeFile(string filePath, string sourceCode) { SourceClass = GetSimpleTypeName(classDeclaration), SourceNamespace = classDeclaration.Ancestors().OfType().FirstOrDefault()?.Name.ToString() ?? "", - SourceAssembly = classDeclaration.SyntaxTree.GetRoot().DescendantNodes().OfType().FirstOrDefault()?.Usings.FirstOrDefault()?.Name.ToString() ?? "", + SourceAssembly = classDeclaration.SyntaxTree.GetRoot() + .DescendantNodes() + .OfType() + .FirstOrDefault()? + .Usings.FirstOrDefault()? + .Name?.ToString() ?? "", TargetClass = dependency.Split('.')[(dependency.Split('.').Length - 1)], TargetNamespace = dependency.Contains(".") ? dependency.Substring(0, dependency.LastIndexOf('.')) : "", TargetAssembly = dependency.Contains(".") ? dependency.Substring(0, dependency.LastIndexOf('.')) : "",