Skip to content

Migrate to reusable danger workflows from ruby-grape-danger#69

Merged
dblock merged 9 commits intodblock:masterfrom
numbata:reusable-workflows
Dec 17, 2025
Merged

Migrate to reusable danger workflows from ruby-grape-danger#69
dblock merged 9 commits intodblock:masterfrom
numbata:reusable-workflows

Conversation

@numbata
Copy link
Copy Markdown
Collaborator

@numbata numbata commented Dec 17, 2025

Summary

Migrate danger-changelog to use the new reusable danger workflows and reporting infrastructure from ruby-grape-danger gem. This refactoring eliminates duplicate workflow code and consolidates danger integration logic into the ruby-grape-danger gem, following the DRY principle.

Changes

  • Workflows: Replace custom danger.yml and danger-comment.yml with calls to reusable workflows from ruby-grape-danger

    • danger-run.yml: Executes danger checks and exports report
    • danger-comment.yml: Posts/updates PR comment with results
  • Dangerfile: Simplify by importing ruby-grape-danger gem

    • Remove report export logic (now handled by ruby-grape-danger Dangerfile)
    • Remove duplicate helper functions
    • Focus on project-specific checks only (changelog.check!)
  • Dependencies: Add ruby-grape-danger gem from report-workflows branch (for testing)

  • Documentation: Align README with simplified workflow pattern

Benefits

  • DRY: One source of truth for danger reporting infrastructure
  • Consistent: All Grape projects use the same workflow patterns
  • Maintainable: Bug fixes in workflows benefit all projects
  • Scalable: Easy to add new checks without touching workflows

Simplify danger-changelog by removing responsibility for reporting and
workflow orchestration, delegating these to ruby-grape-danger as the
shared Danger integration framework.

Changes:
  - Simplify Dangerfile to import ruby-grape-danger and run checks
  - Replace local workflows with references to ruby-grape-danger reusable workflows
  - Reference workflows from numbata/ruby-grape-danger@report-workflows (testing branch)
  - Add secrets: inherit to workflow calls for proper secret passing
  - Remove duplicate reporting logic (now handled by imported Dangerfile)
  - Remove "Reusing the GitHub workflows" section from README
  - Update README to clarify danger-changelog's role (CHANGELOG validation only)

The Dangerfile is now just 6 lines:
  danger.import_dangerfile(gem: 'ruby-grape-danger')
  toc.check!
  changelog.check!

Workflows are now thin wrappers with proper secret handling:
  - danger.yml: uses ruby-grape/danger/.github/workflows/danger-run.yml@report-workflows
  - danger-comment.yml: uses ruby-grape/danger/.github/workflows/danger-comment.yml@report-workflows

Benefits:
  - Reduced duplication (52 lines removed)
  - Single source of truth for danger workflows
  - Automatic reporting when ruby-grape-danger is required
  - Easier to maintain and evolve
  - Clear separation of concerns
@numbata
Copy link
Copy Markdown
Collaborator Author

numbata commented Dec 17, 2025

Blocked by ruby-grape/danger#15

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the danger integration by migrating from custom workflow implementations to reusable workflows provided by the ruby-grape-danger gem. The change eliminates ~60 lines of duplicated workflow code and simplifies the Dangerfile by delegating report export logic to the shared gem, following the DRY principle and establishing consistency across Grape projects.

Key Changes:

  • Replace custom GitHub Actions workflows with reusable workflow calls to ruby-grape/danger repository
  • Simplify Dangerfile to import ruby-grape-danger gem and focus only on project-specific checks (changelog.check!)
  • Add ruby-grape-danger as a dependency and remove toc.check! validation

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
.github/workflows/danger.yml Replaced 30-line custom workflow with 2-line reusable workflow call
.github/workflows/danger-comment.yml Replaced 30-line custom workflow with 2-line reusable workflow call
Dangerfile Simplified from 30 lines to 6 lines by importing ruby-grape-danger gem and removing manual report export
Gemfile Added ruby-grape-danger gem dependency
README.md Fixed trailing whitespace (formatting improvement)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

