Skip to content

Ensure the release CI doesn't break due to the Bundler checksum feature#9436

Open
Edouard-chin wants to merge 4 commits intoruby:masterfrom
Shopify:ec-try-checksum-on-dev
Open

Ensure the release CI doesn't break due to the Bundler checksum feature#9436
Edouard-chin wants to merge 4 commits intoruby:masterfrom
Shopify:ec-try-checksum-on-dev

Conversation

@Edouard-chin
Copy link
Copy Markdown
Collaborator

What was the end-user or developer problem that led to this PR?

Whenever we modify the Bundler VERSION to create a release, CI will break.
This change is purely to fix a problem when developing Bundler. When we tried to release Bundler 4.0.9, we bumped the VERSION from 4.1.0.dev to 4.0.9, this condition now evaluates to false/

return [] if Bundler.gem_version.to_s.end_with?(".dev")

We then ended up with a CI crash.

Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/runner/work/rubygems/rubygems/cache/bundler-4.0.9.gem

What is your fix for the problem, implemented in this PR?

I explained changes one by one in the commit message as it's easier to understand with the associated code.

To make sure that this works on a release CI, I pushed a version bump and ran a CI at https://github.com/Shopify/rubygems/actions/runs/23593699080

Make sure the following tasks are checked

- ### Problem

  This change is purely to fix a problem when developing Bundler.
  When we tried to release Bundler 4.0.9, we bumped the VERSION
  from `4.1.0.dev` to `4.0.9`, this condition now evaluates to false
  https://github.com/ruby/rubygems/blob/34d19fa8a3f84c50e2ba65e0f39c80045e7cbfb8/bundler/lib/bundler/lockfile_generator.rb#L106.
  We then ended up with a CI crash.

  ```
  Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/runner/work/rubygems/rubygems/cache/bundler-4.0.9.gem
  ```

  ### Context

  Computing a checksum for the `bundler` gem is only possible
  when the `bundler.gem` binary exists on disk. When a regular
  user interacts with `bundler`, the spec is loaded from disk and
  an associated cached `bundler.gem` should exists.

  However, when developing Bundler, the spec doesn't come from disk
  but from a fake spec https://github.com/ruby/rubygems/blob/34d19fa8a3f84c50e2ba65e0f39c80045e7cbfb8/bundler/lib/bundler/source/metadata.rb#L22-L28
  that with no associated `bundler.gem`.

  ### Solution

  To prevent CI from breaking whenever we make a release, we have
  to skip computing a checksum if no `bundler.gem` exists.
- ### Problem

  Whenever we bump the bundler `VERSION` to a non development release,
  like we recently did in [4.0.9](ruby#9426)

  The test suite will behave differently and will break due to the
  Bundler checksum feature introduced in ruby#9366

  This is because the expectactions of tests that have a lockfile'
  will sometimes include a checksum line for the bundler gem itself
  depending on whether this condition evaluates to `true`.

  https://github.com/ruby/rubygems/blob/34d19fa8a3f84c50e2ba65e0f39c80045e7cbfb8/bundler/lib/bundler/lockfile_generator.rb#L106

  ### Solution

  We can modify the spec helper `checksums_section_when_enabled` to
  automatically append a checksum entry for bundler whenever necesary.
- ### Problem

  When we make a new bundler release, CI lint will break due to those
  two steps.

https://github.com/ruby/rubygems/blob/34d19fa8a3f84c50e2ba65e0f39c80045e7cbfb8/.github/workflows/ubuntu-lint.yml#L107-L110

  It's a bit tricky to explain without being too verbose, but in
  summary, one check will tell you to update the lockfile to include
  bundler checksum, and once you do and repush, the other check will
  tell you that you have added bundler checksum and you shouldn't
  have.

  ### Context

  When the "Misc check" step runs, it executes `rake version:check`,
  to ensure that the BUNDLED_WITH section of development lockfile
  (such as test_gems.rb.lock) gets modified.
  It does so by literally packaging `bundler.gem` and install it,
  then run `bundle update --bundler`. In this scenario, due to the
  self-manager feature, we are not using the "bundler development"
  binstub but will be using the "real" bundler that we just packaged
  https://github.com/ruby/rubygems/blob/34d19fa8a3f84c50e2ba65e0f39c80045e7cbfb8/bundler/lib/bundler/self_manager.rb#L33

  This has for consequence that the lockfile will include bundler
  checksum, and tell you to update them and repush.

  Once you re-push with the lockfile updated, the other CI check
  `rake dev:frozen_deps` that **uses** bundler development binstub
  will not include a checksum entry for bundler and will tell you
  to remove it from the lockfile...

  ### Solution

  I want to prevent `rake version:check` from using the packaged
  bundler and use the binstub so that no checksum get added to
  development lockfile. We can do so with the `bundle lock` command
  instead, which won't autoswitch bundler.
- ### Problem

  This test breaks whenever checksums are computed. It didn't break
  before because the gemfile in this test doesn't include any gems
  (only git gems) and therefore checksum is skipped.

  ### Context

  This test was added in c19a9f2 to ensure Bundler will not load
  "digest". I don't think this test really works as it will break
  as soon as you had a regular gem in the gemfile test.
  https://github.com/ruby/rubygems/blob/34d19fa8a3f84c50e2ba65e0f39c80045e7cbfb8/spec/runtime/setup_spec.rb#L1354-L1355

  I'm being unlucky and it now fails because we compute a checksum
  for the "bundler" gem itself. Computing a checksum requires
  "rubygems/package", and down the line requires "digest".

  ### Solution

  For the sake of shipping this PR, I'm going to go workaround the
  problem and skip checksum so that "digest" is not loaded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants