Skip to content

Commit ea9382e

Browse files
committed
Add Sequel-style lint checks and Ruby CI matrix
1 parent b7bfc6c commit ea9382e

5 files changed

Lines changed: 86 additions & 4 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-24.04
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
ruby: ['3.3', '3.4', '4.0']
18+
steps:
19+
- uses: actions/checkout@v6
20+
- uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: ${{ matrix.ruby }}
23+
bundler-cache: true
24+
- run: bundle exec rake check

‎Gemfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ gem 'logger'
88
gem 'minitest-hooks', '~> 1.5'
99
gem 'minitest-global_expectations', '~> 1.0'
1010
gem 'securerandom'
11+
gem 'visibility_checker', '~> 1.0'

‎Gemfile.lock‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ GEM
2525
mini_portile2 (~> 2.8.0)
2626
turso_libsql (0.2.0)
2727
ffi (~> 1.17)
28+
visibility_checker (1.0.0)
2829

2930
PLATFORMS
3031
ruby
@@ -38,6 +39,7 @@ DEPENDENCIES
3839
rake (~> 13.0)
3940
securerandom
4041
sqlite3 (~> 2.0)
42+
visibility_checker (~> 1.0)
4143

4244
CHECKSUMS
4345
bigdecimal (4.1.3) sha256=61ebe1e5e559bdc3cc6f2c0ee7f427321fc838f59611c294356eb04d6e21cf66
@@ -54,6 +56,7 @@ CHECKSUMS
5456
sequel (5.109.0) sha256=e0d1d474442d620c8497d7f4851c0cc3a277920519051b8014b2877aa55efffe
5557
sqlite3 (2.10.2) sha256=f1ea68cd3287f8a49f39a088ac9e4bd0ef4e7f394c3d4a60dd4c7e44b0566964
5658
turso_libsql (0.2.0) sha256=edc837c80df7e5602130a9a578688183eac9d501cb1521d0747fd34079eacdb3
59+
visibility_checker (1.0.0) sha256=db9f5552ca394b211e6533bdb5844dc556dcebfa5cf3083673debbdf71e447c3
5760

5861
BUNDLED WITH
5962
4.0.20

‎Rakefile‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,56 @@
22

33
require 'rake/testtask'
44

5+
RUBY_WARNING_FLAGS = ['-w'].freeze
6+
STRICT_BLOCK_WARNING_FLAGS = RUBY_VERSION >= '3.4' ? ['-W:strict_unused_block'].freeze : [].freeze
7+
58
Rake::TestTask.new do |t|
69
t.libs << 'test'
710
t.pattern = 'test/**/*_test.rb'
11+
t.warning = true
12+
t.ruby_opts.concat(STRICT_BLOCK_WARNING_FLAGS)
813
end
914

10-
task :default => :test
15+
task :default => :check
16+
17+
desc 'Run syntax and method-visibility checks, then warning-enabled native tests'
18+
task :check => [:lint, :test]
19+
20+
desc 'Run the syntax and method-visibility checks used by Sequel'
21+
task :lint => [:check_syntax, :check_visibility]
22+
23+
desc 'Check Ruby syntax with warnings (project files only)'
24+
task :check_syntax do
25+
require 'open3'
26+
files = FileList['lib/**/*.rb', 'test/**/*.rb', 'examples/**/*.rb', 'tasks/**/*.rb', '*.gemspec', 'Gemfile', 'Rakefile'].sort
27+
files.each do |file|
28+
stdout, stderr, status = Open3.capture3(RbConfig.ruby, *RUBY_WARNING_FLAGS, *STRICT_BLOCK_WARNING_FLAGS, '-c', file)
29+
next if status.success? && stderr.empty?
30+
warn stdout unless status.success?
31+
warn stderr unless stderr.empty?
32+
abort "Ruby syntax/warning check failed: #{file}"
33+
end
34+
puts "Syntax and warnings checked: #{files.length} project files"
35+
end
36+
37+
desc 'Check adapter method visibility with Jeremy Evans\' visibility_checker'
38+
task :check_visibility do
39+
ruby(*RUBY_WARNING_FLAGS, *STRICT_BLOCK_WARNING_FLAGS, '-Ilib', 'tasks/check_visibility.rb')
40+
end
1141

1242
desc 'Run Sequel upstream SQLite and integration specs (requires tmp/upstream/sequel)'
1343
task :upstream do
14-
ruby 'test/upstream.rb'
44+
ruby(*RUBY_WARNING_FLAGS, *STRICT_BLOCK_WARNING_FLAGS, 'test/upstream.rb')
1545
end
1646

1747
desc 'Run opt-in HTTP/Turso tests using LIBSQL_TEST_URL and LIBSQL_TEST_AUTH_TOKEN'
1848
task :remote do
19-
ruby '-Ilib', 'test/remote.rb'
49+
ruby(*RUBY_WARNING_FLAGS, *STRICT_BLOCK_WARNING_FLAGS, '-Ilib', 'test/remote.rb')
2050
end
2151

2252
desc 'Run the native HTTP tests against the local upstream Hrana fixture'
2353
task :remote_local do
2454
sh({'LIBSQL_TEST_URL' => 'http://localhost:8080', 'LIBSQL_TEST_AUTH_TOKEN' => ''},
2555
'tmp/hrana-venv/bin/python', 'test/support/hrana_server.py',
26-
RbConfig.ruby, '-Ilib', 'test/remote.rb')
56+
RbConfig.ruby, *RUBY_WARNING_FLAGS, *STRICT_BLOCK_WARNING_FLAGS, '-Ilib', 'test/remote.rb')
2757
end

‎tasks/check_visibility.rb‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen-string-literal: true
2+
3+
require 'libsql-sequel'
4+
require 'visibility_checker'
5+
6+
# Also check a prepared dataset: Sequel mixes additional modules into it.
7+
Sequel.connect(:adapter => :libsql) do |db|
8+
prepared = db.select(Sequel.as(:$value, :value)).prepare(:first, :visibility_check)
9+
classes = [db.singleton_class, db.dataset.singleton_class, prepared.singleton_class]
10+
changes = classes.flat_map{|klass| VisibilityChecker.visibility_changes(klass)}.uniq
11+
# Sequel's own prepared module changes literal_symbol_append visibility.
12+
# Report changes introduced by this adapter, not inherited upstream changes.
13+
library = File.expand_path('../lib/', __dir__) + '/'
14+
changes.select! do |change|
15+
source = change.overridden_by.instance_method(change.method).source_location
16+
source && source.first.start_with?(library)
17+
end
18+
changes.each do |change|
19+
warn "#{change.overridden_by}##{change.method}: #{change.new_visibility} overrides #{change.original_visibility} in #{change.defined_in}"
20+
end
21+
abort 'Adapter method visibility changed' unless changes.empty?
22+
end
23+
24+
puts 'No adapter method visibility changes'

0 commit comments

Comments
 (0)