-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fetch custom Ruby version file specified by ruby file: option in Gemfile
#14230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,6 +50,7 @@ def fetch_files | |||||||||||
| fetched_files += gemspecs | ||||||||||||
| fetched_files << T.must(ruby_version_file) if ruby_version_file | ||||||||||||
| fetched_files << T.must(tool_versions_file) if tool_versions_file | ||||||||||||
| fetched_files << T.must(ruby_file_version_file) if ruby_file_version_file | ||||||||||||
| fetched_files += path_gemspecs | ||||||||||||
| fetched_files += find_included_files(fetched_files) | ||||||||||||
|
|
||||||||||||
|
|
@@ -138,6 +139,28 @@ def tool_versions_file | |||||||||||
| @tool_versions_file ||= T.let(fetch_support_file(".tool-versions"), T.nilable(Dependabot::DependencyFile)) | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| sig { returns(T.nilable(DependencyFile)) } | ||||||||||||
| def ruby_file_version_file | ||||||||||||
| return unless gemfile | ||||||||||||
|
|
||||||||||||
| @ruby_file_version_file ||= T.let( | ||||||||||||
| begin | ||||||||||||
| filename = ruby_file_version_filename | ||||||||||||
| fetch_support_file(filename) if filename | ||||||||||||
| end, | ||||||||||||
| T.nilable(Dependabot::DependencyFile) | ||||||||||||
| ) | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| sig { returns(T.nilable(String)) } | ||||||||||||
| def ruby_file_version_filename | ||||||||||||
| content = gemfile&.content | ||||||||||||
| return unless content | ||||||||||||
|
|
||||||||||||
| match = content.match(/^\s*ruby\s+file:\s*['"]([^'"]+)['"]/) | ||||||||||||
| match&.captures&.first | ||||||||||||
|
||||||||||||
| match&.captures&.first | |
| filename = match&.captures&.first | |
| return if filename&.include?("/") || filename&.include?("\\") | |
| filename |
Copilot
AI
Feb 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file_preparer needs to be updated to include custom ruby version files in the prepared_dependency_files. Currently, the prepared_dependency_files method on lines 32-40 explicitly lists ruby_version_file and tool_versions_file, but does not include the newly fetched ruby_file_version_file.
Without this, even though the custom ruby version file is fetched by the FileFetcher, it won't be passed to the FileParser or FileUpdater, which will cause dependency resolution to fail when a Gemfile uses the "ruby file:" option.
Add a ruby_file_version_file method similar to ruby_version_file (lines 83-85) and tool_versions_file (lines 87-90), and include it in the array on line 32-40.
Copilot
AI
Feb 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lockfile_updater needs to write custom ruby version files when creating temporary dependency files. Currently, write_temporary_dependency_files (lines 128-144) calls write_ruby_version_file and write_tool_versions_file to handle .ruby-version and .tool-versions files, but it doesn't handle custom ruby version files specified via the "ruby file:" option.
Add a write_ruby_file_version_file method similar to write_ruby_version_file (lines 147-153) and write_tool_versions_file (lines 156-162), and call it from write_temporary_dependency_files. Also add a ruby_file_version_file method similar to lines 212-214 and 217-219 to locate the custom version file from dependency_files.
Copilot
AI
Feb 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The update_checker/file_preparer also needs to be updated to include custom ruby version files in the prepared_dependency_files. Currently, prepared_dependency_files on lines 118-124 includes ruby_version_file and tool_versions_file, but doesn't include the custom ruby version file specified via the "ruby file:" option.
Add a ruby_file_version_file method similar to ruby_version_file (lines 194-196) and tool_versions_file (lines 199-201), and include it in the array on lines 118-124.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| [ | ||
| { | ||
| "name": "Gemfile", | ||
| "path": "Gemfile", | ||
| "sha": "88b4e0a1c8093fae2b4fa52534035f9f85ed0956", | ||
| "size": 100, | ||
| "url": "https://api.github.com/repos/gocardless/bump/contents/Gemfile?ref=master", | ||
| "html_url": "https://github.com/gocardless/bump/blob/master/Gemfile", | ||
| "git_url": "https://api.github.com/repos/gocardless/bump/git/blobs/88b4e0a1c8093fae2b4fa52534035f9f85ed0956", | ||
| "download_url": "https://raw.githubusercontent.com/gocardless/bump/master/Gemfile", | ||
| "type": "file", | ||
| "_links": { | ||
| "self": "https://api.github.com/repos/gocardless/bump/contents/Gemfile?ref=master", | ||
| "git": "https://api.github.com/repos/gocardless/bump/git/blobs/88b4e0a1c8093fae2b4fa52534035f9f85ed0956", | ||
| "html": "https://github.com/gocardless/bump/blob/master/Gemfile" | ||
| } | ||
| }, | ||
| { | ||
| "name": "Gemfile.lock", | ||
| "path": "Gemfile.lock", | ||
| "sha": "d429264c8c2f0f306a422900c2f41123e07c31b4", | ||
| "size": 100, | ||
| "url": "https://api.github.com/repos/gocardless/bump/contents/Gemfile.lock?ref=master", | ||
| "html_url": "https://github.com/gocardless/bump/blob/master/Gemfile.lock", | ||
| "git_url": "https://api.github.com/repos/gocardless/bump/git/blobs/d429264c8c2f0f306a422900c2f41123e07c31b4", | ||
| "download_url": "https://raw.githubusercontent.com/gocardless/bump/master/Gemfile.lock", | ||
| "type": "file", | ||
| "_links": { | ||
| "self": "https://api.github.com/repos/gocardless/bump/contents/Gemfile.lock?ref=master", | ||
| "git": "https://api.github.com/repos/gocardless/bump/git/blobs/d429264c8c2f0f306a422900c2f41123e07c31b4", | ||
| "html": "https://github.com/gocardless/bump/blob/master/Gemfile.lock" | ||
| } | ||
| }, | ||
| { | ||
| "name": "custom-ruby-version", | ||
| "path": "custom-ruby-version", | ||
| "sha": "005119baaa0653ca59d923010341d8341daa8c43", | ||
| "size": 6, | ||
| "url": "https://api.github.com/repos/gocardless/bump/contents/custom-ruby-version?ref=master", | ||
| "html_url": "https://github.com/gocardless/bump/blob/master/custom-ruby-version", | ||
| "git_url": "https://api.github.com/repos/gocardless/bump/git/blobs/005119baaa0653ca59d923010341d8341daa8c43", | ||
| "download_url": "https://raw.githubusercontent.com/gocardless/bump/master/custom-ruby-version", | ||
| "type": "file", | ||
| "_links": { | ||
| "self": "https://api.github.com/repos/gocardless/bump/contents/custom-ruby-version?ref=master", | ||
| "git": "https://api.github.com/repos/gocardless/bump/git/blobs/005119baaa0653ca59d923010341d8341daa8c43", | ||
| "html": "https://github.com/gocardless/bump/blob/master/custom-ruby-version" | ||
| } | ||
| } | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "name": "custom-ruby-version", | ||
| "path": "custom-ruby-version", | ||
| "sha": "005119baaa0653ca59d923010341d8341daa8c43", | ||
| "size": 6, | ||
| "url": "https://api.github.com/repos/gocardless/bump/contents/custom-ruby-version?ref=master", | ||
| "html_url": "https://github.com/gocardless/bump/blob/master/custom-ruby-version", | ||
| "git_url": "https://api.github.com/repos/gocardless/bump/git/blobs/005119baaa0653ca59d923010341d8341daa8c43", | ||
| "download_url": "https://raw.githubusercontent.com/gocardless/bump/master/custom-ruby-version", | ||
| "type": "file", | ||
| "content": "My4yLjAK\n", | ||
| "encoding": "base64", | ||
| "_links": { | ||
| "self": "https://api.github.com/repos/gocardless/bump/contents/custom-ruby-version?ref=master", | ||
| "git": "https://api.github.com/repos/gocardless/bump/git/blobs/005119baaa0653ca59d923010341d8341daa8c43", | ||
| "html": "https://github.com/gocardless/bump/blob/master/custom-ruby-version" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "name": "Gemfile", | ||
| "path": "Gemfile", | ||
| "sha": "aabbcc1122334455667788990011223344556677", | ||
| "size": 80, | ||
| "url": "https://api.github.com/repos/gocardless/bump/contents/Gemfile?ref=master", | ||
| "html_url": "https://github.com/gocardless/bump/blob/master/Gemfile", | ||
| "git_url": "https://api.github.com/repos/gocardless/bump/git/blobs/aabbcc1122334455667788990011223344556677", | ||
| "download_url": "https://raw.githubusercontent.com/gocardless/bump/master/Gemfile", | ||
| "type": "file", | ||
| "content": "c291cmNlICJodHRwczovL3J1YnlnZW1zLm9yZyIKCnJ1YnkgZmlsZTogImN1\nc3RvbS1ydWJ5LXZlcnNpb24iCgpnZW0gImJ1c2luZXNzIiwgIn4+IDEuMCIK\n", | ||
| "encoding": "base64", | ||
| "_links": { | ||
| "self": "https://api.github.com/repos/gocardless/bump/contents/Gemfile?ref=master", | ||
| "git": "https://api.github.com/repos/gocardless/bump/git/blobs/aabbcc1122334455667788990011223344556677", | ||
| "html": "https://github.com/gocardless/bump/blob/master/Gemfile" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| source "https://rubygems.org" | ||
|
|
||
| ruby file: "custom-ruby-version" | ||
|
|
||
| gem "business", "~> 1.4.0" | ||
| gem "statesman", "~> 1.2.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| GEM | ||
| remote: https://rubygems.org/ | ||
| specs: | ||
| business (1.4.0) | ||
| statesman (1.2.1) | ||
|
|
||
| PLATFORMS | ||
| ruby | ||
|
|
||
| DEPENDENCIES | ||
| business (~> 1.4.0) | ||
| statesman (~> 1.2.0) | ||
|
|
||
| BUNDLED WITH | ||
| 2.2.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 2.2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern could be made more robust to handle edge cases. Consider these improvements:
While the current pattern /^\sruby\s+file:\s'"['"]/ will work for basic cases, consider making it more flexible to match actual Gemfile parsing behavior. You could use a pattern like:
/^\sruby\s+(?:file:\s|:file\s*=>\s*)'"['"]/
This handles both hash syntaxes and is more aligned with Ruby conventions.