Skip to content

Commit b26e8dd

Browse files
committed
Trying to fix ci errors
1 parent 8a3a52b commit b26e8dd

File tree

4 files changed

+63
-29
lines changed

4 files changed

+63
-29
lines changed

.github/workflows/cicd.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
run: bundle exec rubocop
7373

7474
- name: Run tests
75-
if: matrix.ruby-version != '3.4' || matrix.rails-version != 'rails-8.0'
75+
if: matrix.ruby-version != '4.0' || matrix.rails-version != 'rails-8.1'
7676
run: bundle exec appraisal ${{ matrix.rails-version }} rspec --tag '~generator'
7777
env: # Dummy environment variables for local providers
7878
OLLAMA_API_BASE: http://localhost:11434/v1
@@ -81,15 +81,15 @@ jobs:
8181
SKIP_COVERAGE: true
8282

8383
- name: Run full test suite with coverage (latest Ruby/Rails)
84-
if: matrix.ruby-version == '3.4' && matrix.rails-version == 'rails-8.0'
84+
if: matrix.ruby-version == '4.0' && matrix.rails-version == 'rails-8.1'
8585
run: bundle exec appraisal ${{ matrix.rails-version }} rspec
8686
env: # Dummy environment variables for local providers
8787
OLLAMA_API_BASE: http://localhost:11434/v1
8888
GPUSTACK_API_BASE: http://localhost:11444/v1
8989
GPUSTACK_API_KEY: test
9090

9191
- name: Upload coverage to Codecov
92-
if: matrix.ruby-version == '3.4' && matrix.rails-version == 'rails-8.0'
92+
if: matrix.ruby-version == '4.0' && matrix.rails-version == 'rails-8.1'
9393
uses: codecov/codecov-action@v5
9494
env:
9595
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
@@ -124,7 +124,7 @@ jobs:
124124
- name: Set up Ruby
125125
uses: ruby/setup-ruby@v1
126126
with:
127-
ruby-version: '3.4'
127+
ruby-version: '4.0'
128128
bundler-cache: true
129129

130130
- name: Check if version needs publishing

spec/fixtures/templates/default_models_template.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
gem 'ruby_llm', path: ENV['RUBYLLM_PATH'] || '../../../..'
44

5-
after_bundle do
6-
generate 'ruby_llm:install'
7-
rails_command 'db:migrate'
8-
generate 'ruby_llm:chat_ui'
9-
end
5+
bundle_command 'install'
6+
generate 'ruby_llm:install'
7+
rails_command 'db:migrate'
8+
generate 'ruby_llm:chat_ui'

spec/fixtures/templates/namespaced_models_template.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
gem 'ruby_llm', path: ENV['RUBYLLM_PATH'] || '../../../..'
44

5-
after_bundle do
6-
generate 'ruby_llm:install',
7-
'chat:Llm::Chat',
8-
'message:Llm::Message',
9-
'model:Llm::Model',
10-
'tool_call:Llm::ToolCall'
11-
rails_command 'db:migrate'
12-
generate 'ruby_llm:chat_ui',
13-
'chat:Llm::Chat',
14-
'message:Llm::Message',
15-
'model:Llm::Model'
16-
end
5+
bundle_command 'install'
6+
generate 'ruby_llm:install',
7+
'chat:Llm::Chat',
8+
'message:Llm::Message',
9+
'model:Llm::Model',
10+
'tool_call:Llm::ToolCall'
11+
rails_command 'db:migrate'
12+
generate 'ruby_llm:chat_ui',
13+
'chat:Llm::Chat',
14+
'message:Llm::Message',
15+
'model:Llm::Model'

spec/support/generator_test_helpers.rb

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,58 @@
11
# frozen_string_literal: true
22

33
require 'English'
4+
require 'open3'
5+
require 'tmpdir'
46
module GeneratorTestHelpers
57
def self.cleanup_test_app(app_path)
68
FileUtils.rm_rf(app_path)
79
end
810

911
def self.create_test_app(name, template:, template_path:)
1012
template_file = File.join(template_path, template)
13+
ruby_llm_path = File.expand_path('../..', __dir__)
14+
root_bundle_gemfile = ENV['BUNDLE_GEMFILE'] || Bundler.default_gemfile.to_s
1115

12-
Bundler.with_unbundled_env do
13-
Dir.chdir(Dir.tmpdir) do
14-
ENV['RUBYLLM_PATH'] = File.expand_path('../..', __dir__)
15-
`rails new #{name} --skip-bootsnap -m #{template_file} 2>&1`
16-
success = $CHILD_STATUS.success?
17-
raise "Failed to create test app #{name}" unless success
18-
end
19-
end
16+
root_env = {
17+
'RUBYLLM_PATH' => ruby_llm_path,
18+
'BUNDLE_GEMFILE' => root_bundle_gemfile
19+
}
20+
root_env['BUNDLE_PATH'] = ENV['BUNDLE_PATH'] if ENV.key?('BUNDLE_PATH')
21+
root_env['BUNDLE_DISABLE_SHARED_GEMS'] = ENV['BUNDLE_DISABLE_SHARED_GEMS'] if ENV.key?('BUNDLE_DISABLE_SHARED_GEMS')
22+
23+
app_path = File.join(Dir.tmpdir, name)
24+
25+
create_command = [
26+
'bundle', 'exec', 'rails', 'new', name,
27+
'--skip-bootsnap', '--skip-bundle', '--skip-kamal', '--skip-thruster'
28+
]
29+
output, status = run_command(root_env, create_command, chdir: Dir.tmpdir)
30+
raise_command_error(name, create_command, status, output) unless status.success?
31+
32+
app_env = root_env.merge('BUNDLE_GEMFILE' => File.join(app_path, 'Gemfile'))
33+
34+
install_command = ['bundle', 'install', '--quiet']
35+
output, status = run_command(app_env, install_command, chdir: app_path)
36+
raise_command_error(name, install_command, status, output) unless status.success?
37+
38+
template_command = ['bundle', 'exec', 'rails', 'app:template', "LOCATION=#{template_file}"]
39+
output, status = run_command(app_env, template_command, chdir: app_path)
40+
raise_command_error(name, template_command, status, output) unless status.success?
41+
end
42+
43+
def self.run_command(env, command, chdir:)
44+
stdout, stderr, process_status = Open3.capture3(env, *command, chdir:)
45+
["#{stdout}#{stderr}", process_status]
46+
end
47+
48+
def self.raise_command_error(name, command, status, output)
49+
raise <<~ERROR
50+
Failed to create test app #{name}
51+
Command: #{command.join(' ')}
52+
Exit status: #{status.exitstatus}
53+
Output:
54+
#{output}
55+
ERROR
2056
end
2157

2258
def within_test_app(app_path, &)

0 commit comments

Comments
 (0)