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

Fix Gemfile.lock.release handling for plugins #22075

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

agrare
Copy link
Member

@agrare agrare commented Aug 24, 2022

When plugins run tests on a release branch the Gemfile.lock.release was copied to Gemfile.lock but since the plugin spec doesn't match (GIT vs PATH) the Gemfile.lock was invalidated and rebuilt with the latest gem versions.

This meant that plugin tests on release branches were not actually testing with the gems from the release.

This change patches the Gemfile.lock to fix the engine spec so the Gemfile.lock isn't invalidated. It will have to be called by the bin/before_install script in each plugin.

NOTE: this has to be done prior to ruby setup since that runs bundle install, thus I implemented this in Python as that is available on github actions already. Awk/sed all process one line at a time so rebuilding the entire gem block proved impractical though I'm sure it could be done.

@@ -16,7 +16,6 @@ def self.manageiq_plugin_update(plugin_root = nil, force_bundle_update: true)
# determine plugin root dir. Assume we are called from a 'bin/' script in the plugin root
plugin_root ||= Pathname.new(caller_locations.last.absolute_path).dirname.parent

setup_gemfile_lock if ENV["CI"]
Copy link
Member Author

Choose a reason for hiding this comment

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

At this point the Gemfile.lock will have already been patched and this would just overwrite it.

Copy link
Member

Choose a reason for hiding this comment

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

I think we still need this for build...or does build manually copy the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

The build doesn't call bin/setup in each plugin dir, it only does this for the core repo

Copy link
Member

Choose a reason for hiding this comment

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

Oh ok - I forgot that core doesn't call into these methods...I really need to push my branch where it does, cause I keep confusing myself haha.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. So is this line needed or not?

with open('Gemfile.lock') as f:
gemfile_lock = f.read()

gemfile_lock_patched = re.compile("GIT\n remote: %s\n revision: .+\n branch: .+\n" %(os.environ['GITHUB_REPOSITORY'])).sub('PATH\n remote: .\n', gemfile_lock)
Copy link
Member Author

@agrare agrare Aug 24, 2022

Choose a reason for hiding this comment

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

NOTE these GitHub actions env vars don't with with cross-repo but this is no different from the existing before_install checks so I left it for now

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to log the Gemfile.lock before and after patching? Or maybe just the diff? I was hoping to see what this looks like in the CI log.

Copy link
Member

Choose a reason for hiding this comment

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

There's a typo in your comment... I'm not sure what you're saying.

Copy link
Member Author

@agrare agrare Aug 24, 2022

Choose a reason for hiding this comment

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

Fixed, it was supposed to be env vars, basically when running cross-repo for the oparin branch the GITHUB_BASE_REF is still master because the PR is created in the cross-repo repository. This is used https://github.com/ManageIQ/manageiq/blob/master/bin/before_install#L25 and will be used by the providers, just means we can't test this easily with cross-repo.

Copy link
Member

Choose a reason for hiding this comment

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

ah... shucks... I just asked below if we can test it with cross repo to see how it works. I guess you can do the old fashioned way and just create a WIP plugin PR to use this code to verify it works.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I just committed a Gemfile.lock.release to bypass the need to copy it from core

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to log the Gemfile.lock before and after patching? Or maybe just the diff? I was hoping to see what this looks like in the CI log.

Gemfile.lock is already logged in CI.

Copy link
Member

Choose a reason for hiding this comment

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

I was more interested in seeing what it changed and less about the full contents.

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

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

I'd like to see an end to end run of this in CI to better understand what's being patched but I like the idea of surgically fixing this for release branches to ensure we're testing with the same gems.

bin/ci/patch_plugin_gemfile_lock Show resolved Hide resolved
with open('Gemfile.lock') as f:
gemfile_lock = f.read()

gemfile_lock_patched = re.compile("GIT\n remote: %s\n revision: .+\n branch: .+\n" %(os.environ['GITHUB_REPOSITORY'])).sub('PATH\n remote: .\n', gemfile_lock)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to log the Gemfile.lock before and after patching? Or maybe just the diff? I was hoping to see what this looks like in the CI log.

with open('Gemfile.lock') as f:
gemfile_lock = f.read()

gemfile_lock_patched = re.compile("GIT\n remote: %s\n revision: .+\n branch: .+\n" %(os.environ['GITHUB_REPOSITORY'])).sub('PATH\n remote: .\n', gemfile_lock)
Copy link
Member

Choose a reason for hiding this comment

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

There's a typo in your comment... I'm not sure what you're saying.

@agrare
Copy link
Member Author

agrare commented Aug 24, 2022

And this is what the diff looks like for the manageiq-providers-autosde plugin:

