Skip to content
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

Clean up Gemfile & pin all gems #680

Merged
merged 6 commits into from
Aug 22, 2024
Merged

Clean up Gemfile & pin all gems #680

merged 6 commits into from
Aug 22, 2024

Conversation

Splines
Copy link
Member

@Splines Splines commented Aug 14, 2024

  • Pin gem versions instead of using the newest commit on the main branch
  • Don't use >=, but ~> instead, which will not automatically install major version updates
  • Clean up comments in the Gemfile and remove old packages that were commented out. Note that when the comments are not on a separate line, VSCode can do the alphabetical ordering for us automatically.
  • ⚠ Remove SQLite dependency: as far as I can tell, we don't use SQLite anywhere, is that correct? We have been using PostgreSQL instead for a long time.

In this PR, we don't update any dependencies, i.e. we didn't do bundle update, just bundle install with the pinned versions. An exception is the SQLite dependency, which is removed as seen above.

TODO

  • Pin version for every single gem! (Is there a bundler command for this that we could use? -> didn't find one, but GitHub Copilot generated a neat little script that saved me a lot of time searching the version numbers. Of course, you have to manually fix some mistakes (e.g. version number after the line comment), but this is easy to fix manually afterwards.
# ./pin_gemfile_versions.rb

require "bundler"

# Parse the Gemfile.lock
lockfile_parser = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock"))

# Read the original Gemfile
gemfile_content = File.read("Gemfile")

# Create a hash of gem names and their versions
gem_versions = lockfile_parser.specs.each_with_object({}) do |spec, hash|
  hash[spec.name] = spec.version.to_s
end

# Update the Gemfile content with version specifiers
updated_gemfile_content = gemfile_content.lines.map do |line|
  if line =~ /gem\s+["']([^"']+)["']/
    gem_name = Regexp.last_match(1)
    version = gem_versions[gem_name]
    if version
      line.sub(/$/, ", '~> #{version}'")
    else
      line
    end
  else
    line
  end
end.join

# Write the updated content back to the Gemfile
File.write("Gemfile", updated_gemfile_content)

@Splines Splines added the dependencies Pull requests that update a dependency file label Aug 14, 2024
@Splines Splines self-assigned this Aug 14, 2024
@Splines Splines marked this pull request as ready for review August 20, 2024 14:54
@Splines Splines changed the title Clean up Gemfile Clean up Gemfile & pin all gems Aug 20, 2024
Copy link

codecov bot commented Aug 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (dev@0d39b9e). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff           @@
##             dev     #680   +/-   ##
======================================
  Coverage       ?   53.80%           
======================================
  Files          ?      157           
  Lines          ?     6644           
  Branches       ?        0           
======================================
  Hits           ?     3575           
  Misses         ?     3069           
  Partials       ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@fosterfarrell9 fosterfarrell9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Indeed, SQlite has not been used by us for a long time.

@Splines Splines merged commit dd0d68b into dev Aug 22, 2024
5 checks passed
@Splines Splines deleted the deps/gemfile branch August 22, 2024 21:28
@Splines Splines mentioned this pull request Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants