From a8a7e6f80faa15721c180e6179b3004ae69eee6b Mon Sep 17 00:00:00 2001 From: Nano Taboada <87288+nanotaboada@users.noreply.github.com> Date: Sun, 16 Mar 2025 16:59:58 -0300 Subject: [PATCH] chore(ci): improve .NET CI workflow --- .github/workflows/dotnet.yml | 108 +++++++++++++++++------------------ 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 458183a..60f2f63 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -10,24 +10,30 @@ on: branches: [ "master" ] jobs: - build: runs-on: ubuntu-latest steps: + - name: Checkout repository + uses: actions/checkout@v4 - - name: Checkout repository - uses: actions/checkout@v4 + - name: Set up .NET 8 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x - - name: Set up .NET 8 - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x + - name: Cache NuGet packages + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + restore-keys: | + ${{ runner.os }}-nuget- - - name: Restore dependencies - run: dotnet restore + - name: Restore dependencies + run: dotnet restore - - name: Build projects - run: dotnet build --no-restore + - name: Build projects + run: dotnet build --no-restore test: needs: build @@ -35,66 +41,58 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Run tests and collect code coverage (Cobertura) run: dotnet test --results-directory "coverage" --collect:"Code Coverage;Format=cobertura" - - name: Install dotnet-coverage - run: dotnet tool update --global dotnet-coverage + + - name: Install dotnet-coverage tool + run: dotnet tool install --global dotnet-coverage + - name: Merge coverage reports run: dotnet-coverage merge coverage/**/*.cobertura.xml --output coverage/cobertura.xml --output-format cobertura - - name: Install ReportGenerator + + - name: Install ReportGenerator tool run: dotnet tool install --global dotnet-reportgenerator-globaltool - - name: Run ReportGenerator to generate Markdown summary + + - name: Generate Markdown summary run: reportgenerator -reports:coverage/cobertura.xml -targetdir:coverage -reporttypes:"MarkdownSummaryGithub" + - name: Display Markdown summary run: cat coverage/SummaryGithub.md >> $GITHUB_STEP_SUMMARY + - name: Upload coverage report artifact uses: actions/upload-artifact@v4 with: name: cobertura.xml path: coverage/cobertura.xml - coverage-codecov: - needs: test - runs-on: ubuntu-latest - steps: - - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Download coverage report artifact - uses: actions/download-artifact@v4 - with: - name: cobertura.xml - - - name: Display structure of downloaded files - run: ls -R cobertura.xml - - - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v5.4.0 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: cobertura.xml - use_oidc: false - verbose: true - - coverage-codacy: + coverage: needs: test runs-on: ubuntu-latest + strategy: + matrix: + service: [codecov, codacy] # Parallel jobs for Codecov and Codacy steps: + - name: Checkout repository + uses: actions/checkout@v4 - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Download coverage report artifact - uses: actions/download-artifact@v4 - with: - name: cobertura.xml - - - name: Display coverage report file - run: ls -lah cobertura.xml + - name: Download coverage report artifact + uses: actions/download-artifact@v4 + with: + name: cobertura.xml - - name: Upload coverage report to Codacy - uses: codacy/codacy-coverage-reporter-action@v1.3.0 - with: - project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} - coverage-reports: cobertura.xml \ No newline at end of file + - name: Upload coverage report to ${{ matrix.service }} + if: ${{ matrix.service == 'codecov' }} + uses: codecov/codecov-action@v5.4.0 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: cobertura.xml + use_oidc: false + verbose: true + + - name: Upload coverage report to ${{ matrix.service }} + if: ${{ matrix.service == 'codacy' }} + uses: codacy/codacy-coverage-reporter-action@v1.3.0 + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: cobertura.xml