Skip to content

Commit df7bcfd

Browse files
committed
Fix CI issues: Ruby version consistency, lint integration, and optimizations
- Update Rails 6.1 CI job to use Ruby 3.0.6 (consistent with gemspec requirement) - Add lint checks to all CI jobs in main workflow - Fix pre-commit hook to use bash instead of sh for better compatibility - Optimize file globbing in rake tasks for better performance - Use more efficient reject/select pattern instead of multiple next statements
1 parent 2b30230 commit df7bcfd

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

.github/workflows/ruby.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ jobs:
1515
- name: Set up Ruby
1616
uses: ruby/setup-ruby@v1
1717
with:
18-
ruby-version: 2.7.6
18+
ruby-version: 3.0.6
1919
bundler-cache: true
2020
- name: Run tests
2121
run: bundle exec rake
22+
- name: Run lint checks
23+
run: bundle exec rake lint
2224
- name: Run interaction tests
2325
run: ./specs_e2e/rails_6_1/test.sh
2426
env:
@@ -36,6 +38,8 @@ jobs:
3638
bundler-cache: true
3739
- name: Run tests
3840
run: bundle exec rake
41+
- name: Run lint checks
42+
run: bundle exec rake lint
3943
- run: gem uninstall -v '>= 2' -ax bundler || true
4044
- run: gem install bundler -v '< 2'
4145
- name: Run interaction tests
@@ -55,6 +59,8 @@ jobs:
5559
bundler-cache: true
5660
- name: Run tests
5761
run: bundle exec rake
62+
- name: Run lint checks
63+
run: bundle exec rake lint
5864
- run: gem uninstall -v '>= 2' -ax bundler || true
5965
- run: gem install bundler -v '< 2'
6066
- name: Run interaction tests

bin/install-hooks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pre_commit_hook = File.join(hooks_dir, 'pre-commit')
88

99
# Create pre-commit hook content
1010
hook_content = <<~HOOK
11-
#!/bin/sh
11+
#!/usr/bin/env bash
1212
# Pre-commit hook to run linters and check for newlines
1313
1414
# Check for files missing newlines

rakelib/lint.rake

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ desc 'Ensure all files end with newline'
2020
task :check_newlines do
2121
files_without_newline = []
2222

23-
Dir.glob('**/*.{rb,rake,yml,yaml,md,gemspec,ru,erb,js,json}').each do |file|
24-
next if file.include?('vendor/') || file.include?('node_modules/') || file.include?('.git/')
25-
next if file.include?('pkg/') || file.include?('tmp/') || file.include?('coverage/')
26-
next unless File.file?(file)
23+
# Define excluded directories
24+
excluded_dirs = %w[vendor/ node_modules/ .git/ pkg/ tmp/ coverage/]
2725

26+
# Get all relevant files and filter out excluded directories more efficiently
27+
Dir.glob('**/*.{rb,rake,yml,yaml,md,gemspec,ru,erb,js,json}')
28+
.reject { |f| excluded_dirs.any? { |dir| f.start_with?(dir) } }
29+
.select { |f| File.file?(f) }
30+
.each do |file|
2831
content = File.read(file)
2932
files_without_newline << file unless content.empty? || content.end_with?("\n")
3033
end
@@ -42,11 +45,14 @@ desc 'Fix files missing final newline'
4245
task :fix_newlines do
4346
fixed_files = []
4447

45-
Dir.glob('**/*.{rb,rake,yml,yaml,md,gemspec,ru,erb,js,json}').each do |file|
46-
next if file.include?('vendor/') || file.include?('node_modules/') || file.include?('.git/')
47-
next if file.include?('pkg/') || file.include?('tmp/') || file.include?('coverage/')
48-
next unless File.file?(file)
48+
# Define excluded directories (same as check_newlines)
49+
excluded_dirs = %w[vendor/ node_modules/ .git/ pkg/ tmp/ coverage/]
4950

51+
# Get all relevant files and filter out excluded directories more efficiently
52+
Dir.glob('**/*.{rb,rake,yml,yaml,md,gemspec,ru,erb,js,json}')
53+
.reject { |f| excluded_dirs.any? { |dir| f.start_with?(dir) } }
54+
.select { |f| File.file?(f) }
55+
.each do |file|
5056
content = File.read(file)
5157
unless content.empty? || content.end_with?("\n")
5258
File.write(file, content + "\n")

0 commit comments

Comments
 (0)