Skip to content

[RFC] Microsoft.Testing.Extensions.GitHubReport: publish test results to GitHub from MTP #9003

Closed

Description

Summary

Propose a new MTP extension Microsoft.Testing.Extensions.GitHubReport that publishes test results back to GitHub when the test session runs in GitHub Actions. Mirrors the design and CLI shape of the existing Microsoft.Testing.Extensions.AzureDevOpsReport extension.

Motivation

Today, users running MTP-powered test projects on GitHub Actions get test results in two places:

  1. The raw stdout of the workflow step.
  2. A separate, post-process Action (dorny/test-reporter, EnricoMi/publish-unit-test-result-action, ctrf-io/github-test-reporter, …) that parses TRX or JUnit after the test step finishes.

The post-process path works but:

  • It runs after the fact (no live progress, no real-time annotations).
  • File/line annotations are best-effort regex over TRX/JUnit, not authoritative test-node metadata.
  • It requires every consumer to wire up a separate job step.

We already have Microsoft.Testing.Extensions.AzureDevOpsReport, which integrates natively with Azure DevOps (live publishing, build summary, annotations, progress, artifact upload). The GitHub equivalent is a natural symmetry to add.

Proposed design

Detection

Mirror the AzDO extension''s TF_BUILD=true gating:

  • GITHUB_ACTIONS=true enables the extension.
  • GITHUB_TOKEN, GITHUB_REPOSITORY, GITHUB_REF, GITHUB_SHA, GITHUB_RUN_ID, GITHUB_STEP_SUMMARY consumed as needed (each tier degrades gracefully if its required vars are missing, with a trace log).
  • All CLI options no-op outside GitHub Actions and emit a warning if explicitly set (same pattern as --report-azdo*).

Three tiers (adoptable incrementally)

Tier Feature Auth GitHub API
1 Job summary + workflow logging commands — write a Markdown summary to $GITHUB_STEP_SUMMARY; emit ::error file=…,line=…,title=…::message for failures, ::warning file=… for skipped, ::notice for retries. None Built-in (file + stdout)
2 Check Run with annotations — create a Check Run, attach per-failure annotations pinned to file:line using TestFileLocationProperty from the TestNode. GITHUB_TOKEN POST/PATCH /repos/{owner}/{repo}/check-runs
3 Sticky PR comment — post/update a single comment on the PR with the summary table (find-or-create by marker). GITHUB_TOKEN + pull_request event POST/PATCH /repos/.../issues/{n}/comments

CLI options (mirroring --report-azdo*)

  • --report-github — master switch (default on when GITHUB_ACTIONS=true).
  • --report-github-summary — Tier 1 Markdown summary.
  • --report-github-progress — Tier 1 progress via step summary updates.
  • --report-github-annotations — Tier 1 ::error workflow commands (and Tier 2 Check Run annotations if a token is available).
  • --report-github-comment — Tier 3 sticky PR comment.

Implementation outline

File layout mirrors src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/:

  • GitHubExtensions.cs — public AddGitHubProvider(this ITestApplicationBuilder) entry point.
  • GitHubCommandLineProvider.cs / GitHubCommandLineOptions.cs — CLI surface.
  • GitHubReporter.cs — env detection, master switch.
  • GitHubSummaryReporter.cs — Tier 1 summary writer.
  • GitHubAnnotationEmitter.cs — Tier 1 workflow command emitter.
  • GitHubCheckRunClient.cs / GitHubCheckRunPublisher.cs — Tier 2 Check Runs API.
  • GitHubPullRequestCommentClient.cs / GitHubPullRequestCommentPublisher.cs — Tier 3 sticky comment.
  • TestingPlatformBuilderHook.cs — auto-registration hook.
  • PACKAGE.md, BannedSymbols.txt, csproj.

Why an MTP extension instead of a separate Action?

Aspect MTP extension Post-process Action
Setup Reference one NuGet + flag Add a separate workflow step
Live progress ✅ Check Run updates ❌ After test step exits
File/line annotation fidelity ✅ Direct from TestNode metadata Best-effort regex over TRX
Works for fork PRs ✅ GITHUB_TOKEN ✅
Maintenance We own it Third-party

