Skip to content

Commit 3b5202e

Browse files
authored
Init RubyCritic configuration (#595)
2 parents 256be11 + 5217cae commit 3b5202e

File tree

4 files changed

+211
-0
lines changed

4 files changed

+211
-0
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,12 @@ jobs:
8383
- name: Run tests
8484
run: bundle exec rspec
8585

86+
- name: Upload coverage artifact
87+
uses: actions/upload-artifact@v4
88+
with:
89+
name: coverage
90+
path: coverage/
91+
retention-days: 7
92+
8693
- name: Change owner of container working directory
8794
run: chown root:root .

.github/workflows/rubycritic.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: RubyCritic
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI RSpec Tests"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
rubycritic:
11+
name: RubyCritic
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
actions: read
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
ref: ${{ github.event.workflow_run.head_sha }}
23+
24+
- name: Download coverage artifact
25+
uses: actions/download-artifact@v4
26+
with:
27+
name: coverage
28+
path: tmp/coverage
29+
run-id: ${{ github.event.workflow_run.id }}
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Set up Ruby
33+
uses: ruby/setup-ruby@v1
34+
with:
35+
ruby-version: 3.3.4
36+
bundler-cache: true
37+
38+
- name: Get PR number
39+
id: pr
40+
run: |
41+
if [ "${{ github.event.workflow_run.event }}" = "pull_request" ]; then
42+
PR_NUMBER=$(gh pr list --head "${{ github.event.workflow_run.head_branch }}" --json number --jq '.[0].number')
43+
echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT
44+
echo "is_pr=true" >> $GITHUB_OUTPUT
45+
else
46+
echo "number=${{ github.event.workflow_run.run_number }}" >> $GITHUB_OUTPUT
47+
echo "is_pr=false" >> $GITHUB_OUTPUT
48+
fi
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Run RubyCritic on changed files
53+
run: |
54+
mkdir -p tmp/rubycritic/pr-${{ steps.pr.outputs.number }}
55+
files=$(git diff --name-only origin/development...HEAD -- '*.rb' | xargs)
56+
if [ -n "$files" ]; then
57+
bundle exec rubycritic --no-browser --format html --path tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/changed $files
58+
else
59+
mkdir -p tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/changed
60+
echo "No Ruby files changed" > tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/changed/index.html
61+
fi
62+
63+
- name: Run RubyCritic on full codebase
64+
run: |
65+
bundle exec rubycritic --no-browser --format html --path tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/full app lib
66+
67+
- name: Copy coverage report
68+
run: |
69+
cp -r tmp/coverage tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/coverage
70+
71+
- name: Create index page
72+
run: |
73+
cat > tmp/rubycritic/pr-${{ steps.pr.outputs.number }}/index.html << EOF
74+
<!DOCTYPE html>
75+
<html>
76+
<head><title>Code Quality Reports - PR #${{ steps.pr.outputs.number }}</title></head>
77+
<body>
78+
<h1>Code Quality Reports - PR #${{ steps.pr.outputs.number }}</h1>
79+
<ul>
80+
<li><a href="coverage/index.html">Code Coverage Report</a></li>
81+
<li><a href="changed/overview.html">RubyCritic - Changed Files</a></li>
82+
<li><a href="full/overview.html">RubyCritic - Full Codebase</a></li>
83+
</ul>
84+
</body>
85+
</html>
86+
EOF
87+
88+
- name: Deploy to GitHub Pages
89+
uses: peaceiris/actions-gh-pages@v4
90+
with:
91+
github_token: ${{ secrets.GITHUB_TOKEN }}
92+
publish_dir: tmp/rubycritic
93+
destination_dir: rubycritic
94+
keep_files: true
95+
96+
- name: Comment PR with report links
97+
if: ${{ steps.pr.outputs.is_pr == 'true' }}
98+
uses: actions/github-script@v7
99+
with:
100+
script: |
101+
const prNumber = ${{ steps.pr.outputs.number }};
102+
const repoOwner = context.repo.owner;
103+
const repoName = context.repo.repo;
104+
const baseUrl = `https://${repoOwner}.github.io/${repoName}/rubycritic/pr-${prNumber}`;
105+
106+
const body = `## Code Quality Reports
107+
108+
| Report | Link |
109+
|--------|------|
110+
| Code Coverage | [View Report](${baseUrl}/coverage/index.html) |
111+
| RubyCritic - Changed Files | [View Report](${baseUrl}/changed/overview.html) |
112+
| RubyCritic - Full Codebase | [View Report](${baseUrl}/full/overview.html) |
113+
`;
114+
115+
github.rest.issues.createComment({
116+
owner: repoOwner,
117+
repo: repoName,
118+
issue_number: prNumber,
119+
body: body
120+
});

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ group :development, :test do
9191
gem 'faker'
9292
gem 'rspec-rails', '7.1.0'
9393
gem 'rubocop', require: false
94+
gem 'rubycritic', require: false
9495
gem 'ruby-lsp'
9596
end
9697

Gemfile.lock

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ GEM
126126
aws-sigv4 (~> 1.5)
127127
aws-sigv4 (1.9.1)
128128
aws-eventstream (~> 1, >= 1.0.2)
129+
axiom-types (0.1.1)
130+
descendants_tracker (~> 0.0.4)
131+
ice_nine (~> 0.11.0)
132+
thread_safe (~> 0.3, >= 0.3.1)
129133
base64 (0.2.0)
130134
bcrypt (3.1.20)
131135
benchmark (0.4.0)
@@ -152,7 +156,11 @@ GEM
152156
rack-test (>= 0.6.3)
153157
regexp_parser (>= 1.5, < 3.0)
154158
xpath (~> 3.2)
159+
childprocess (5.1.0)
160+
logger (~> 1.5)
155161
cocoon (1.2.15)
162+
coercible (1.0.0)
163+
descendants_tracker (~> 0.0.1)
156164
concurrent-ruby (1.3.4)
157165
connection_pool (2.4.1)
158166
crack (1.0.0)
@@ -165,6 +173,8 @@ GEM
165173
irb (~> 1.10)
166174
reline (>= 0.3.8)
167175
declarative (0.0.20)
176+
descendants_tracker (0.0.4)
177+
thread_safe (~> 0.3, >= 0.3.1)
168178
devise (4.9.4)
169179
bcrypt (~> 3.0)
170180
orm_adapter (~> 0.1)
@@ -184,6 +194,35 @@ GEM
184194
addressable (~> 2.8)
185195
drb (2.2.1)
186196
dry-cli (1.4.0)
197+
dry-configurable (1.3.0)
198+
dry-core (~> 1.1)
199+
zeitwerk (~> 2.6)
200+
dry-core (1.2.0)
201+
concurrent-ruby (~> 1.0)
202+
logger
203+
zeitwerk (~> 2.6)
204+
dry-inflector (1.3.1)
205+
dry-initializer (3.2.0)
206+
dry-logic (1.6.0)
207+
bigdecimal
208+
concurrent-ruby (~> 1.0)
209+
dry-core (~> 1.1)
210+
zeitwerk (~> 2.6)
211+
dry-schema (1.15.0)
212+
concurrent-ruby (~> 1.0)
213+
dry-configurable (~> 1.0, >= 1.0.1)
214+
dry-core (~> 1.1)
215+
dry-initializer (~> 3.2)
216+
dry-logic (~> 1.6)
217+
dry-types (~> 1.8)
218+
zeitwerk (~> 2.6)
219+
dry-types (1.9.1)
220+
bigdecimal (>= 3.0)
221+
concurrent-ruby (~> 1.0)
222+
dry-core (~> 1.0)
223+
dry-inflector (~> 1.0)
224+
dry-logic (~> 1.4)
225+
zeitwerk (~> 2.6)
187226
elastic-apm (4.7.3)
188227
concurrent-ruby (~> 1.0)
189228
http (>= 3.0)
@@ -221,6 +260,15 @@ GEM
221260
ffi-compiler (1.3.2)
222261
ffi (>= 1.15.5)
223262
rake
263+
flay (2.13.3)
264+
erubi (~> 1.10)
265+
path_expander (~> 1.0)
266+
ruby_parser (~> 3.0)
267+
sexp_processor (~> 4.0)
268+
flog (4.8.0)
269+
path_expander (~> 1.0)
270+
ruby_parser (~> 3.1, > 3.1.0)
271+
sexp_processor (~> 4.8)
224272
fugit (1.11.1)
225273
et-orbi (~> 1, >= 1.2.11)
226274
raabro (~> 1.4)
@@ -297,6 +345,7 @@ GEM
297345
httpclient (2.8.3)
298346
i18n (1.14.6)
299347
concurrent-ruby (~> 1.0)
348+
ice_nine (0.11.2)
300349
image_processing (1.13.0)
301350
mini_magick (>= 4.9.5, < 5)
302351
ruby-vips (>= 2.0.17, < 3)
@@ -317,6 +366,10 @@ GEM
317366
june-analytics-ruby (2.4.3)
318367
jwt (2.2.3)
319368
language_server-protocol (3.17.0.3)
369+
launchy (3.1.1)
370+
addressable (~> 2.8)
371+
childprocess (~> 5.0)
372+
logger (~> 1.6)
320373
listen (3.9.0)
321374
rb-fsevent (~> 0.10, >= 0.10.3)
322375
rb-inotify (~> 0.9, >= 0.9.10)
@@ -563,6 +616,7 @@ GEM
563616
parser (3.3.4.0)
564617
ast (~> 2.4.1)
565618
racc
619+
path_expander (1.1.3)
566620
pg (1.5.7)
567621
pgvector (0.2.2)
568622
prism (0.30.0)
@@ -635,6 +689,12 @@ GEM
635689
redis (4.8.1)
636690
redis-client (0.22.2)
637691
connection_pool
692+
reek (6.5.0)
693+
dry-schema (~> 1.13)
694+
logger (~> 1.6)
695+
parser (~> 3.3.0)
696+
rainbow (>= 2.0, < 4.0)
697+
rexml (~> 3.1)
638698
regexp_parser (2.9.2)
639699
reline (0.6.0)
640700
io-console (~> 0.5)
@@ -691,6 +751,21 @@ GEM
691751
ffi (~> 1.12)
692752
logger
693753
ruby2_keywords (0.0.5)
754+
ruby_parser (3.22.0)
755+
racc (~> 1.5)
756+
sexp_processor (~> 4.16)
757+
rubycritic (4.11.0)
758+
flay (~> 2.13)
759+
flog (~> 4.7)
760+
launchy (>= 2.5.2)
761+
parser (>= 3.3.0.5)
762+
rainbow (~> 3.1.1)
763+
reek (~> 6.5.0, < 7.0)
764+
rexml
765+
ruby_parser (~> 3.21)
766+
simplecov (>= 0.22.0)
767+
tty-which (~> 0.5.0)
768+
virtus (~> 2.0)
694769
rubyzip (2.3.2)
695770
sass-rails (6.0.0)
696771
sassc-rails (~> 2.1, >= 2.1.1)
@@ -718,6 +793,7 @@ GEM
718793
sentry-sidekiq (5.18.2)
719794
sentry-ruby (~> 5.18.2)
720795
sidekiq (>= 3.0)
796+
sexp_processor (4.17.5)
721797
sidekiq (7.3.0)
722798
concurrent-ruby (< 2)
723799
connection_pool (>= 2.3.0)
@@ -754,9 +830,11 @@ GEM
754830
railties (>= 6.0.0)
755831
text_splitters (1.0.0)
756832
thor (1.3.2)
833+
thread_safe (0.3.6)
757834
tilt (2.4.0)
758835
timeout (0.4.3)
759836
trailblazer-option (0.1.2)
837+
tty-which (0.5.0)
760838
turbo-rails (2.0.11)
761839
actionpack (>= 6.0.0)
762840
railties (>= 6.0.0)
@@ -766,6 +844,10 @@ GEM
766844
unicode-display_width (2.5.0)
767845
uri (1.0.3)
768846
vcr (6.2.0)
847+
virtus (2.0.0)
848+
axiom-types (~> 0.1)
849+
coercible (~> 1.0)
850+
descendants_tracker (~> 0.0, >= 0.0.3)
769851
vite_rails (3.0.20)
770852
railties (>= 5.1, < 9)
771853
vite_ruby (~> 3.0, >= 3.2.2)
@@ -866,6 +948,7 @@ DEPENDENCIES
866948
rspec-rails (= 7.1.0)
867949
rubocop
868950
ruby-lsp
951+
rubycritic
869952
sass-rails (>= 6)
870953
selenium-webdriver
871954
sentry-rails

0 commit comments

Comments
 (0)