A GitHub actions that automate the Gitflow workflow where one has a develop
branch for continuous development and a main
(production) branch that would automatically deploy to production. In between that, a release
branch is created from develop
to perform release preparation tasks before being merged to main
branch. Occasionally, a hotfix
branch is created from main
for hot fixes.
We can add a workflow that creates a PR for release
. It will create a PR with release note that contains all the new changes in the body. The new branch would be called release/x.y.z
.
This basically "freezes" the develop
branch for releases. Other PRs can be merged to develop
during the release
branch lifetime without affecting it.
Create .github/workflows/create-release.yml
on:
workflow_dispatch:
inputs:
version:
type: string
required: true
description: "Version to release"
name: Create release
jobs:
pre_release:
runs-on: ubuntu-latest
steps:
- name: gitflow-workflow-action create release
uses: hoangvvo/gitflow-workflow-action
with:
develop_branch: "develop"
main_branch: "main"
version: ${{ inputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Create .github/workflows/post-release.yml
on:
pull_request:
types:
- opened
- closed
- labeled
name: Release workflows
jobs:
release_workflow:
runs-on: ubuntu-latest
steps:
- name: gitflow-workflow-action release workflows
uses: hoangvvo/gitflow-workflow-action
with:
develop_branch: "develop"
main_branch: "main"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
This workflow does several things:
- Autolabel
release
andhotfix
according to the branch name. - If the PR is labelled
release
orhotfix
and merged tomain
, it will create a release, merge back todevelop
branch, and trigger integrations. This is the process in Gitflow.
Note: It does not handle the deployment process. That is for your team to implement separately.
It is often that an anouncement is made to a Slack channel after a release. To do so, specify SLACK_TOKEN
env and slack
input.
jobs:
release_workflow:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: gitflow-workflow-action release workflows
uses: hoangvvo/gitflow-workflow-action
with:
develop_branch: "develop"
main_branch: "main"
slack: >
{
"channel": "hoang-test",
"username_mapping": {
"hoangvvo": "U03B3E4UPV3"
}
}
env:
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}