Trade-offs / open questions

  1. Doesn''t help the microsoft/testfx repo''s own CI — testfx runs on AzDO, not GitHub Actions, so this extension wouldn''t have GITHUB_TOKEN available in our own pipelines. This is primarily useful for users of MTP running on GitHub Actions.
  2. HTTP from the test host — Tier 2/3 introduce REST calls during/after the test session. AzDO extension already does the same; design GitHubCheckRunClient after AzureDevOpsTestResultsClient.
  3. Permission scoping — Tier 2 needs checks: write; Tier 3 needs pull-requests: write. Document required permissions: block in PACKAGE.md.
  4. Authentication beyond GITHUB_TOKEN — should we also accept a PAT or GitHub App token via env var (e.g. for self-hosted/Jenkins-running-against-GitHub-PR scenarios)? Recommend yes, via GITHUBREPORTER_TOKEN fallback.
  5. Annotation aggregation limits — GitHub caps Check Run annotations at 50 per request; need batching for large failure counts (mirroring how AzureDevOpsArtifactUploader batches).
  6. xUnit/NUnit/TUnit — should work via MTP for any test framework that emits TestFileLocationProperty; verify and document gaps.

Out of scope

  • Auto-creating a PR with fix suggestions.
  • Coverage publishing (separate concern; can be a sibling extension or layered on top once the GitHub plumbing exists).
  • Trend/history (the AzDO extension''s AzureDevOpsHistoryService is AzDO-API-specific; GitHub equivalent would need workflow-run-history APIs and is a follow-up).

Acceptance criteria

  • New extension project under src/Platform/Microsoft.Testing.Extensions.GitHubReport/ builds and packs as Microsoft.Testing.Extensions.GitHubReport.
  • Tier 1 works in any GitHub Actions workflow with zero additional configuration.
  • Tier 2/3 work when permissions: grants checks: write / pull-requests: write.
  • Acceptance tests under test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ exercise each tier with a fake/stub GitHub server.
  • PACKAGE.md documents required workflow permissions: blocks and the CLI surface.

🤖 RFC drafted with the assistance of GitHub Copilot CLI.