script: |
const script = require('./.github/scripts/post-danger-comment.js');
await script({ github, context, core });
uses: ruby-grape/danger/.github/workflows/danger-comment.yml@report-workflows
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow references a specific branch (@report-workflows) of the reusable workflow. While this is appropriate for testing during development, consider updating this to reference a stable version tag or the main branch once the ruby-grape-danger repository's report-workflows branch is merged and released. Using branch references can lead to unexpected changes if the upstream branch is modified.

Suggested change
uses: ruby-grape/danger/.github/workflows/danger-comment.yml@report-workflows
uses: ruby-grape/danger/.github/workflows/danger-comment.yml@main

Copilot uses AI. Check for mistakes.
@@ -2,31 +2,9 @@ name: Danger
on:
pull_request:
types: [ opened, reopened, edited, synchronize ]
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow_call trigger has been added, but this workflow doesn't appear to be called by any other workflows in the repository based on the PR changes. If this trigger is intended for future use or external calls, consider adding a comment explaining its purpose. Otherwise, it may be unnecessary and could be removed to keep the configuration minimal.

Suggested change
types: [ opened, reopened, edited, synchronize ]
types: [ opened, reopened, edited, synchronize ]
# Expose this workflow so it can be invoked by other workflows via `workflow_call` (current or future use).

Copilot uses AI. Check for mistakes.
contents: read
issues: write
pull-requests: write
workflow_call:
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow_call trigger has been added, but this workflow doesn't appear to be called by any other workflows in the repository based on the PR changes. If this trigger is intended for future use or external calls, consider adding a comment explaining its purpose. Otherwise, it may be unnecessary and could be removed to keep the configuration minimal.

Suggested change
workflow_call:

Copilot uses AI. Check for mistakes.
Comment thread Gemfile
gem 'rubocop', '~> 1.63.1'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'ruby-grape-danger'
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ruby-grape-danger gem is added without a version constraint or Git source specification. According to the PR description, this should reference the report-workflows branch from the ruby-grape-danger gem repository for testing purposes. Without specifying the source, this will attempt to install from rubygems.org where the gem may not exist or may not have the required functionality.

Consider adding a Git source specification, for example:

gem 'ruby-grape-danger', git: 'https://github.com/ruby-grape/danger', branch: 'report-workflows'
Suggested change
gem 'ruby-grape-danger'
gem 'ruby-grape-danger', git: 'https://github.com/ruby-grape/danger', branch: 'report-workflows'

Copilot uses AI. Check for mistakes.
Comment thread Dangerfile
File.write(report_path, JSON.pretty_generate(report))
end
end
changelog.check!
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toc.check! call has been removed from the Dangerfile. Since danger-toc is still a dependency in the Gemfile (line 8), this appears to be an intentional removal of the table of contents check. If this check is no longer needed, consider also removing the danger-toc gem dependency from the Gemfile to keep dependencies clean and reduce the project's dependency footprint.

Suggested change
changelog.check!
changelog.check!
toc.check!

Copilot uses AI. Check for mistakes.
path: danger_report.json
retention-days: 1
if-no-files-found: ignore
uses: ruby-grape/danger/.github/workflows/danger-run.yml@report-workflows
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow references a specific branch (@report-workflows) of the reusable workflow. While this is appropriate for testing during development, consider updating this to reference a stable version tag or the main branch once the ruby-grape-danger repository's report-workflows branch is merged and released. Using branch references can lead to unexpected changes if the upstream branch is modified.

Suggested change
uses: ruby-grape/danger/.github/workflows/danger-run.yml@report-workflows
uses: ruby-grape/danger/.github/workflows/danger-run.yml@main

Copilot uses AI. Check for mistakes.
@dblock dblock merged commit a9a710a into dblock:master Dec 17, 2025
10 checks passed
@dblock
Copy link
Copy Markdown
Owner

dblock commented Dec 17, 2025

@numbata I added you as a maintainer of ruby-grape-danger (GitHub and RubyGems) - make a release and update references to something stable?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants