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

add tool for pushing vendor updates to consuming repos easier #687

Merged
merged 1 commit into from Oct 6, 2020

Conversation

dhellmann
Copy link
Contributor

No description provided.

@dhellmann
Copy link
Contributor Author

/cc @elmiko @JoelSpeed

hack/push_updates.sh Outdated Show resolved Hide resolved
if [ -z "$SHA" ]; then
echo "Determining SHA for machine-api-operator repository..."
hub clone openshift/machine-api-operator
(cd ./machine-api-operator && git checkout origin/$BRANCH_NAME)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should not be done in a temporary directory, and additionally cleaned up after completion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a temporary directory, see lines 86-87.

I didn't add a trap to clean it up because @elmiko wanted it to run in a container, and I figured everything would be removed when the container is removed. Maybe that assumption isn't safe or some folks will run this outside of the container?

Copy link
Contributor

Choose a reason for hiding this comment

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

i certainly don't want to see us do extra work just for the container option. that said, it should be relatively safe to leave artifacts in a temporary directory as it will get cleaned by the o/s as needed. additionally it might help for debugging to have the artifacts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It certainly helped while developing the script. :-)

# Push updates that need to be vendored in other repositories.

if ! which hub 2>/dev/null 1>&2; then
echo "This tool requires the hub command line app." 1>&2
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible just to use git tool?.. Don't know all the details, but from visual inspection, it is possible to replicate all commandls with git clone and git remote add ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

git can't create the fork if you don't already have it

Copy link
Contributor

@elmiko elmiko left a comment

Choose a reason for hiding this comment

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

this looks really nice to me, thanks Doug!

definitely think we should get Joel's thoughts, but he is out till next week.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 26, 2020
@dhellmann
Copy link
Contributor Author

/retest

Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Looks good. My only concern is about the SHA length causing long commit messages and long branch names, should we always truncate to a 7 digit short commit SHA to prevent these long messages? Should still work with short SHAs right?

Comment on lines 36 to 38
-s SHA
The SHA from machine-api-operator repository to push.
Defaults to HEAD of master.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need a full SHA or will it work with the 7 character short SHA? Might be worth a note in the help if it supports one and not the other

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's actually any reference, but it seemed safer to suggest using a SHA because if you just pass "HEAD" or a branch name then the commit message wouldn't be very meaningful. The short SHA should be OK.

hub clone openshift/$repo
pushd ./$repo

hub fork --remote-name $REMOTE_NAME
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this succeed if there is already a fork?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it recognizes the fork even if it has a different name and sets up the remote appropriately.

hack/push_updates.sh Outdated Show resolved Hide resolved
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 3, 2020
@JoelSpeed
Copy link
Contributor

I think I'm happy with this as is now, would be good to see it in action (maybe dry run?) so we can verify it works before merging, what do people think?

@dhellmann
Copy link
Contributor Author

I think I'm happy with this as is now, would be good to see it in action (maybe dry run?) so we can verify it works before merging, what do people think?

Sure, that makes sense. Do you want me to do that and link to some PRs, or do you want to give it a spin to see how it behaves first hand?

/retest

@JoelSpeed
Copy link
Contributor

Just cloned this myself to have a play, not sure how important these are but some observations:

  • You can't get the help text without hub installed
  • The name of the script uses an underscore, our convention for this is hyphens (all bar 1 other are hyphens)
  • Using dry run, I got an error Error creating fork: JoelSpeed/cluster-api-provider-azure already exists on github.com which I wasn't expecting to see, this caused the script to exit. My CAPZ fork is directly from kubernetes-sigs, not from the openshift fork, I wonder how many people will have that problem or if there is a workaround 🤔
  • Commit message was Update machine-api-operator to 8f5ef9 for AWS, looks good, had intended to have 7 chars but my suggestion should have been ${SHA:0:7} instead for 7 characters, not sure how many we want?
  • The AWS clone, update commit all seemed to work well :)

@dhellmann
Copy link
Contributor Author

Just cloned this myself to have a play, not sure how important these are but some observations:

  • You can't get the help text without hub installed

Fixed

  • The name of the script uses an underscore, our convention for this is hyphens (all bar 1 other are hyphens)

Fixed

  • Using dry run, I got an error Error creating fork: JoelSpeed/cluster-api-provider-azure already exists on github.com which I wasn't expecting to see, this caused the script to exit. My CAPZ fork is directly from kubernetes-sigs, not from the openshift fork, I wonder how many people will have that problem or if there is a workaround 🤔

I changed the logic so the fork isn't created in dry-run mode.

I think if you create a fork yourself using a different repository name the hub command will use the Github API to figure that out. I could also see if I can make it try a simple clone if the fork fails.

  • Commit message was Update machine-api-operator to 8f5ef9 for AWS, looks good, had intended to have 7 chars but my suggestion should have been ${SHA:0:7} instead for 7 characters, not sure how many we want?