Activity

  1. Evangelink commented on Jul 13, 2026

    @Evangelink
    MemberAuthor

    Where this landed, and what's next

    I went back through the code before answering. The RFC is partially delivered: the token-free tier shipped (and then some), the token-based tiers did not. More importantly, re-examining the token tiers surfaced a feasibility blocker the original write-up under-weighted. Details below.

    ✅ Shipped as Microsoft.Testing.Extensions.GitHubActionsReport

    The RFC's Tier 1 (and more) is in src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/, gated on GITHUB_ACTIONS=true + the --report-gh master switch, unit-tested:

    • --report-gh-annotations — ::error file=,line=,col=,title= per failure (source location resolved from the exception stack trace, repo-root-relative) + title-only ::warning for skips. These already surface in the PR "Files changed" gutter and the Annotations tab.
    • --report-gh-step-summary — Markdown summary table to $GITHUB_STEP_SUMMARY.
    • --report-gh-groups — ::group::/::endgroup:: per assembly (beyond the RFC).
    • --report-gh-slow-test-notices + --report-gh-slow-test-threshold (beyond the RFC).

    All of this needs no token and no HTTP, works on any workflow with zero config, and — notably — already delivers the RFC's headline "authoritative file:line annotations" selling point.

    ❌ Not built: Tier 2 (Check Run) and Tier 3 (sticky PR comment)

    No GITHUB_TOKEN, HttpClient, Check Run, or PR-comment code exists.

    The blocker that reframes the decision

    On a pull_request run from a fork, the default GITHUB_TOKEN is read-only — it can't checks: write (Tier 2) or pull-requests: write (Tier 3). So both token tiers would silently no-op in the exact OSS-on-Actions scenario that motivates them. pull_request_target works but is a security footgun we shouldn't nudge users toward. The RFC's compatibility table optimistically marked forks ✅; in practice they're the weakest case for the token tiers.

    Cost/benefit per remaining tier

    • Tier 2 – Check Run: incremental value over the shipped annotations is modest (annotations are already on the PR + Annotations tab). It mainly adds a named status check and escapes the ~10-annotation-per-command soft cap. Cost: HTTP-from-test-host reliability, token scoping, 50-annotations-per-request batching, the fork limitation, and testfx can't dogfood it (our CI is AzDO) so it'd be stub-server-tested only.
    • Tier 3 – sticky PR comment: lowest differentiation — posted at end-of-run (not "live"), duplicates a crowded ecosystem (EnricoMi, dorny, ctrf), same fork wall, and the token-free step summary already renders the same table.

    Recommendation

    1. Close the Tier-1 scope of this RFC as delivered. The high-value, zero-config 80% is shipped.
    2. Do not build Tiers 2/3 speculatively. Keep one tracking issue for "token-based GitHub publishing," gated on demonstrated demand (👍 / concrete user asks) given the fork limitation and ecosystem overlap.
    3. If pursued, Tier 2 before Tier 3 — it's the differentiated piece (authoritative annotations as a status check). Requirements up front: document the fork read-only-token limitation + permissions: block, model the client on AzureDevOpsTestResultsClient, add the GITHUBREPORTER_TOKEN fallback for non-GHA hosts (Jenkins-against-GitHub), and batch annotations at 50/request.
    4. Housekeeping regardless: (a) the shipped CLI names are --report-gh-*, not the RFC's --report-github-* — reconcile docs; (b) note that file:line comes from the exception stack trace, not TestFileLocationProperty, so cross-framework (xUnit/NUnit/TUnit) behavior should be verified and documented; (c) confirm PACKAGE.md documents the CLI surface (permissions only become relevant if the token tiers ever ship).

    TL;DR: the practical value shipped. I'd close this RFC as "Tier 1 done" and let the token tiers be pulled by real user demand rather than pushed.

    🤖 Reviewed against the current codebase with the assistance of GitHub Copilot CLI.

  2. Evangelink commented on Jul 13, 2026

    @Evangelink
    MemberAuthor

    Correction on the CLI naming point

    Follow-up to housekeeping item (a) in my previous comment — I want to reverse it. The shipped --report-gh-* naming is correct; it's the RFC's proposed --report-github-* that's out of step with the established convention.

    The AzDO sibling sets the precedent, and it deliberately splits the two surfaces:

    Surface AzDO extension GitHub extension Convention
    Package / namespace / types AzureDevOps* (spelled out) GitHubActions* (spelled out) full name
    CLI options --report-azdo, --report-azdo-* --report-gh, --report-gh-* short handle

    The CLI token is intentionally the short informal handle, not the product's full name: AzDO abbreviates azure-devops -> azdo, so GitHub abbreviating github -> gh is the exact analogue. gh is also the name of the official GitHub CLI, so it's the idiomatic short form users already recognize — not an invented contraction. Spelling it out as --report-github-* would actually be the inconsistent choice.

    So: no code change needed — --report-gh-* stays. The only thing to reconcile is the RFC text, which should be updated from --report-github-* to --report-gh-*.

    🤖 Reviewed with the assistance of GitHub Copilot CLI.

  3. Ramstad commented on Jul 15, 2026

    @Ramstad

    I just tested this and it works really nice!

    Could this also include the totals across assemblies output when running dotnet test? This one:

      total: 2935
      failed: 1
      succeeded: 2929
      skipped: 5
      duration: 3m 26s 221ms
    
  4. Evangelink commented on Jul 15, 2026

    @Evangelink
    MemberAuthor

    Thanks for testing out the extension Stian Ramstad (@Ramstad)! We will look at improving it for multi-asm behavior (dotnet test).

  5. Ramstad commented on Jul 15, 2026

    @Ramstad

    Another suggestion.
    It would be nice if it could output some indication of failure when options like --minimum-expected-tests cause failure.
    Like general handling of the different MTP known exit codes scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/rfc

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions