You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extract danger reporting infrastructure into reusable workflows and gem
Moves reporting responsibility from consuming gems into ruby-grape-danger,
establishing it as the authoritative Danger integration framework for Grape
projects.
Key changes:
- Add RubyGrapeDanger::Reporter class for consistent danger report generation
- Implement automatic reporting via at_exit hook in gem's Dangerfile
- Add reusable GitHub Actions workflows (danger-run.yml, danger-comment.yml)
with embedded script for posting/updating PR comments
- Consuming gems now just import ruby-grape-danger and add their checks
Benefits:
✅ DRY: Workflows defined once, reused by all projects
✅ Consistent: All projects use same reporting format and behavior
✅ Maintainable: Fix bugs in workflows once, all projects benefit
✅ Scalable: New danger checks automatically get reporting infrastructure
✅ Simple API: Projects only need `danger.import_dangerfile(gem: 'ruby-grape-danger')`
Example usage:
danger.import_dangerfile(gem: 'ruby-grape-danger')
changelog.check!
# Reporting happens automatically via at_exit hook
Includes comprehensive specs for Reporter class with 13 test cases covering:
- JSON report generation and formatting
- Message type handling (strings, objects with .message method)
- Edge cases (missing files, missing PR number, empty arrays, nil values)
- Multiline content preservation
To test things out, make a dummy entry in `CHANGELOG.md` that doesn't match the standard format and make a pull request. Iterate until green.
40
80
81
+
## Reusable Workflows
82
+
83
+
This gem provides **reusable GitHub Actions workflows** that can be referenced by any Grape project to implement standardized Danger checks with consistent reporting.
84
+
85
+
### Architecture
86
+
87
+
The workflows are separated into two stages:
88
+
89
+
1. **danger-run.yml**: Executes Danger checks and generates a report
90
+
- Runs `bundle exec danger dry_run` with your project's Dangerfile
91
+
- Generates a JSON report of check results
92
+
- Uploads the report as an artifact
93
+
94
+
2. **danger-comment.yml**: Posts/updates PR comments with results
95
+
- Downloads the Danger report artifact
96
+
- Formats and posts results as a PR comment
97
+
- Updates existing comment on subsequent runs
98
+
99
+
### Benefits of Reusable Workflows
100
+
101
+
✅ **DRY**: Define workflows once in `ruby-grape-danger`, reuse everywhere
102
+
✅ **Consistent**: All Grape projects use the same reporting format and behavior
103
+
✅ **Maintainable**: Fix a bug in the workflows once, all projects benefit automatically
104
+
✅ **Scalable**: Add new checks to any project's Dangerfile without touching workflows
1. Checks out **your project's repository** (not ruby-grape-danger)
116
+
2. Installs dependencies from **your Gemfile**
117
+
3. Runs danger using **your Dangerfile**
118
+
- Your Dangerfile imports `ruby-grape-danger`'s Dangerfile via `danger.import_dangerfile(gem: 'ruby-grape-danger')`
119
+
- The imported Dangerfile registers an `at_exit` hook for automatic reporting
120
+
- Runs your project-specific checks (added after the import)
121
+
- When Dangerfile finishes, the `at_exit` hook automatically exports the report
122
+
4. The report is uploaded as an artifact for the commenting workflow
123
+
124
+
Each project maintains its own Dangerfile with project-specific checks, while the `ruby-grape-danger` gem provides shared infrastructure for consistent reporting and workflow execution.
125
+
126
+
### Examples
127
+
128
+
- [danger-changelog](https://github.com/ruby-grape/danger-changelog) - Validates CHANGELOG format
0 commit comments