Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/danger-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ jobs:
}

// Fail if there are errors
if (report.errors && report.errors.length > 0) {
if (hasItems(report.errors)) {
core.setFailed('Danger found errors');
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 0.2.2 (Next)

* Your contribution here.
* [#16](https://github.com/ruby-grape/danger/pull/16): Report workflow postreview fixes - [@numbata](https://github.com/numbata).
* [#15](https://github.com/ruby-grape/danger/pull/15): Extract danger reporting infrastructure into reusable workflows and gem - [@numbata](https://github.com/numbata).

### 0.2.1 (2024/02/01)
Expand Down
16 changes: 7 additions & 9 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ require 'English'
# to get automatic reporting with their own custom checks.

# Register at_exit hook to export report when Dangerfile finishes
dangerfile_instance = self if defined?(Danger::Dangerfile) && is_a?(Danger::Dangerfile)
at_exit do
# Only skip if there's an actual exception (not SystemExit from danger calling exit)
next if $ERROR_INFO && !$ERROR_INFO.is_a?(SystemExit)
next unless dangerfile_instance

# Find the Dangerfile instance and get its current status_report
ObjectSpace.each_object(Danger::Dangerfile) do |df|
reporter = RubyGrapeDanger::Reporter.new(df.status_report)
reporter.export_json(
ENV.fetch('DANGER_REPORT_PATH', nil),
ENV.fetch('GITHUB_EVENT_PATH', nil)
)
break
end
reporter = RubyGrapeDanger::Reporter.new(dangerfile_instance.status_report)
reporter.export_json(
ENV.fetch('DANGER_REPORT_PATH', nil),
ENV.fetch('GITHUB_EVENT_PATH', nil)
)
end

# --------------------------------------------------------------------------------------------------------------------
Expand Down
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- [Commit via a Pull Request](#commit-via-a-pull-request)
- [Reusable Workflows](#reusable-workflows)
- [Architecture](#architecture)
- [Benefits of Reusable Workflows](#benefits-of-reusable-workflows)
- [How It Works](#how-it-works)
- [Examples](#examples)
- [License](#license)
Expand Down Expand Up @@ -60,7 +59,7 @@ on:

jobs:
danger:
uses: ruby-grape/ruby-grape-danger/.github/workflows/danger-run.yml@main
uses: ruby-grape/danger/.github/workflows/danger-run.yml@main
```

Create `.github/workflows/danger-comment.yml`:
Expand All @@ -75,7 +74,7 @@ on:

jobs:
comment:
uses: ruby-grape/ruby-grape-danger/.github/workflows/danger-comment.yml@main
uses: ruby-grape/danger/.github/workflows/danger-comment.yml@main
```

### Commit via a Pull Request
Expand All @@ -100,19 +99,12 @@ The workflows are separated into two stages:
- Formats and posts results as a PR comment
- Updates existing comment on subsequent runs

### Benefits of Reusable Workflows

✅ **DRY**: Define workflows once in `ruby-grape-danger`, reuse everywhere
✅ **Consistent**: All Grape projects use the same reporting format and behavior
✅ **Maintainable**: Fix a bug in the workflows once, all projects benefit automatically
✅ **Scalable**: Add new checks to any project's Dangerfile without touching workflows

### How It Works

When you reference the reusable workflows:

```yaml
uses: ruby-grape/ruby-grape-danger/.github/workflows/danger-run.yml@main
uses: ruby-grape/danger/.github/workflows/danger-run.yml@main
```

GitHub Actions:
Expand Down
2 changes: 1 addition & 1 deletion ruby-grape-danger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
s.add_runtime_dependency 'danger', '~> 9'
s.add_runtime_dependency 'danger-changelog', '~> 0.7'
s.add_runtime_dependency 'danger-changelog', '~> 0.8'
s.add_runtime_dependency 'danger-toc', '~> 0.2'
end