I switched to using the abbreviated hash computed by git instead of truncating it in the script.

  • The AWS clone, update commit all seemed to work well :)

@dhellmann
Copy link
Contributor Author

I think if you create a fork yourself using a different repository name the hub command will use the Github API to figure that out. I could also see if I can make it try a simple clone if the fork fails.

On second thought, I'm not sure that's actually possible.

I wonder if because of the error handling we would actually want the script to run in 2 different phases. First to build all of the patches, and then either a second run to submit them or just leave it up to the user to submit them (and automate submission separately when we put this into a prow job).

Thoughts?

Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

I switched to using the abbreviated hash computed by git instead of truncating it in the script.

+1 for this

I think the fallback to simple clone looks good, I haven't tested it, but I think it should work. I personally would prefer to keep the script so that it automates the whole thing. If I have to delete some of my forks and have them properly forked from the openshift forks to make that work, I think that's a sacrifice I'd be willing to make.


# Use -d option to avoid build errors because we aren't going to
# build locally.
go get -d github.com/openshift/machine-api-operator@${FULL_SHA}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think FULL_SHA is initialised when SHA is set explicitly, looks like it's only set when SHA is empty and we work it out in the script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed that, and also split the operation into 2 loops as we discussed in the meeting this morning.

@JoelSpeed
Copy link
Contributor

@dhellmann Used the script earlier and it pretty much worked a treat! (https://bugzilla.redhat.com/show_bug.cgi?id=1877743) Had to manually fix one up because they're using a replace for one of the dependencies, and I had to set github.user in my git config, but then the fallback to simple clone worked as well.

Only thing I will say is that it doens't look like ovirt is in a place where they need this script just yet, might be worth dropping them from the defaults for now.

From this experience, future improvement ideas:

  • Reuse an existing directory: In case of failure, could re-use existing cloned resources?
  • Allow a PR description to be provided
  • Pause on commit failure to allow you to fix up, then continue?

@dhellmann
Copy link
Contributor Author

@dhellmann Used the script earlier and it pretty much worked a treat! (https://bugzilla.redhat.com/show_bug.cgi?id=1877743) Had to manually fix one up because they're using a replace for one of the dependencies, and I had to set github.user in my git config, but then the fallback to simple clone worked as well.

I think I assumed the GitHub.user setting was part of configuring hub, but apparently not. It looks like the script could read ~/.config/hub instead. At the very least we could have it require the user to set up the git config it's expecting.

Only thing I will say is that it doens't look like ovirt is in a place where they need this script just yet, might be worth dropping them from the defaults for now.

Makes sense.

From this experience, future improvement ideas:

  • Reuse an existing directory: In case of failure, could re-use existing cloned resources?

I thought about making it create the working directory with the SHA in the name, so it could find it again later. Then it could skip building the patch if it sees a cloned repo in that predictable temp directory, assuming that the user would have fixed whatever caused the failure before running again. What do you think?

  • Allow a PR description to be provided

Definitely.

  • Pause on commit failure to allow you to fix up, then continue?

See above

@dhellmann
Copy link
Contributor Author

I rebased, squashed, and removed ovirt from the list of repositories.

@dhellmann
Copy link
Contributor Author

/retest

@JoelSpeed
Copy link
Contributor

/approve

Thanks @dhellmann

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JoelSpeed

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

The pull request process is described here

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 21, 2020
Copy link
Contributor

@elmiko elmiko left a comment

Choose a reason for hiding this comment

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

looks mostly good to me, just had one question


function fork_repo () {
local repo_name="$1"
local remote_name="$2"
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems like remote_name is unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

d'oh, it's using REMOTE_NAME below instead of the local variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

i figured it had to be one or the other XD

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the extra variable.

Copy link
Contributor

@elmiko elmiko 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-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

12 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@JoelSpeed
Copy link
Contributor

/hold

This will just keep retesting unnecessarily until it's merged

Do we want to get this merged before master opens or do we not really care?

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 22, 2020
@dhellmann
Copy link
Contributor Author

It doesn't really make any difference to me, so if you'd like to wait that's fine.

@JoelSpeed
Copy link
Contributor

Saves us having to create a BZ, so let's just hold cancel when master opens, we can all use it from here until then

Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 22, 2020
@elmiko
Copy link
Contributor

elmiko commented Sep 22, 2020

just wanted to note that i tried the script out in dry run mode today and everything is working as i would expect.

@JoelSpeed
Copy link
Contributor

/hold cancel

I think this should be able to merge now that the 4.6 branch has been cut 🤔

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 5, 2020
@elmiko
Copy link
Contributor

elmiko commented Oct 5, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 5, 2020
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

3 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit d3599f4 into openshift:master Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants