Skip to content

New CLI option: --run-make to run make and commit changes#24

Merged
openshift-merge-bot[bot] merged 2 commits intomainfrom
makefile
Nov 22, 2024
Merged

New CLI option: --run-make to run make and commit changes#24
openshift-merge-bot[bot] merged 2 commits intomainfrom
makefile

Conversation

@EmilienM
Copy link
Copy Markdown
Contributor

@EmilienM EmilienM commented Nov 11, 2024

Some projects need to run custom tasks when merging with upstream, like
vendoring or code generation. Let's try to run make merge-bot
If the target doesn't exist we return an error.

Example on where it'll be used: openshift/cluster-api-provider-openstack#332

This feature can be used through a new CLI option: --run-make.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Nov 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: EmilienM

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@EmilienM
Copy link
Copy Markdown
Contributor Author

/assign pierreprinetti
per our conversation

@EmilienM
Copy link
Copy Markdown
Contributor Author

/test

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Nov 11, 2024

@EmilienM: The /test command needs one or more targets.
The following commands are available to trigger required jobs:

  • /test images
  • /test lint
  • /test unittests

Use /test all to run all jobs.

Details

In response to this:

/test

Instructions 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.

@EmilienM
Copy link
Copy Markdown
Contributor Author

/test cluster-api-provider-openstack-main

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Nov 11, 2024

@EmilienM: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test images
  • /test lint
  • /test unittests

Use /test all to run all jobs.

Details

In response to this:

/test cluster-api-provider-openstack-main

Instructions 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.

Comment thread src/merge_bot/merge_bot.py Outdated
logging.debug(f"make merge-bot output: {proc.stdout.decode()}")
except subprocess.CalledProcessError as err:
if "No rule to make target" not in err.stderr.decode():
raise RepoException(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we really raise a RepoException when the repository doesn't have a make merge-bot target, and trigger a Manual intervention is needed to merge {source} into {dest} message on slack? IMO, we should log what happens but not send update to slack, so perhaps raise a different exception type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that was a bad copy paste.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  • If the repo doesn't have merge-bot target, just move on: no error at all.
  • If the repo has the target but running it failed, we send an error but we also send an update on Slack saying that manual intervention is needed in the PR. I think it's fine this way.

Comment thread src/merge_bot/merge_bot.py Outdated
if update_go_modules:
commit_go_mod_updates(gitwd)

run_make(gitwd)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we more this under the if update_go_modules: conditional just above? Also it feels like we want run_make() to run before commit_go_mod_updates()

Perhaps this would be good to split the functions, and have them only generate updated content, then in a separate function commit the new content if there is anything to commit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have to run make after go mod is updated in order to update all assets after go vendoring was updated.
Also I don't want to add the make block within the go block since any repo could have this Makefile target, so let's make them separate in that order.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please move run_make(gitwd) in the if update_go_modules: branch. This ensures we don't accidentally create commits unless the user wants us to re-generate code and vendoring.

https://github.com/shiftstack/merge-bot/blob/main/src/merge_bot/cli.py#L164-L169

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the run_make is not only for go projects. Any project could have a merge-bot target they want to run when merging. Isn't?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Then make a new option. I believe the intention is that by default we don't add more commits that the one we merge from the upstream repository. @mdbooth @pierreprinetti, any thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm happy with a new function. I'll wait for Pierre & Matt in case they have any feedback otherwise I'll propose it by end of week.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've done the change Martin.

@EmilienM EmilienM force-pushed the makefile branch 3 times, most recently from 71acefe to 28b9d30 Compare November 14, 2024 16:46
@EmilienM EmilienM changed the title Using make as a new hook New CLI option: --run-make to run make and commit changes Nov 22, 2024
Some projects need to run custom tasks when merging with upstream, like
vendoring or code generation. Let's try to run `make merge-bot`
If the target doesn't exist we return an error.

Example on where it'll be used: openshift/cluster-api-provider-openstack#332

This feature can be used through a new CLI option: `--run-make`.
* use Fedora
* install make, git, difftools so we can run make and dependencies
  needed in the future to run make in our projects.
Copy link
Copy Markdown
Contributor

@mandre mandre left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci Bot added the lgtm label Nov 22, 2024
@openshift-merge-bot openshift-merge-bot Bot merged commit 85165be into main Nov 22, 2024
@openshift-merge-bot openshift-merge-bot Bot deleted the makefile branch November 22, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants