Skip to content

ci: improve coverage upload reliability and observability - #19

Merged
Franchef merged 2 commits into
mainfrom
copilot/update-ci-workflow-for-coverage
May 9, 2026
Merged

ci: improve coverage upload reliability and observability#19
Franchef merged 2 commits into
mainfrom
copilot/update-ci-workflow-for-coverage

Conversation

Copilot AI commented May 9, 2026

Copy link
Copy Markdown
Contributor

Both coverage upload steps lacked conditional execution, a token for Codecov auth, and useful diagnostics. Artifact path was too broad, with no retention policy.

Changes

Upload coverage report

  • if: always() — runs even on test failure for post-mortem debugging
  • path: coverage/**/*.xml — scoped to actual coverage output instead of entire coverage/ dir
  • if-no-files-found: warn — non-fatal when coverage files are absent
  • retention-days: 7 — bounded artifact storage

Upload coverage to Codecov

  • if: always() — consistent with artifact upload behavior
  • token: ${{ secrets.CODECOV_TOKEN }} — explicit auth token
  • verbose: true — surfacing upload diagnostics in CI logs
- name: Upload coverage report
  if: always()
  uses: actions/upload-artifact@v5
  with:
    name: coverage-report
    path: coverage/**/*.xml
    if-no-files-found: warn
    retention-days: 7

- name: Upload coverage to Codecov
  if: always()
  uses: codecov/codecov-action@v5
  with:
    token: ${{ secrets.CODECOV_TOKEN }}
    directory: coverage/
    fail_ci_if_error: false
    verbose: true
Original prompt

Create a pull request in repository Franchef/Semantic.NET that updates the CI workflow at .github/workflows/ci.yml.

Requirements:

  • Work from the existing branch copilot/fix-ci-coverage-upload if possible, otherwise use an appropriate branch based on the provided base branch.
  • Update the Upload coverage report step to:
    • add if: always()
    • keep uses: actions/upload-artifact@v5
    • set name: coverage-report
    • change path from coverage/ to coverage/**/*.xml
    • add if-no-files-found: warn
    • add retention-days: 7
  • Update the Upload coverage to Codecov step to:
    • add if: always()
    • keep uses: codecov/codecov-action@v5
    • add token: ${{ secrets.CODECOV_TOKEN }}
    • keep directory: coverage/
    • keep fail_ci_if_error: false
    • add verbose: true
  • Do not change unrelated parts of the workflow.
  • After applying the change, open a pull request against main.

The file currently being updated is .github/workflows/ci.yml.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Suggest improvements to this code.

Assistant: A few small workflow smells stand out in this snippet:

  1. Unconditional artifact upload

    • Upload coverage report runs even if tests fail earlier, which can be wasteful or misleading depending on what files exist.
    • In GitHub Actions, this is often clearer when controlled explicitly with if:.
  2. Very broad artifact path

    • Uploading coverage/ blindly may include extra test result files, nested folders, or inconsistent output depending on how dotnet test writes results.
    • It’s usually better to upload only the actual coverage files you care about.
  3. No artifact retention policy

    • Artifacts default to GitHub’s retention settings, which may be longer than needed for CI coverage outputs.
    • Setting retention-days keeps storage usage predictable.

Recommended improvements

Option 1: Keep the current structure, but make it more explicit

This is the smallest improvement and fits GitHub Actions best practices well:

      - name: Upload coverage report
        if: always()
        uses: actions/upload-artifact@v5
        with:
          name: coverage-report
          path: |
            coverage/**/*.xml
            coverage/**/*.cobertura.xml
          if-no-files-found: warn
          retention-days: 7

Why this is better

  • if: always() ensures upload still happens even if tests fail, which is useful for debugging partial results.
  • path is narrowed to likely coverage outputs instead of the whole directory.
  • if-no-files-found: warn avoids failing the workflow just because coverage files weren’t generated.
  • retention-days: 7 reduces unnecessary artifact storage.

Option 2: Upload only on success

If you only want artifacts when tests completed successfully, make that intent explicit:

      - name: Upload coverage report
        if: success()
        uses: actions/upload-artifact@v5
        with:
          name: coverage-report
          path: |
            coverage/**/*.xml
            coverage/**/*.cobertura.xml
          if-no-files-found: error
          retention-days: 7

When to choose this

  • Use this if missing coverage should be treated as a real CI problem.
  • It keeps artifacts cleaner, but you lose partial debugging data from failed test runs.

Option 3: Simplify by removing the artifact step entirely

Since you already upload coverage to Codecov right after this, the artifact upload may be redundant unless you specifically want downloadable raw coverage files from GitHub Actions.

If you do not need manual download/debugging of coverage files, you could simplify to:

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v5
        with:
          directory: coverage/
          fail_ci_if_error: false

Why this may be better

  • Fewer steps to maintain.
  • Less artifact storage.
  • Clearer CI pipeline if Codecov is the only consumer.

Best-practice recommendation for this workflow

For a .NET CI pipeline, I’d recommend either:

  • artifact + Codecov if you want debugging visibility, or
  • Codecov only if you want the workflow as simple as possible.

If you keep the artifact step, this version is probably the best balance:

      - name: Upload coverage report
        if: always()
        uses: actions/upload-artifact@v5
        with:
          name: coverage-report
          path: coverage/**/*.xml
          if-no-files-found: warn
          retention-days: 7

One more .NET-specific note: if you know the exact coverage format produced by --collect:"XPlat Code Coverage" in your setup, you can make the path even more precise, for example:

path: coverage/**/coverage.cobertura.xml

That’s usually the cleanest option for .NET test coverage output.

User: ```

  • name: Upload coverage reports to Codecov
    use...

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Update CI workflow to improve coverage report handling ci: improve coverage upload reliability and observability May 9, 2026
Copilot AI requested a review from Franchef May 9, 2026 18:09
@Franchef Franchef added this to the NuGet packages milestone May 9, 2026
@Franchef Franchef added the enhancement New feature or request label May 9, 2026
@Franchef Franchef linked an issue May 9, 2026 that may be closed by this pull request
@codecov

codecov Bot commented May 9, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@Franchef
Franchef marked this pull request as ready for review May 9, 2026 18:13
@Franchef
Franchef merged commit fd7b58e into main May 9, 2026
3 checks passed
@Franchef
Franchef deleted the copilot/update-ci-workflow-for-coverage branch May 9, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

README badges

2 participants