Skip to content

Commit d2c8786

Browse files
committed
Remove API token requirement from Danger workflow
Switch to tokenless execution using with GitHub Actions annotations for inline feedback. This eliminates the need for the grape-bot token while still providing PR feedback via workflow annotations. Changes: - Use commit SHAs instead of branch refs for reliable diff calculation - Output violations as GitHub Actions annotations (errors, warnings, notices) - Update to actions/checkout@v6 with full history fetch
1 parent d4244ab commit d2c8786

File tree

2 files changed

+62
-7
lines changed

2 files changed

+62
-7
lines changed

.github/workflows/danger.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ jobs:
66
danger:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v4
9+
- uses: actions/checkout@v6
1010
with:
11-
fetch-depth: 100
11+
fetch-depth: 0
1212
- name: Set up Ruby
1313
uses: ruby/setup-ruby@v1
1414
with:
1515
ruby-version: 3.4
1616
bundler-cache: true
1717
- name: Run Danger
18-
run: |
19-
# the token is public, has public_repo scope and belongs to the grape-bot user owned by @dblock, this is ok
20-
TOKEN=$(echo -n Z2hwX2lYb0dPNXNyejYzOFJyaTV3QUxUdkNiS1dtblFwZTFuRXpmMwo= | base64 --decode)
21-
DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose
18+
env:
19+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
20+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
21+
run: bundle exec danger dry_run --base=$BASE_SHA --head=$HEAD_SHA --verbose

Dangerfile

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
11
# frozen_string_literal: true
22

3-
danger.import_dangerfile(gem: 'ruby-grape-danger')
3+
# Inline checks from ruby-grape-danger (avoids plugins requiring GitHub API token)
4+
5+
has_app_changes = !git.modified_files.grep(/lib/).empty?
6+
has_spec_changes = !git.modified_files.grep(/spec/).empty?
7+
8+
if has_app_changes && !has_spec_changes
9+
warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false)
10+
end
11+
12+
if !has_app_changes && has_spec_changes
13+
message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false)
14+
end
15+
16+
# Simplified changelog check (replaces danger-changelog plugin which requires github.* methods)
17+
# Note: toc.check! from danger-toc plugin removed (not essential for CI)
18+
has_changelog_changes = git.modified_files.include?('CHANGELOG.md') || git.added_files.include?('CHANGELOG.md')
19+
if has_app_changes && !has_changelog_changes
20+
warn('Please update CHANGELOG.md with a description of your changes.', sticky: false)
21+
end
22+
23+
(git.modified_files + git.added_files - %w[Dangerfile]).each do |file|
24+
next unless File.file?(file)
25+
26+
contents = File.read(file)
27+
if file.start_with?('spec')
28+
fail("`xit` or `fit` left in tests (#{file})") if contents =~ /^\w*[xf]it/
29+
fail("`fdescribe` left in tests (#{file})") if contents =~ /^\w*fdescribe/
30+
end
31+
end
32+
33+
# Output as GitHub Actions annotations (since we can't post PR comments without token)
34+
if ENV['GITHUB_ACTIONS']
35+
violation_report[:errors].each do |v|
36+
if v.file && v.line
37+
puts "::error file=#{v.file},line=#{v.line}::#{v.message}"
38+
else
39+
puts "::error::#{v.message}"
40+
end
41+
end
42+
43+
violation_report[:warnings].each do |v|
44+
if v.file && v.line
45+
puts "::warning file=#{v.file},line=#{v.line}::#{v.message}"
46+
else
47+
puts "::warning::#{v.message}"
48+
end
49+
end
50+
51+
violation_report[:messages].each do |v|
52+
if v.file && v.line
53+
puts "::notice file=#{v.file},line=#{v.line}::#{v.message}"
54+
else
55+
puts "::notice::#{v.message}"
56+
end
57+
end
58+
end

0 commit comments

Comments
 (0)