decaporg / decaporg/decap-cms

Request: Support for Scoping by Branch

Open
#1,737 30 comments 31 reactions 0 assignees View on GitHub
pinned
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

**Is your feature request related to a problem? Please describe.**

I think it would be useful to support environment-specific branches.

It is perfectly easy to set up Netlify to deploy multiple branches of the same project, so you can easily have three separate environments easily enough. In the following discussion I will use Gatsby, but I think this problem applies to whatever static site builder you are using.

- **dev** When running locally on localhost
- **staging** A staging branch added to Netlify as an additional branch deploy.
- **production** A production branch added to Netlify as the production branch.

If we weren't using Netlify CMS, this would be all we would need. We could develop locally and push to staging when we wanted to make changes available, then promote by merging staging into production and pushing to the production brancg when these changes are ready.

However, out of the box all these environments will be using the same `config.yml`, meaning all three will load from and make changes to the same branch - whichever branch you have defined as the value for `branch`. Assuming your `branch` is set to `production` then a change made by a dev locally is propagated to production which is obviously not tennable.

What is needed is a way to isolate content changes to each environment, so that changes made in development are made to a `dev` branch, changes made on staging are made to a `staging` branch and changes made on production are made to a `production` branch.

[1]: https://www.netlifycms.org/docs/add-to-your-site/#editorial-workflow

**Describe the solution you'd like**

I think it would make sense for Netlify-CMS to support the ability to enable automatic population of `branch` field with name of current Git branch, for example:
```yml
branch: auto
```
So assuming the `staging` branch is being deployed by Netlify to a staging URL, on staging `branch` is set to `staging`, meaning any changes made on staging are kept within the `staging` branch. It would probably make sense to allow more control over mappings of branch to environment, for example supporting some kind of map that decides the branch based on a regex run on the branch name, for example any branch prefixed with `hotfix-` would use the `staging` branch.

[Edit] Netlify offers the concept of 'Contexts' ([here](https://www.netlify.com/docs/continuous-deployment/#deploy-contexts)) which sound perfect for this. They can be used to set an Env based on branch. So all that is necessary is for Netlify CMS to check for a predetermined env, for example `NETLIFY_BRANCH` before falling back to the `branch` defined in the `config.yml`.

**Describe alternatives you've considered**

This can be currently only be achieved by deploying an environment-specific `config.yml` to each remote environment, and defaulting to a `dev` branch in development. Probably the easiest way to do this is to use a pre-build step to populate the `branch` field your `config.yml` with the name of the current branch, however this adds additional complexity and obfuscation. I think this should be declarable in Netlify's `config.yml`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.