diff --git a/.github/workflows/danger-comment.yml b/.github/workflows/danger-comment.yml index e6759f7..64ece3e 100644 --- a/.github/workflows/danger-comment.yml +++ b/.github/workflows/danger-comment.yml @@ -3,33 +3,9 @@ on: workflow_run: workflows: [Danger] types: [completed] - -permissions: - actions: read - contents: read - issues: write - pull-requests: write + workflow_call: jobs: comment: - runs-on: ubuntu-latest - if: github.event.workflow_run.event == 'pull_request' - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - name: Download Danger Report - uses: actions/download-artifact@v4 - continue-on-error: true - with: - name: danger-report - run-id: ${{ github.event.workflow_run.id }} - repository: ${{ github.event.workflow_run.repository.full_name }} - github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Post or Update PR Comment - uses: actions/github-script@v7 - with: - 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 + secrets: inherit diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml index a062f28..e85bf57 100644 --- a/.github/workflows/danger.yml +++ b/.github/workflows/danger.yml @@ -2,31 +2,9 @@ name: Danger on: pull_request: types: [ opened, reopened, edited, synchronize ] + workflow_call: + jobs: danger: - name: Danger - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.7 - bundler-cache: true - - name: Run Danger - # Note: We use 'dry_run' mode intentionally as part of a two-workflow pattern. - # The actual commenting on GitHub is handled by the danger-comment.yml workflow. - run: bundle exec danger dry_run --verbose - env: - DANGER_REPORT_PATH: danger_report.json - - name: Upload Danger Report - if: always() - uses: actions/upload-artifact@v4 - with: - name: danger-report - path: danger_report.json - retention-days: 1 - if-no-files-found: ignore + uses: ruby-grape/danger/.github/workflows/danger-run.yml@report-workflows + secrets: inherit diff --git a/Dangerfile b/Dangerfile index 8f8a2ab..5be30d2 100644 --- a/Dangerfile +++ b/Dangerfile @@ -1,30 +1,6 @@ # danger.systems -toc.check! -changelog.check! - -# Export report for danger-comment workflow -require 'json' -event_path = ENV.fetch('GITHUB_EVENT_PATH', nil) -report_path = ENV.fetch('DANGER_REPORT_PATH', nil) -if report_path && event_path && File.exist?(event_path) - event = JSON.parse(File.read(event_path)) - pr_number = event.dig('pull_request', 'number') - if pr_number - to_messages = lambda do |items| - Array(items).map do |item| - item.respond_to?(:message) ? item.message : item.to_s - end - end +# Import ruby-grape-danger for automatic danger report export +danger.import_dangerfile(gem: 'ruby-grape-danger') - report = { - pr_number: pr_number, - errors: to_messages.call(status_report[:errors]), - warnings: to_messages.call(status_report[:warnings]), - messages: to_messages.call(status_report[:messages]), - markdowns: to_messages.call(status_report[:markdowns]) - } - - File.write(report_path, JSON.pretty_generate(report)) - end -end +changelog.check! diff --git a/Gemfile b/Gemfile index ac70f32..95faab4 100644 --- a/Gemfile +++ b/Gemfile @@ -15,5 +15,6 @@ group :development, :test do gem 'rubocop', '~> 1.63.1' gem 'rubocop-rake' gem 'rubocop-rspec' + gem 'ruby-grape-danger' gem 'yard', '~> 0.9.11' end diff --git a/README.md b/README.md index d7ea0fb..bf34674 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ changelog.filename = 'CHANGES.md' ### changelog.format -Set the format of the CHANGELOG file. +Set the format of the CHANGELOG file. ```ruby changelog.format = :keep_a_changelog