$ GITHUB_SERVER_URL=https://github.com GITHUB_REPOSITORY=ManageIQ/manageiq-providers-autosde ./bin/ci/patch_plugin_gemfile_lock
$ diff Gemfile.lock Gemfile.lock.release 
99,100c99,102
< PATH
<   remote: .
---
> GIT
>   remote: https://github.com/ManageIQ/manageiq-providers-autosde
>   revision: 1939a10c1aa1e58e0a89684c59f16b4c114f363e
>   branch: oparin

So the new block looks like this:

PATH
  remote: .
  specs:
    manageiq-providers-autosde (0.1.0)
      autosde_openapi_client (~> 1.1.0)
      typhoeus (~> 1.4)

@bdunne
Copy link
Member

bdunne commented Aug 24, 2022

And this is what the diff looks like for the manageiq-providers-autosde plugin:

$ GITHUB_SERVER_URL=https://github.com GITHUB_REPOSITORY=ManageIQ/manageiq-providers-autosde ./bin/ci/patch_plugin_gemfile_lock
$ diff Gemfile.lock Gemfile.lock.release 
99,100c99,102
< PATH
<   remote: .
---
> GIT
>   remote: https://github.com/ManageIQ/manageiq-providers-autosde
>   revision: 1939a10c1aa1e58e0a89684c59f16b4c114f363e
>   branch: oparin

So the new block looks like this:

PATH
  remote: .
  specs:
    manageiq-providers-autosde (0.1.0)
      autosde_openapi_client (~> 1.1.0)
      typhoeus (~> 1.4)

Will the bundle install in the ruby setup update any dependencies under specs: if they have changed in the plugin gemspec?

@agrare
Copy link
Member Author

agrare commented Aug 25, 2022

Will the bundle install in the ruby setup update any dependencies under specs: if they have changed in the plugin gemspec?

You mean like if a plugin updated their gemspec but we didn't update the Gemfile.lock? The bundle install will fail since it can't resolve the dependencies until we update Gemfile.lock which is what we want rather than silently succeeding but not using the right gem versions.

Ran a test to show this, I downgraded the resolved autosde_openapi_client to 1.0.54 in the Gemfile.lock where the spec requires ~> 1.1.0: https://github.com/ManageIQ/manageiq-providers-autosde/runs/8016809143?check_suite_focus=true#step:5:49

@agrare agrare force-pushed the dont_setup_gemfile_lock_plugins branch 2 times, most recently from 23ef482 to 78b3650 Compare August 31, 2022 16:57
@Fryguy Fryguy self-assigned this Aug 31, 2022
@agrare agrare force-pushed the dont_setup_gemfile_lock_plugins branch from 78b3650 to 8f51075 Compare September 1, 2022 16:48
@agrare
Copy link
Member Author

agrare commented Oct 3, 2022

@Fryguy what do you think about this?

@miq-bot miq-bot added the stale label Feb 27, 2023
@miq-bot
Copy link
Member

miq-bot commented Feb 27, 2023

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s)

Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation.

@kbrock
Copy link
Member

kbrock commented May 24, 2023

@Fryguy you good to merge?

@kbrock kbrock self-assigned this May 24, 2023
@kbrock
Copy link
Member

kbrock commented May 31, 2023

Is this good to go?

@Fryguy
Copy link
Member

Fryguy commented Jun 5, 2023

Honestly I don't remember - this was a cross-repo thing, but I'm not sure it's needed?

@agrare
Copy link
Member Author

agrare commented Jun 5, 2023

@Fryguy this wasn't cross repo, the issue here is that when running specs on release branches on GHA plugins are not using the Gemfile.lock.release In this case this caused the scheduled CI runs to be green where the tests should have actually failed. (PR description does a better job of explaining the issue)

@Fryguy
Copy link
Member

Fryguy commented Jun 5, 2023

Ok thanks - I double checked and Ruby is installed by default in GHA, so this could be a ruby script:

See https://github.com/Fryguy/sandbox/actions/runs/5178658485/jobs/9330435149#step:10:18 (installed version is ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu])

@Fryguy Fryguy removed the stale label Jun 5, 2023
@agrare
Copy link
Member Author

agrare commented Jun 5, 2023

Hm must have been added since I originally tested this (has been almost a year I guess so that makes sense). Okay I'm going to have to rewrite and retest this then

@agrare agrare force-pushed the dont_setup_gemfile_lock_plugins branch from 8f51075 to 432e8cd Compare July 21, 2023 17:30
@Fryguy
Copy link
Member

Fryguy commented Jul 21, 2023

I thought setup_gemfile_lock was also called in core bin/setup, so specs would use it. But I don't see that here. 🤔

@kbrock
Copy link
Member

kbrock commented Jul 21, 2023

Yea, I can only find it within this file.
I'd feel more comfortable with this merged.
The current code (before merge) definitely opens us up to versioning nuances

@kbrock
Copy link
Member

kbrock commented Sep 28, 2023

ok, trying to follow this thread

