Skip to content

Commit 8600f3b

Browse files
authored
Fix CI setup for Windows (#352)
Fixes for Windows Co-authored-by: Andy Waite <[email protected]>
1 parent a49b02e commit 8600f3b

File tree

9 files changed

+35
-20
lines changed

9 files changed

+35
-20
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,8 @@ jobs:
5252
- name: Lint Ruby files
5353
run: bin/rubocop
5454

55+
- name: Lint Ruby files
56+
run: bin/rubocop
57+
5558
- name: Run tests
56-
run: bin/rails db:setup && bin/rails db:migrate && bin/rails test
59+
run: bundle exec rails db:setup && bundle exec rails db:migrate && bundle exec rails test

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ gem "tapioca", "~> 0.13", require: false, platforms: :ruby
2020
gem "psych", "~> 5.1", require: false
2121
gem "rails"
2222
gem "webmock"
23+
24+
platforms :mingw, :x64_mingw, :mswin, :jruby do
25+
gem "tzinfo"
26+
gem "tzinfo-data"
27+
end

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ DEPENDENCIES
301301
sorbet-static-and-runtime
302302
sqlite3 (< 2)
303303
tapioca (~> 0.13)
304+
tzinfo
305+
tzinfo-data
304306
webmock
305307

306308
BUNDLED WITH

gemfiles/Gemfile-rails-main

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ gem "tapioca", "~> 0.11", require: false, platforms: :ruby
2020
gem "psych", "~> 5.1", require: false
2121
gem "rails", github: "rails/rails", branch: "main"
2222
gem "webmock"
23+
24+
platforms :mingw, :x64_mingw, :mswin, :jruby do
25+
gem "tzinfo"
26+
gem "tzinfo-data"
27+
end

lib/ruby_lsp/ruby_lsp_rails/hover.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def generate_column_content(name)
7777
schema_file = model[:schema_file]
7878

7979
@response_builder.push(
80-
"[Schema](#{URI::Generic.build(scheme: "file", path: schema_file)})",
80+
"[Schema](#{URI::Generic.from_path(path: schema_file)})",
8181
category: :links,
8282
) if schema_file
8383

lib/ruby_lsp/ruby_lsp_rails/runner_client.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ def initialize
4646
Process.setsid
4747
rescue Errno::EPERM
4848
# If we can't set the session ID, continue
49+
rescue NotImplementedError
50+
# setpgrp() may be unimplemented on some platform
51+
# https://github.com/Shopify/ruby-lsp-rails/issues/348
4952
end
5053

5154
stdin, stdout, stderr, wait_thread = Bundler.with_original_env do
52-
Open3.popen3("bin/rails", "runner", "#{__dir__}/server.rb", "start")
55+
Open3.popen3("bundle", "exec", "rails", "runner", "#{__dir__}/server.rb", "start")
5356
end
5457

5558
@stdin = T.let(stdin, IO)

test/ruby_lsp_rails/code_lens_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Test < ActiveSupport::TestCase
3636
# The last 3 are for the test declaration.
3737
assert_equal(6, response.size)
3838
assert_match("Run", response[3].command.title)
39-
assert_equal("bin/rails test /fake.rb:2", response[3].command.arguments[2])
39+
assert_match(%r{(ruby )?bin/rails test /fake\.rb:2}, response[3].command.arguments[2])
4040
assert_match("Run In Terminal", response[4].command.title)
4141
assert_match("Debug", response[5].command.title)
4242
end
@@ -54,7 +54,7 @@ class Test < ActiveSupport::TestCase
5454
# The last 3 are for the test declaration.
5555
assert_equal(6, response.size)
5656
assert_match("Run", response[3].command.title)
57-
assert_equal("bin/rails test /fake.rb:2", response[3].command.arguments[2])
57+
assert_match(%r{(ruby )?bin/rails test /fake\.rb:2}, response[3].command.arguments[2])
5858
assert_match("Run In Terminal", response[4].command.title)
5959
assert_match("Debug", response[5].command.title)
6060
end
@@ -73,7 +73,7 @@ class Test < ActiveSupport::TestCase
7373
# The last 3 are for the test declaration.
7474
assert_equal(6, response.size)
7575
assert_match("Run", response[3].command.title)
76-
assert_equal("bin/rails test /fake.rb:2", response[3].command.arguments[2])
76+
assert_match(%r{(ruby )?bin/rails test /fake\.rb:2}, response[3].command.arguments[2])
7777
assert_match("Run In Terminal", response[4].command.title)
7878
assert_match("Debug", response[5].command.title)
7979
end
@@ -144,7 +144,7 @@ def test_example
144144
# The last 3 are for the test class.
145145
assert_equal(6, response.size)
146146
assert_match("Run", response[3].command.title)
147-
assert_equal("bin/rails test /fake.rb:2", response[3].command.arguments[2])
147+
assert_match(%r{(ruby )?bin/rails test /fake\.rb:2}, response[3].command.arguments[2])
148148
assert_match("Run In Terminal", response[4].command.title)
149149
assert_match("Debug", response[5].command.title)
150150
end

test/ruby_lsp_rails/hover_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class User < ApplicationRecord
5252
```
5353
5454
**Definitions**: [fake.rb](file:///fake.rb#L1,1-2,4)
55-
[Schema](file://#{dummy_root}/db/schema.rb)
55+
[Schema](#{URI::Generic.from_path(path: dummy_root + "/db/schema.rb")})
5656
5757
5858
**id**: integer (PK)
@@ -95,7 +95,7 @@ class User < ApplicationRecord
9595
RUBY
9696

9797
assert_equal(<<~CONTENT.chomp, response.contents.value)
98-
[Schema](file://#{dummy_root}/db/schema.rb)
98+
[Schema](#{URI::Generic.from_path(path: dummy_root + "/db/schema.rb")})
9999
100100
**id**: integer (PK)
101101
@@ -139,7 +139,7 @@ class CompositePrimaryKey < ApplicationRecord
139139
```
140140
141141
**Definitions**: [fake.rb](file:///fake.rb#L1,1-2,4)
142-
[Schema](file://#{dummy_root}/db/schema.rb)
142+
[Schema](#{URI::Generic.from_path(path: dummy_root + "/db/schema.rb")})
143143
144144
145145
**order_id**: integer (PK)
@@ -172,7 +172,7 @@ class User < ApplicationRecord
172172

173173
assert_includes(
174174
response.contents.value,
175-
"[Schema](file://#{dummy_root}/db/structure.sql)",
175+
"[Schema](#{URI::Generic.from_path(path: dummy_root + "/db/structure.sql")})",
176176
)
177177
end
178178

test/ruby_lsp_rails/runner_client_test.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
require "test_helper"
55
require "ruby_lsp/ruby_lsp_rails/runner_client"
66

7+
# tests are hanging in CI. https://github.com/Shopify/ruby-lsp-rails/issues/348
8+
return if Gem.win_platform?
9+
710
module RubyLsp
811
module Rails
912
class RunnerClientTest < ActiveSupport::TestCase
@@ -54,16 +57,10 @@ class RunnerClientTest < ActiveSupport::TestCase
5457
end
5558

5659
test "failing to spawn server creates a null client" do
57-
FileUtils.mv("bin/rails", "bin/rails_backup")
58-
File.open("bin/rails", "w") do |f|
59-
f.write("foo")
60-
end
61-
File.chmod(0o755, "bin/rails")
62-
63-
# The error message is slightly different on Ubuntu, so we need to allow for that
60+
FileUtils.mv("test/dummy/config/application.rb", "test/dummy/config/application.rb.bak")
6461
assert_output(
6562
"",
66-
%r{Ruby LSP Rails failed to initialize server: bin/rails: (line )?1: foo:( command)? not found},
63+
/Ruby LSP Rails failed to initialize server/,
6764
) do
6865
client = RunnerClient.create_client
6966

@@ -72,7 +69,7 @@ class RunnerClientTest < ActiveSupport::TestCase
7269
assert_predicate(client, :stopped?)
7370
end
7471
ensure
75-
FileUtils.mv("bin/rails_backup", "bin/rails")
72+
FileUtils.mv("test/dummy/config/application.rb.bak", "test/dummy/config/application.rb")
7673
end
7774

7875
test "is resilient to extra output being printed during boot" do

0 commit comments

Comments
 (0)