Skip to content

Fix prebuild open #14019

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

Merged
merged 2 commits into from
Oct 25, 2022
Merged

Fix prebuild open #14019

merged 2 commits into from
Oct 25, 2022

Conversation

nVitius
Copy link
Contributor

@nVitius nVitius commented Oct 20, 2022

Description

Made this PR in an effort to address some issues I ran into with prebuilds.
I don't know how to test the changes I made in workspace-factory.ts. The original pull request that had changes to that block of code (#13768) didn't have any unit tests, so I wasn't sure where to add some.

Related Issue(s)

Fixes #14017

How to test

  • Create new prebuild
  • Open workspace from either the branches tab or the specific prebuild page
  • Prebuild should load correctly and the branch should be checked out in git

Release Notes

Check out the correct branch when opening a prebuild for a commit that is also the latest HEAD of the context branch

Documentation

Werft options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-integration-tests=all
    Valid options are all, workspace, webapp, ide

@nVitius nVitius requested a review from a team October 20, 2022 07:56
@werft-gitpod-dev-com
Copy link

annotations in the pull request changed, but user is not allowed to start a job

@nVitius
Copy link
Contributor Author

nVitius commented Oct 20, 2022

@jankeromnes Pinging you as you're the author of the PR that originally implemented this feature.

@jankeromnes
Copy link
Contributor

jankeromnes commented Oct 21, 2022

Hi @nVitius! 👋 Wow, many thanks for this contribution 👀 I'm happy to take a look today and help move this forward. ⏩

I see that you're already aware that there was a different bug #13991, where the original Git context (branch, commit) of the Prebuild was being kept in place, instead of being updated to whichever Git context is mandated by the context URL (e.g. new branch, new commit...)

However, you're probably right that this might be different and related to the new bit of code that I don't fully understand yet.

I'll start by triggering a CI build for your PR (so that we can test your changes) and by trying to reproduce your specific issue.

/werft run

👍 started the job as gitpod-build-fix-prebuild-open-fork.0
(with .werft/ from main)

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-fix-prebuild-open.0 because the annotations in the pull request description changed
(with .werft/ from main)

@jankeromnes
Copy link
Contributor

Note: The CI says that the build failed, but I notice that it actually started two builds:

I guess this is a CI bug, but we can simply ignore the first build and focus exclusively on the second.

@laushinka laushinka added the do-not-merge/cla-pending CLA has not been signed label Oct 21, 2022
@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-fix-prebuild-open.1 because the annotations in the pull request description changed
(with .werft/ from main)

@vulkoingim
Copy link
Contributor

vulkoingim commented Oct 21, 2022

/werft run

👍 started the job as gitpod-build-fix-prebuild-open-fork.1
(with .werft/ from main)

@jankeromnes
Copy link
Contributor

jankeromnes commented Oct 21, 2022

Okay, here is a preview environment that actually works (sorry for the CI troubles, and thanks @vulkoingim for the help!)

EDIT: Whoops, looks like the preview environment got garbage collected a bit too eagerly 🤦 this seems to happen every hour for custom CI builds (which we need here because regular CI builds don't currently work with forks). Anyway, I'll trigger a new build this afternoon and resume testing. 🤞

EDIT 2: Here we go again:

Comment on lines +379 to +380
CommitContext.computeHash(context.originalContext) !==
CommitContext.computeHash(buildWorkspace.context)
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that you're using CommitContext.computeHash here instead of using context.originalContext.revision directly. I guess this adds support for the case where:

  • The prebuild was created for a multi-repo project
  • The main repo's branch HEAD is still the same commit as the prebuild
  • However, one of the dependent repos' branch now has a different commit

However, do we actually want to delete the ref in this case? 🤔 I'm not fully certain of the consequences on the additional repositories.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, on a side note, would you be okay with using a single if statement with 3 conditions, instead of two nested if blocks? (But I'm aware that's mostly personal preference, so please feel free to disregard this suggestion.)

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 wanted to make sure that the original logic was still available in the case that CommitContext.is(context.originalContext) was not true.

I wasn't sure that originalContext would always be a CommitContext and didn't want to break anything since there weren't specific unit tests for that block.

If you think it looks good, I can update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting that you're using CommitContext.computeHash here instead of using context.originalContext.revision directly.

I saw it being used elsewhere when reading through some code and it made sense... I hadn't looked at the Interface for CommitContext too closely nor the definition for computeHash. Makse sense to me to use revision instead. Let me know what you think and I can make that change.

Copy link
Contributor

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

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

Tested and works like a charm! ✨ Many thanks for this impressive contribution. 🎯 I'm happy that I got to better understand what this code does / what its consequences are.

Adding a temporary hold for the merge-bot while we figure out the CLA. Have we already been in touch about this? If not I'm happy to help resolve this.

@jankeromnes
Copy link
Contributor

Actually adding the hold (I forgot):

/hold

@nVitius
Copy link
Contributor Author

nVitius commented Oct 21, 2022

Adding a temporary hold for the merge-bot while we figure out the CLA. Have we already been in touch about this? If not I'm happy to help resolve this.

Haven't received anything about the CLA. Let me know what I need to do that. I'm also on the Discord server for Gitpod if it makes it easier to coordinate that.

@jankeromnes
Copy link
Contributor

Haven't received anything about the CLA. Let me know what I need to do that. I'm also on the Discord server for Gitpod if it makes it easier to coordinate that.

Sure! I've asked internally, and it looks like we'd need you to sign the following form:

https://powerforms.docusign.net/30e1aa46-cce5-4bc6-a933-ad02cd8d5ada?env=eu&acct=86335c2c-01b9-4edc-a187-014f5150a112&accountId=86335c2c-01b9-4edc-a187-014f5150a112

Could you please take a look when you have some time, and sign it if it looks good to you? Please do let me know if you have any questions about this.

@nVitius
Copy link
Contributor Author

nVitius commented Oct 24, 2022

@jankeromnes Thanks for the link. I signed the CLA.

@jankeromnes
Copy link
Contributor

jankeromnes commented Oct 24, 2022

That's great, many thanks @nVitius! The next step is for @meysholdt to counter-sign and store the CLA, and then this should be good to go. 🚀

Let's also give this PR a green build (so that the merge bot is happy) -- we've already tested this PR in a custom build, so this one doesn't need a preview URL:

/werft run

👍 started the job as gitpod-build-fix-prebuild-open-fork.2
(with .werft/ from main)

@meysholdt
Copy link
Member

hey @nVitius, thank you for signing the CLA!

@roboquat roboquat merged commit cc786bb into gitpod-io:main Oct 25, 2022
@jankeromnes
Copy link
Contributor

jankeromnes commented Oct 25, 2022

Congratulations on your first contribution to Gitpod @nVitius! 🎉 🎉 🎉

And thanks again for going all the way from noticing the bug, to undertanding the code, to fixing the bug, seemingly without any help. 🙏 🤯

@nVitius
Copy link
Contributor Author

nVitius commented Oct 25, 2022

Thanks, @jankeromnes. Happy I could help.

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.

Branch not checked out in prebuild
7 participants