in development, setup_gemfile_lock is not called. so bin/setup and bin/update are not changed.

in ci, bin/setup => manageiq_plugin_setup => manageiq_plugin_update => setup_gemfile_lock
So bin/before_install will need to be changed to call this new script.

It was moved into that script so the gemfile.lock can be setup before all this ruby processing.

I'm 👍 on this. We just need to update the 35 repos with this change

so this is WIP: rewrite in ruby?
It is short enough that maybe keeping in python may be more future proof.

ugh. do we just revisit this every 6-12 months?

@agrare
Copy link
Member Author

agrare commented Oct 11, 2023

I haven't had time to rewrite the script in ruby and retest this whole thing. Are we 👎 on a python script? Is that a blocker for merge?

@agrare agrare force-pushed the dont_setup_gemfile_lock_plugins branch from 432e8cd to 21f8197 Compare October 11, 2023 12:24
@Fryguy
Copy link
Member

Fryguy commented Oct 11, 2023

We were just waiting on a rewrite to Ruby. We can merge now with python and change in a follow up.

Separately we need a change to all of the plugins bin/before_install. However, alternatively we may want to move towards running a shared bin/before_install from core. I had started that work but never finished it.

@kbrock
Copy link
Member

kbrock commented Oct 16, 2023

Think I vote keeping python and moving script to manageiq/bin/{ci/}?patch_plugin_gemfile_lock.
So all subprojects will call this single script.

not sure if it will be tricky to link in the ci.yaml file. Maybe as simple as rspec/manageiq/bin/...

@Fryguy
Copy link
Member

Fryguy commented Oct 16, 2023

I was about to merge but noticed the python script doesn't modify the Gemfile.lock.release, but instead modifies Gemfile.lock. Not sure I understand how that's supposed to work?

@agrare
Copy link
Member Author

agrare commented Oct 16, 2023

I was about to merge but noticed the python script doesn't modify the Gemfile.lock.release, but instead modifies Gemfile.lock. Not sure I understand how that's supposed to work?

Guess I need a better PR description, the problem I was trying to solve was that plugin specs on release branches weren't running with the gems that were in the Gemfile.lock.release because bundler saw the Gemfile.lock as invalid due to the plugin local path override and would bundle update everything.

This script patches the Gemfile.lock after it was copied from Gemfile.lock.release but before bundle install is run.

@kbrock
Copy link
Member

kbrock commented Oct 20, 2023

ok. did that clear up the confusion.
Is this ready to go?

Or at least ready to blast out all child projects to point to this common script?

@Fryguy
Copy link
Member

Fryguy commented Oct 20, 2023

@agrare ok that part makes sense, but the "copy Gemfile.lock.release to Gemfile.lock" line was removed here https://github.com/ManageIQ/manageiq/pull/22075/files#diff-3407d3d6c1f5822da11eac8ba10639efe824e11d65c8bd19ce034253ea124eb9L85. Or is this relying on the core bin/before_install (

# Gemfile.lock.release only applies to non-master branches and PRs to non-master branches
if [[ "$GITHUB_REPOSITORY_OWNER" = "ManageIQ" && "$GITHUB_BASE_REF" != "master" && "$GITHUB_REF_NAME" != "master" && "$GITHUB_REF_NAME" != "dependabot/"* ]]; then
echo "== Setup Gemfile.lock.release =="
cp -f "$APP_ROOT/Gemfile.lock.release" "$APP_ROOT/Gemfile.lock"
echo
fi
) somehow in the plugin repos?

@miq-bot miq-bot added the stale label Jan 22, 2024
@miq-bot
Copy link
Member

miq-bot commented Jan 22, 2024

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s).

@agrare agrare force-pushed the dont_setup_gemfile_lock_plugins branch from 21f8197 to 206b325 Compare March 11, 2024 18:26
@miq-bot
Copy link
Member

miq-bot commented Mar 11, 2024

Checked commits agrare/manageiq@508107c~...206b325 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
1 file checked, 0 offenses detected
Everything looks fine. 👍

setup_gemfile_lock if ci?

Copy link
Member

@kbrock kbrock Mar 11, 2024

Choose a reason for hiding this comment

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

alternatively, if we want to make a slow transition, we can run this unless we are running build version 2:

setup_gemfile_lock if ci? && ENV["BUILD"] != "v2"

and when we upgrade the github/ci.yaml we can set an env BUILD=v2 when we upgrade the ci.yaml to call bin/ci/patch_plugin_gemfile_lock

@miq-bot
Copy link
Member

miq-bot commented Apr 26, 2024

This pull request is not mergeable. Please rebase and repush.

@miq-bot
Copy link
Member

miq-bot commented Jul 29, 2024

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s).

1 similar comment
@miq-bot
Copy link
Member

miq-bot commented Nov 1, 2024

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s).

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.

6 participants