[FEATURE] Allow conventions to append additional information to job summary
This PR implements the ability for conventions to contribute custom content to PSRule job summaries, providing extensibility for the generated output.
Changes Made
Core Implementation
-
Added
IJobSummaryContributorinterface: Allows conventions to provide custom content sections -
Added
JobSummarySectionclass: Represents custom sections with title and markdown content -
Enhanced
JobSummaryWriter: Now collects and displays convention contributions in job summaries -
Updated
AssertPipelineBuilder: Passes convention contributors toJobSummaryWriterduring pipeline construction
Key Features
- Backward compatible: Existing conventions and job summaries continue to work unchanged
- Extensible: Conventions can add multiple sections with custom titles and markdown content
- Error resilient: Exceptions from individual conventions don't break the entire job summary
- Flexible content: Supports any markdown content including tables, lists, links, code blocks, etc.
Usage Example
Conventions can implement the IJobSummaryContributor interface to add custom sections:
public class MyConvention : BaseConvention, IConventionV1, IJobSummaryContributor
{
public IEnumerable<JobSummarySection>? GetJobSummaryContent()
{
return new[]
{
new JobSummarySection("Custom Metrics", "- Processed: 100 items\n- Success rate: 95%"),
new JobSummarySection("Environment Info", "- Runtime: .NET 8.0\n- OS: Linux")
};
}
// ... other convention implementation
}
The job summary will include additional sections after the standard PSRule content:
# PSRule result summary
❌ PSRule completed with an overall result of 'Fail' with 10 rule(s) and 5 target(s) in 00:00:02.123.
## Analysis
...
## Custom Metrics
- Processed: 100 items
- Success rate: 95%
## Environment Info
- Runtime: .NET 8.0
- OS: Linux
Testing
- Added comprehensive unit tests covering normal operation, empty contributors, and error scenarios
- All existing tests continue to pass, ensuring backward compatibility
- Created example convention demonstrating the feature
This implementation provides the requested extensibility for job summaries while maintaining all existing functionality and following PSRule's architectural patterns.
Fixes #2667.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
Allow registering conventions by using the
IRuntimeServiceCollectioninterface. Similar toAddServiceadd a method forAddConvention.
Added AddConvention<TConvention>() method to IRuntimeServiceCollection interface, similar to AddService. This allows conventions to be registered using the same service collection pattern. Also added GetConventions() method to ILanguageScope to retrieve registered conventions. Changes made in 59894e8.