Skip to content

Commit 4ccc62a

Browse files
committed
Use PR comments instead of GitHub annotations
1 parent 75943eb commit 4ccc62a

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

.github/workflows/danger.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,33 @@ jobs:
1515
ruby-version: 3.4
1616
bundler-cache: true
1717
- name: Run Danger
18+
id: danger
1819
env:
1920
BASE_SHA: ${{ github.event.pull_request.base.sha }}
2021
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
21-
run: bundle exec danger dry_run --base=$BASE_SHA --head=$HEAD_SHA --verbose
22+
DANGER_REPORT_PATH: danger_report.md
23+
run: |
24+
bundle exec danger dry_run --base=$BASE_SHA --head=$HEAD_SHA --verbose
25+
# Check if report contains errors
26+
if grep -q "### Errors" danger_report.md 2>/dev/null; then
27+
echo "has_errors=true" >> $GITHUB_OUTPUT
28+
fi
29+
- name: Find existing comment
30+
if: always()
31+
uses: peter-evans/find-comment@v3
32+
id: find-comment
33+
with:
34+
issue-number: ${{ github.event.pull_request.number }}
35+
comment-author: 'github-actions[bot]'
36+
body-includes: '## Danger Report'
37+
- name: Post or update PR comment
38+
if: always()
39+
uses: peter-evans/create-or-update-comment@v4
40+
with:
41+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
42+
issue-number: ${{ github.event.pull_request.number }}
43+
body-path: danger_report.md
44+
edit-mode: replace
45+
- name: Fail if errors found
46+
if: steps.danger.outputs.has_errors == 'true'
47+
run: exit 1

Dangerfile

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,33 @@ end
3030
end
3131
end
3232

33-
# Output as GitHub Actions annotations (since we can't post PR comments without token)
34-
# Using print instead of puts to avoid Danger's "You used puts" warning
35-
if ENV['GITHUB_ACTIONS']
36-
violation_report[:errors].each do |v|
37-
if v.file && v.line
38-
print "::error file=#{v.file},line=#{v.line}::#{v.message}\n"
39-
else
40-
print "::error::#{v.message}\n"
41-
end
33+
# Output markdown report for GitHub Actions to post as PR comment
34+
if ENV['DANGER_REPORT_PATH']
35+
report = []
36+
report << '## Danger Report'
37+
report << ''
38+
39+
if violation_report[:errors].any?
40+
report << '### Errors'
41+
violation_report[:errors].each { |v| report << "- :no_entry_sign: #{v.message}" }
42+
report << ''
4243
end
4344

44-
violation_report[:warnings].each do |v|
45-
if v.file && v.line
46-
print "::warning file=#{v.file},line=#{v.line}::#{v.message}\n"
47-
else
48-
print "::warning::#{v.message}\n"
49-
end
45+
if violation_report[:warnings].any?
46+
report << '### Warnings'
47+
violation_report[:warnings].each { |v| report << "- :warning: #{v.message}" }
48+
report << ''
5049
end
5150

52-
violation_report[:messages].each do |v|
53-
if v.file && v.line
54-
print "::notice file=#{v.file},line=#{v.line}::#{v.message}\n"
55-
else
56-
print "::notice::#{v.message}\n"
57-
end
51+
if violation_report[:messages].any?
52+
report << '### Messages'
53+
violation_report[:messages].each { |v| report << "- :book: #{v.message}" }
54+
report << ''
5855
end
5956

60-
# Debug: show counts
61-
total = violation_report[:errors].count + violation_report[:warnings].count + violation_report[:messages].count
62-
print "::notice::Danger completed: #{violation_report[:errors].count} errors, #{violation_report[:warnings].count} warnings, #{violation_report[:messages].count} messages\n"
57+
if violation_report[:errors].empty? && violation_report[:warnings].empty? && violation_report[:messages].empty?
58+
report << ':white_check_mark: All checks passed!'
59+
end
60+
61+
File.write(ENV['DANGER_REPORT_PATH'], report.join("\n"))
6362
end

0 commit comments

Comments
 (0)