Add --always-run-hooks flag to run lifecycle hooks even when no rebase is needed#67
Conversation
|
Hi @mpryc. Thanks for your PR. I'm waiting for a openshift-eng member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
This change is required to achieve the full rebase process for all OADP modules described in: Some modules need dependency updates to reference freshly rebased upstream versions, even when the modules themselves have no upstream changes requiring a rebase. |
|
/hold - need to add one more condition where destination branch already contains the change which is being made by hook (no rebase situation). |
|
/assign @RadekManak |
4d2916d to
e53ef05
Compare
|
/unhold |
|
/ok-to-test |
RadekManak
left a comment
There was a problem hiding this comment.
I guess the feature makes sense. Please take more time reviewing llm generated code before submitting.
| ``` | ||
|
|
||
| Example 3. Rebasebot usage in OpenShift CI pipeline. | ||
| Example 3. Run Go module updates even when no rebase is needed. |
There was a problem hiding this comment.
Let's keep the examples minimal the main readme. I don't think the feature needs example.
| args.post_rebase_hook = [hook_ref] | ||
| args.pre_carry_commit_hook = None | ||
| args.pre_push_rebase_branch_hook = None | ||
| args.pre_create_pr_hook = None |
There was a problem hiding this comment.
Each hook should create different sentinel file to test all were executed.
| assert passed_gh_app_provider._cloner_app_credentials.app_id == 137497 # default value | ||
| assert passed_gh_app_provider._app_credentials.app_key == b'some cool content' | ||
| assert passed_gh_app_provider._cloner_app_credentials.app_key == b'some cool content' | ||
|
|
There was a problem hiding this comment.
I don't see the value of these tests. They are way too confusing for the little benefit of ensuring that the argument parsing works. We use an external library for parsing anyway. I think we should remove these.
| # Case 4: we created a PR, but no changes were done to the repos after that. | ||
| # Just infrom that the PR is in a good shape. | ||
| message = f"PR {pr_url} already contains the latest changes" | ||
| elif pr_url is not None and pr_url != "": |
There was a problem hiding this comment.
I don't think this function needs always_run_hooks as parameter.
| f"{ex}", | ||
| ) | ||
| return False | ||
|
|
There was a problem hiding this comment.
I don't think there is a need to run. Pre push and pre PR hooks if we are in dry_run. I would expected these to interact with the network since they also depend on external factors like PR being open or branch pushed.
Keeping the dry_run cutoff in one place makes the code cleaner.
There was a problem hiding this comment.
@mpryc Everything below this is behind if(dry_run): This is in unnecessarily complex.
Revert:
if dry_run:
logging.info("Dry run mode is enabled. Do not create a PR.")
return True
push_required = _is_push_required(gitwd, rebase) if needs_rebase else False
And then you can clean up the dry run checks below.
|
|
||
| Enable this behavior with the opt-in `--always-run-hooks` flag: | ||
|
|
||
| ```txt |
There was a problem hiding this comment.
This does not need codeblock exampe example since it is just a bool param.
…e is needed This enables users to run maintenance tasks, dependency updates, and code generation hooks regardless of whether upstream changes require a rebase. Signed-off-by: Michal Pryc <mpryc@redhat.com> Co-Authored-By: Claude <noreply@anthropic.com>
1. Cleaned up README.md to remove unnecessary examples. 2. Removed always_run from the _report_result 3. Dry run does not trigger Pre push and Pre PR hooks 4. Removed unnecessary tests for new flag 5. Modified tests to include different sentinel files 6. Updated tests to cover above fixes Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Michal Pryc <mpryc@redhat.com>
e53ef05 to
c431f4a
Compare
| f"{ex}", | ||
| ) | ||
| return False | ||
|
|
There was a problem hiding this comment.
@mpryc Everything below this is behind if(dry_run): This is in unnecessarily complex.
Revert:
if dry_run:
logging.info("Dry run mode is enabled. Do not create a PR.")
return True
push_required = _is_push_required(gitwd, rebase) if needs_rebase else False
And then you can clean up the dry run checks below.
| @@ -635,14 +658,13 @@ def _report_result(needs_rebase: bool, pr_available: bool, pr_url: str, dest_url | |||
| # We updated the exiting PR. | |||
| message = f"I updated existing rebase PR: {pr_url}" | |||
| else: | |||
There was a problem hiding this comment.
This is missing a case when updating existing PR, but only hooks made updates.
There was a problem hiding this comment.
@RadekManak I have made changes and tested - works great on the project where no changes were during rebase, but only hooks made changes, however there is one part which I hope won't break others:
The check if push is required is now happening without if needs_rebase, so always it's being executed to see if actual push is requied.
- Always check actual git diffs instead of needs_rebase flag to determine
if push/PR is required, fixing bug where hook-generated changes weren't
pushed when --always-run-hooks is enabled and no rebase was needed
- Simplify dry_run handling by checking early and returning, removing
nested dry_run conditionals throughout the code
- Add missing case in _report_result for when hooks update an existing PR
(Case 4: hooks made changes to existing PR)
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Michal Pryc <mpryc@redhat.com>
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mpryc, RadekManak The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Summary
--always-run-hooksCLI flag to enable hook execution even when no rebase is requiredKey Changes
CLI & Core Logic
--always-run-hooksopt-in flag incli.pybot.pyto run main lifecycle hooks even without rebase when flag is enabledTesting
Documentation
Use Cases
This feature enables scenarios like:
Behavior
When
--always-run-hooksis enabled:--update-go-modules) execute as usualCo-Authored-By: Claude noreply@anthropic.com