A GitHub action implementation to support Distributed Git Flow.
This action automatically raises the PRs to sync the upstream branch changes with the corresponding downstream branches. It will take care of merging this PR without any manual intervention if there is no merge conflict. In case of any merge conflicts, it notifies the respective squad via Slack. It also reports the squads on PR create and merge.
To configure this action on a GitHub repository, you need two secrets
-
GH_APP_CREDENTIALS_TOKEN
- A GitHub Action Credentials token that can be obtained by following this tutorial. This GitHub App requires the following permissions- Contents - Read & Write
- Metadata - Read Only
- Pull Requests - Read & Write
-
SLACK_BOT_TOKEN
- A Slack Bot Token, that can be obtained by creating a new app in your slack workspace with the chat:write OAuth Permission. After creating the slack app, make sure you are creating the required squad's slack channels in your slack workspace and add this newly created slack app to those channels. For example, if you have two squads,mantis
andviper
, then you need the following channelsmaster
- To notify the PR open/close changes on themaster
branchstaging-mantis
- To notify the PR open/close changes and merge conflicts on thestaging/mantis
branchdevelop-mantis
- To notify the PR open/close changes and merge conflicts on thedevelop/mantis
branchstaging-viper
- To notify the PR open/close changes and merge conflicts on thestaging/viper
branchdevelop-viper
- To notify the PR open/close changes and merge conflicts on thedevelop/viper
branch
# .github/workflows/pr.yml
name: On PR Status Change
on:
pull_request:
types:
- opened
- closed
branches:
- master
- 'staging/**'
- 'develop/**'
# env:
# SLACK_CHANNEL_PREFIX: test <- an optional prefix for the slack channel names. Eg. test-staging-mantis, test-develop-viper
jobs:
prStatusChange:
runs-on: ubuntu-latest
steps:
- name: Obtain GitHub App Installation Access Token
id: githubAppAuth
run: |
TOKEN="$(npx obtain-github-app-installation-access-token ci ${{ secrets.GH_APP_CREDENTIALS_TOKEN }})"
echo "::set-output name=GH_APP_TOKEN::$TOKEN"
- uses: chargebee/distributed-gitflow@master
env:
GITHUB_TOKEN: ${{ steps.githubAppAuth.outputs.GH_APP_TOKEN }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
After successful configuration of this GitHub action as mentioned above, it will take care of automating all the manual work needed in keeping all the protected branches in sync as mentioned in the Distributed Git Flow document.
- Upon PR creation, it creates a
label
on the PR with the name of thebase
(from
) branch. It will enable to filter the PRs based on the labels.
- Upon merging a PR to
master
, it will create a PR to all the squad's staging branchstaging/{squad_name}
- if a PR already exists, it won't create any new PR
- Notifies on slack's
master
channel
- Upon merging a PR to
staging/{squad_name}
, it will create a PR to the corresponding squad's develop branchdevelop/{squad_name}
- if a PR already exists, it won't create any new PR
- Notifies on slack's
staging/{squad_name}
channel - if the PR is not from the
master
or thedevelop/{squad_name}
branch, thebase
(from
) branch will be deleted.
- Notifies on slack's
develop/{squad_name}
channel -
- if the PR is not from the
staging/{squad_name}
branch, thebase
(from
) branch will be deleted.
- if the PR is not from the
- Notifies on slack's
staging/{squad_name}
channel - If the PR is from the
master
branch, it will be automatically merged. In case of merge conflicts, the PR will be closed and notifies about the merge conflict on thestaging/{squad_name}
channel
- Notifies on slack's
develop/{squad_name}
channel - If the PR is from the corresponding
staging
branch, it will be automatically merged. In case of merge conflicts, the PR will be closed and notifies about the merge conflict on thedevelop/{squad_name}
channel
- create a new branch
- make the required changes and build the package using the
npm run release
command. - raise a PR to the
master
branch - After the PR merge, the updated GitHub action can be a accessed from
chargebee/distributed-gitflow@master