7

At work, we're now using GitHub, and with that GitHub flow. My understanding of GitHub flow is that there is a master branch and feature branches. Unlike git flow, there is no develop branch.

This works quite well on projects that we've done, and simplifies things.

However, for our products, we have a development and production environment. For the production environment, we use the master branch, whereas for the development environment we're not sure how to do it?

The only idea I can think of is:

  1. When a branch is merged with master, redeploy master using GitHub actions.
  2. When another branch is pushed, set up a GitHub action so that any other branch (other than master) is deployed to this environment.

Currently, for projects that require a development environment, we're essentially using git flow (features -> develop -> master).

Do you think my idea is sensible, and if not what would you recommend?

Edit:

Just to clarify, I'm asking the best way to implement development with GitHub Flow and not git flow.

Nathan Sainsbury
  • 313
  • 2
  • 10

4 Answers4

7

In my experience, GitHub Flow with multiple environments works like this. Merging to master does not automatically deploy to production. Instead, merging to master creates a build artifact that is able to be promoted through environments using ChatOps tooling.

For example, pushing to master creates a build artifact named something like my-service-47cbd6c, which is a combination of the service name and the short commit hash. This is pushed to an artifact repository of some kind. The artifact can then be deployed to various environments using tooling such as ChatOps style slash commands to trigger the deloy. This tooling could also have checks to make sure test environments are not skipped, for example. Finally, the artifact is promoted to production.

So for your use case with GitHub Actions, what I would suggest is this:

  1. Pushing to master creates the build artifact and automatically deploys it to the development environment.
  2. Test in development
  3. Promote the artifact by deploying to production using a slash command. The action slash-command-dispatch would help you with this.
peterevans
  • 24,033
  • 6
  • 67
  • 72
  • thank you! Yes, this is what I was looking for, this outlook is interesting and will feed this back. – Nathan Sainsbury May 23 '20 at 12:34
  • @peterevans disclaimer - I've never worked with GitHub flow, mainly with Git Flow or something similar. But most of the sources about GitHub flow says deployment to production and testing should happen before merging to master. For example https://stackoverflow.com/questions/39917843/what-is-the-difference-between-github-flow-and-gitlab-flow/47016500#47016500 or https://guides.github.com/introduction/flow/. In your flow you start testing only after pushing to `master` – VB_ Sep 20 '21 at 20:26
  • @VB_ I only have experience in fairly large orgs where deploying after merge to master is the norm. Allowing deploy of feature branches to production sounds a bit dangerous to me, unless it's carefully managed. I would say, though, don't feel you have to follow "the rules." Experiment a bit and do what works for you and your team. – peterevans Sep 21 '21 at 00:03
1

You might also consider the notion of environments (as illustrated here)

Recently (Feb. 2021), you can:

##Limit which branches can deploy to an environment

You can now limit which branches can deploy to an environment using Environment protection rules.

When a job tries to deploy to an environment with Deployment branches configured Actions will check the value of github.ref against the configuration and if it does not match the job will fail and the run will stop.

The Deployment branches rule can be configured to allow:

  • All branches – Any branch in the repository can deploy
  • Protected branches – Only branches with protection rules
  • Selected branches – Branches matching a set of name patterns

https://i1.wp.com/user-images.githubusercontent.com/185122/107719397-253c1e80-6ca6-11eb-9a5c-5d6fc7d4668e.gif?ssl=1

That means you can define a job to deploy in dev environment, and that job, as a condition, will only run if triggered from a commit pushed from a given branch (master in your case)

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
1

For anyone facing the same question or wanting to simplify their process away from gitflow, I'd recommend taking a look at this article. Whilst it doesn't talk about Github flow explicitly it does effectively provide one solution to the OP.

Purests may consider this to be not strictly Gitflow but to my mind it's a simple tweak that makes the deployment & CI/CD strategy more explicit in git. I prefer to have this approach rather than add some magic to the tooling which can make a process harder for devs to follow and understand.

I think the Gitflow intro is written fairly pragmatically as well:

Different teams may have different deployment strategies. For some, it may be best to deploy to a specially provisioned testing environment. For others, deploying directly to production may be the better choice...

The diagram in the article sums it up well:

enter image description here

So here we have Master == Gitflow main and the useful addition is the temporary release branch from which you can deploy to other environments such as development. What is worth considering is what you choose to call this temporary branch, in the above it's considered a release, in your process it may be a test branch, etc.

You can take or leave the squashing and tagging and the tooling will change between teams. Equally you may or may not care about actual version numbers.

This isn't a million miles away from VonC's answer, the difference is the process is more tightly defined and it's more towards having multiple developers merge into a single branch & apply fixes in order to get a new version ready for production. It may well be that you configure the deployment of this temporary branch via a naming convention as in his answer.

Matt
  • 11,258
  • 4
  • 40
  • 39
  • 1
    Good introduction. Upvoted. I personally no longer use GitFlow, only gitworkflow (one word: https://stackoverflow.com/a/53405887/6309) – VonC Sep 28 '21 at 10:50
-3

Nathan, adding a development branch is good idea, you can work on development changes in new branch and test them in dev environment and after getting signoff to move to production environment you can merge your changes in master branch.

Don't forget to perform regression testing on merged master branch to test both old features and new features are working fine before releasing your code for installation in production

  • 1
    Hi Gabriel, appreciate the resposne. However a development branch isn't featured in GitHub Flow, just git flow. So my question is more about how to create a development environment using GitHub Flow (where there is no sepcific development branch). Hence > When another branch is pushed, set up a GitHub action so that any other branch (other than master) is deployed to this environment. – Nathan Sainsbury May 22 '20 at 17:07