-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 multi branch github deployes by appending branch name for cms pul… #1494
Conversation
Deploy preview for netlify-cms-www ready! Built with commit 3691a3a |
Deploy preview for cms-demo ready! Built with commit 3691a3a |
@@ -138,7 +138,7 @@ export default class GitHub { | |||
const promises = []; | |||
branches.map((branch) => { | |||
promises.push(new Promise((resolve, reject) => { | |||
const slug = branch.ref.split("refs/heads/cms/").pop(); | |||
const slug = branch.ref.split(`refs/heads/${this.api.cms_branch_prefix}`).pop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break sites that don't use master and have existing editorial workflow entries. This kind of backwards compatibility bug is the primary concern with a change like this. We almost need a way to find and transition existing entries, or by some other means ensure that that the change is transparent for existing entries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erquhart Doesn't line 14 in API.js address this concern?
this.cms_branch_prefix = this.branch === 'master' ? 'cms/' : `cms-${this.branch}/`;
It should not affect people that don't use master. It will just keep changes for each main branch separately. Currently things will get mixed and if you have the CMS attached to two different sites each bound to a different branch then changes for one branch get committed to the last branch that commits the workflow. So it will move changes across branches and remove them from the branch they belong to in some cases. |
Rebased. |
I had to rebase which makes the original comment invalid in this thread. Basically the one side of the changes is for the write site into github causing it to make commits of cms- for master and cms-BRANCH- for other branchs. The second file is for reading so it reads the last cms- commit matching the branch it came from. |
You're changing the Example of how this breaks things:
|
@erquhart Yes, but that's the whole point of this patch. When you have two deployments one against master and one against dev with each the cms configured then making changing in dev or master will show up as unpublished entries on the other branch and will get committed on the wrong branch. We have the client work on a deployment in master and we ourselves work on a deployment in dev. When the client has items in their workflow they will see ours and visa versa. So if in dev I work on a certain post of make changes I will all of a sudden see modifications the client has made to the same post and when I merge my changes I will take theirs with it removing them from their change set and workflow. |
Maybe we could then make a little config section in the back end that resolved specific CMS prefix names son only people that need it will get the separate bwhavior |
I changed the implementation to use a custom_branches object to specify the cms prefix. So that way it will not change existing implementations but will allow anyone to configure a multi branch multi deployment setup. backend:
custom_branches:
master: cms-master
dev: cms-dev |
That makes sense, but it's probably worth it to keep this implementation detail internalized. What we need is a better approach to handling metadata, one that allows us to apply these kinds of changes in a backwards compatible fashion. For example, rather than just checking for branches, we should use reproducible metadata to determine which branches were created by Netlify CMS, which also gives us the ability to change how we're naming branches. Still haven't thought through some of the challenges of this approach, like the "reproducible" bit, meaning metadata can always be recreated from a repo if the metadata is deleted for some reason. Note that "metadata" here is referring to one or more files in a branch or ref, which we use to keep track of things. |
Rebased to current master. |
@richtera To be clear, we do really appreciate your work here, even through we're looking at other options as well! |
Using metadata to assign destination branches would be great. I don't know enough about the internals to pull that off myself. Ideally then in the workflow pane you might be able to choose the working branch to peek at other changes and maybe pull them but it might add a lot of complications. |
@tech4him1 Other options would be fine, but currently the new setup makes it pretty much impossible to roll out my patch (because of the lerna repo.) Essentially my requirement is that each netlify deployment (with cms) linked to a branch of a repo should have a standalone workflow. Not doing this was causing changes to be lost all the time because publishing on the wrong branch would move the pull request to the other branch. How about just configuring the cms branch prefix and not supporting multiple ones since each branch has it's own config.yml anyways? Would that be more acceptable? |
Allowing the CMS branch prefix to be customized in the config.yml makes sense to me - we should allow implementors to work around branch name conflicts regardless of the underlying cause. Even with proper metadata in place like @erquhart suggests, we'll likely still want to use a cms-specific prefix for any branches created by the CMS, so it's worth allowing that branch name to be customized if, for whatever reason, it conflicts. I do think that @tech4him1 @erquhart thoughts? Is there a reason we shouldn't make this configurable? We can't reasonably guarantee that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach makes sense to me - @richtera I can write and push the fixes to my review comments to your branch if you'd prefer.
sem.leave(); | ||
resolve(null); | ||
})); | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like something's been truncated here, since this is a syntax error and the function no longer returns anything, and the PR as a whole needs to be formatted by running yarn run format:prettier --write
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking. This was a merge conflict in the branch which I tried to resolve on github. Bad idea.
this.repoURL = `/repos/${this.repo}`; | ||
this.merge_method = config.squash_merges ? 'squash' : 'merge'; | ||
this.branch = config.branch || "master"; | ||
if (config.cms_branch_prefix) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config
argument here is not the value of the config.yml
, it's the argument passed in here: https://github.com/netlify/netlify-cms/blob/master/packages/netlify-cms-backend-github/src/implementation.js#L45-L52. Thus, this isn't actually going to work, though it's very close.
Additionally, I would suggest we use backend.branch_prefix
instead of just cms_branch_prefix
at the top level of the config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I see. I need to fix that I had passed in something else. Fixing.
I like "branch_prefix" as the name. Changing.
cms_branch_prefix: cms-dev | ||
``` | ||
|
||
The default for this value is "cms" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs need to be cleaned up before merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can clean it up, but I am not sure what cleaning is required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the content of the docs here is in the heading, which should just be a short title such as "Custom Branch Name Prefix". The content in the heading should be moved to a short explanatory paragraph, and the 2nd-person voice ("You can configure...", "To enable this feature, you can set...") from earlier in the document should be maintained. A quick note of the reason you might use this (i.e., branch name collisions) would be good too. Thanks!
I'd like to find a way to use the PR base branch, just leaves the problem of determining which PRs were created by the CMS. Sent with GitHawk |
@erquhart I think no matter what you'd need different branch prefixes for multiple source branches since branch names need to be unique and editing the same slug in both branches would still cause a conflict, but maybe there is a workaround there. |
We could use some kind of shortened unique id. A timestamp could even work for our purposes. I'll give this a think tomorrow. Sent with GitHawk |
I think this is the next step: #1669 |
Gave this another look and it really is a simple enough change. @Benaiah I think I missed your comment on the first pass, agreed. I do think @richtera if you can push that change I'll get this merged. |
@erquhart I still says changes are requested but as far as I know those were changed. Not quite sure how to make sure all the right things have been committed. I simplified this to branch_prefix inside of backend |
It needs to be Sent with GitHawk |
Ah perfect. I will do it tomorrow morning. The review links always refer to really old stuff for some reason :) |
@Benaiah I pushed another commit, please sanity check and merge if good. |
Ah cool. I overlooked the one change I like removing the / from the setting |
Added support to name space the CMS_BRANCH_PREFIX by including the branch name for non-master branches. This allows multiple deployments to each user their own branch and their own pull requests.